Page MenuHomePhabricator

No OneTemporary

diff --git a/autoid.php b/autoid.php
new file mode 100644
--- /dev/null
+++ b/autoid.php
@@ -0,0 +1,92 @@
+<?php
+/* Automatic incremented ID based on a prefix and a @@ as a pattern for
+* an automatic increased number.
+*
+* e.g.: neu.txt
+* <form>
+* Action template template:bug: bugs :
+* Thanks "For submitting the bug"
+* Textbox "Description" "/^[^\/:]+$/"
+* autoid "BUG-ID" "=BUG-@@" "/^[^\/:]+$/" @
+* Submit "Send"
+* </form>
+*
+* with template: start.txt
+* ====== @@BUG-ID@@ ======
+* @@Description@@
+*
+* The autoiid field BUG-ID contains a template BUG-@@.
+* 'BUG-' is used as prefix for all new pages.
+* '@@' is replaced with an incremental number based on existing namespace/directory names.
+* e.g. BUG-1, BUG-2, BUG-15 esxist then a new page gets BUG-16 as pagename.
+*
+*/
+class syntax_plugin_bureaucracy_field_autoid extends syntax_plugin_bureaucracy_field {
+
+ function render($params, $form) {
+ $this->_handlePreload();
+ $form->addHidden($params['name'], $this->getParam('value') . '');
+ return;
+ }
+
+ function handle_post($value) {
+ if (is_null($value))
+ return true;
+ // Save pattern
+ $this->opt['autoidpattern'] = $value;
+ // Set value first to ectract the prefix
+ $result = $this->setVal($value);
+ // Extract prefix and automatic incremented pagename
+ $this->getParam('pagename');
+ return $result;
+ }
+
+ function getParam($name) {
+ if (!isset($this->opt[$name]) || $name === 'value' && $this->hidden) {
+ return null;
+ }
+ if ($name === 'pagename') {
+ // Pattern e.g. BUG-@@
+ $value = $this->getParam('value');
+ if (is_null($value)) {
+ return null;
+ }
+
+ // Extract prefix 'BUG-'
+ $prefix = strstr($this->opt['autoidpattern'], "@@", true);
+ // Get all directories starting with the prefix in the current namespace
+ global $ID;
+ global $conf;
+ $ns = cleanID(getNS($ID));
+ $dir = utf8_encodeFN(str_replace(':', '/', $ns));
+ $data = array();
+ $opts2=array();
+ $opts2['listdirs'] = true;
+ $opts2['listfiles'] = false;
+ $opts2['depth'] = 0;
+ $opts2['dirmatch'] = "\/" . strtolower($prefix);
+ search($data, $conf['datadir'] . '/' . $dir, 'search_universal', $opts2, '', 0);
+ // Get highest ID number of found directories
+ $maxid = 1;
+ foreach($data as $i){
+ $current = substr($i['id'], strlen($prefix));
+ if (!is_null($current) && is_numeric($current))
+ $maxid = max(array($maxid, $current));
+ }
+ // Construct pagename
+ $value = $prefix . ($maxid + 1);
+ // Set value to be replaced in template
+ $this->setVal($value);
+
+ if (is_null($value)) {
+ return null;
+ }
+ global $conf;
+ if($conf['useslash']) $value = str_replace('/',' ',$value);
+ return str_replace(':',' ',$value);
+ }
+ return $this->opt[$name];
+ }
+
+
+}

File Metadata

Mime Type
text/x-diff
Expires
Tue, Dec 24, 12:53 PM (18 h, 15 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
530067
Default Alt Text
(3 KB)

Event Timeline