* @author Sam Wilson */ class syntax_plugin_addnewpage extends DokuWiki_Syntax_Plugin { /** * Get some information about this plugin. * * @return array The info array. */ function getInfo() { return array( 'author' => 'iDo, Sam Wilson, Michael Braun', 'email' => '', 'date' => '2013-06-20', 'name' => 'addnewpage', 'desc' => 'Adds a "new page form" to any wiki page.', 'url' => 'https://wiki.dokuwiki.org/plugin:addnewpage', ); } function getType() { return 'substition'; } function getPType() { return 'block'; } function getSort() { return 199; } function connectTo($mode) { $this->Lexer->addSpecialPattern('\{\{NEWPAGE[^\}]*\}\}', $mode, 'plugin_addnewpage'); } // @codingStandardsIgnoreStart function handle($match, $state, $pos, &$handler) { // @codingStandardsIgnoreEnd $ns = substr($match, 10, -2); // strip markup return array($ns); } /** * Create the new-page form. * * @return boolean */ function render($mode, &$renderer, $data) { global $lang; $renderer->info['cache'] = false; $data = $data[0]; // get data back from the array if ($mode == 'xhtml') { $ns_select = $this->_makecombo($data); if ($ns_select == $this->getLang('nooption')) { $renderer->doc .= (!$this->getConf('addpage_hideACL')) ? $ns_select : ''; return true; } $button_val = ((@$this->getLang('okbutton')) ? $this->getLang('okbutton') : 'ok'); $form = '
'.DOKU_LF .DOKU_TAB.'
'.DOKU_LF .DOKU_TAB.DOKU_TAB.$ns_select.DOKU_LF .DOKU_TAB.DOKU_TAB.''.DOKU_LF .DOKU_TAB.DOKU_TAB.''.DOKU_LF .DOKU_TAB.DOKU_TAB.''.DOKU_LF .DOKU_TAB.DOKU_TAB.''.DOKU_LF .DOKU_TAB.'
'.DOKU_LF .'
'; $renderer->doc .= $form; return true; } return false; } /** * Parse namespace request * * @author Samuele Tognini * @author Michael Braun */ function _parse_ns($ns) { global $ID; if ($ns == "@PAGE@") return $ID; if ($ns == "@NS@") return getNS($ID); $ns = preg_replace("/^\.(:|$)/", dirname(str_replace(':', '/', $ID)) . "$1", $ns); $ns = str_replace("/", ":", $ns); $ns = cleanID($ns); return $ns; } /** * Create the HTML Select element for namespace selection. * * @global string $ID The page ID * @param string|false $dest_ns The destination namespace, or false if none provided. * @return string Select element with appropriate NS selected. */ function _makecombo($dest_ns) { global $ID; // If a NS has been provided: // Whether to hide the NS selection (otherwise, show only subnamespaces). $hide = $this->getConf('addpage_hide'); // Whether the user can create pages in the provided NS (or root, if no // destination NS has been set. $can_create = (auth_quickaclcheck($dest_ns.":") >= AUTH_CREATE); if (!empty($dest_ns) && $hide) { if ($can_create) { return ''; } else { return $this->getLang('nooption'); } } $ns = explode(':', $ID); array_pop($ns); $ns = implode(':', $ns); $r = $this->_getnslist(""); $ret = ''; if (!$someopt) $ret = $this->getLang('nooption'); return $ret; } /** * Get a list of namespaces below the given namespace. * Recursively fetches subnamespaces. * * Includes inc/search.php * @global array $conf Site configuration variables * @uses utf8_encodeFN * @param string $tns The top namespace * @return array Multi-dimensional array of all namespaces below $tns */ function _getnslist($tns = '') { require_once(DOKU_INC . 'inc/search.php'); global $conf; if ($tns == '') $tns = $conf['datadir']; if (!is_dir($tns)) $tns = utf8_encodeFN(str_replace(':', '/', $tns)); $data = array(); $exclude = $this->getConf('addpage_exclude'); if ($exclude == "") $exclude = array(); else $exclude = @explode(';', strtolower($exclude)); search($data, $tns, 'search_index', array('ns' => '')); $data2 = array(); foreach ($data as $k => $v) { if ($v['type'] == 'd') { if (!in_array(strtolower($v['id']), $exclude)) { array_push($data2, $v['id']); $r = $this->_getnslist($tns . '/' . $v['id']); foreach ($r as $vv) { if (!in_array(strtolower($vv), $exclude)) { array_push($data2, $v['id'] . ':' . $vv); } } } } } return $data2; } }