/** * Output all needed JavaScript * * @author Andreas Gohr <*****@*****.**> */ function js_out() { global $conf; global $lang; global $config_cascade; // The generated script depends on some dynamic options $cache = new cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.js'); $cache->_event = 'JS_CACHE_USE'; // load minified version for some files $min = $conf['compress'] ? '.min' : ''; // array of core files $files = array(DOKU_INC . "lib/scripts/jquery/jquery{$min}.js", DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', DOKU_INC . "lib/scripts/jquery/jquery-ui{$min}.js", DOKU_INC . "lib/scripts/fileuploader.js", DOKU_INC . "lib/scripts/fileuploaderextended.js", DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/tw-sack.js', DOKU_INC . 'lib/scripts/qsearch.js', DOKU_INC . 'lib/scripts/tree.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/drag.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/editor.js', DOKU_INC . 'lib/scripts/locktimer.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/compatibility.js', DOKU_INC . 'lib/scripts/behaviour.js', DOKU_INC . 'lib/scripts/page.js', tpl_incdir() . 'script.js'); // add possible plugin scripts and userscript $files = array_merge($files, js_pluginscripts()); if (isset($config_cascade['userscript']['default'])) { $files[] = $config_cascade['userscript']['default']; } $cache_files = array_merge($files, getConfigFiles('main')); $cache_files[] = __FILE__; // check cache age & handle conditional request // This may exit if a cache can be used $cache_ok = $cache->useCache(array('files' => $cache_files)); http_cached($cache->cache, $cache_ok); // start output buffering and build the script ob_start(); // add some global variables print "var DOKU_BASE = '" . DOKU_BASE . "';"; print "var DOKU_TPL = '" . tpl_basedir() . "';"; // FIXME: Move those to JSINFO print "var DOKU_UHN = " . (int) useHeading('navigation') . ";"; print "var DOKU_UHC = " . (int) useHeading('content') . ";"; // load JS specific translations $json = new JSON(); $lang['js']['plugins'] = js_pluginstrings(); echo 'LANG = ' . $json->encode($lang['js']) . ";\n"; // load toolbar toolbar_JSdefines('toolbar'); // load files foreach ($files as $file) { echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; js_load($file); echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } // init stuff if ($conf['locktime'] != 0) { js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")"); } // init hotkeys - must have been done after init of toolbar # disabled for FS#1958 js_runonstart('initializeHotkeys()'); // end output buffering and get contents $js = ob_get_contents(); ob_end_clean(); // compress whitespace and comments if ($conf['compress']) { $js = js_compress($js); } $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 http_cached_finish($cache->cache, $js); }
/** * Searches for matching pagenames * * @author Andreas Gohr <*****@*****.**> */ function ajax_qsearch() { global $conf; global $lang; global $INPUT; $query = $INPUT->post->str('q'); if (empty($query)) { $query = $INPUT->get->str('q'); } if (empty($query)) { return; } $query = urldecode($query); $data = ft_pageLookup($query, true, useHeading('navigation')); if (!count($data)) { return; } print '<strong>' . $lang['quickhits'] . '</strong>'; print '<ul>'; foreach ($data as $id => $title) { if (useHeading('navigation')) { $name = $title; } else { $ns = getNS($id); if ($ns) { $name = noNS($id) . ' (' . $ns . ')'; } else { $name = $id; } } echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; } print '</ul>'; }
/** * Searches for matching pagenames * * @author Andreas Gohr <*****@*****.**> */ function ajax_qsearch() { global $conf; global $lang; $query = $_POST['q']; if (empty($query)) { $query = $_GET['q']; } if (empty($query)) { return; } $data = ft_pageLookup($query, true, useHeading('navigation')); if (!count($data)) { return; } print '<strong>' . $lang['quickhits'] . '</strong>'; print '<ul>'; foreach ($data as $id => $title) { if (useHeading('navigation')) { $name = $title; } else { $ns = getNS($id); if ($ns) { $name = shorten(noNS($id), ' (' . $ns . ')', 30); } else { $name = $id; } } echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; } print '</ul>'; }
/** * get the Title for the page **/ public function getSiteTitle($ID) { if (useHeading('content') && $ID) { $heading = p_get_first_heading($ID, true); if ($heading) { return $this->xmlEntities($heading); } } return ucwords($this->xmlEntities(array_pop(explode(':', $ID)))); }
function render($mode, &$R, &$T, $value, $hint) { $heading = null; // only use heading if allowed by configuration if (useHeading('content')) { $titles = $T->fetchTriples($value, $this->util->getTitleKey()); if ($titles) { $heading = $titles[0]['object']; } } // render internal link // (':' is prepended to make sure we use an absolute pagename, // internallink resolves page names, but the name is already resolved.) $R->internallink(':' . $value, $heading); }
/** * Searches for matching pagenames * * @author Andreas Gohr <*****@*****.**> */ function ajax_qsearch() { global $lang; global $INPUT; $maxnumbersuggestions = 50; $query = $INPUT->post->str('q'); if (empty($query)) { $query = $INPUT->get->str('q'); } if (empty($query)) { return; } $query = urldecode($query); $data = ft_pageLookup($query, true, useHeading('navigation')); if (!count($data)) { return; } print '<strong>' . $lang['quickhits'] . '</strong>'; print '<ul>'; $counter = 0; foreach ($data as $id => $title) { if (useHeading('navigation')) { $name = $title; } else { $ns = getNS($id); if ($ns) { /* Displays the Header of the Namespace-Page or of namespace:start as the Name of the NS */ $ns_name = p_get_first_heading(getNS($id)); if (!$ns_name) { $ns_name = p_get_first_heading(getNS($id) . ':start'); } $name = shorten(' [' . $ns_name . ']', 30); } else { $name = $id; } } echo '<li>' . html_wikilink(':' . $id, $name) . '</li>'; $counter++; if ($counter > $maxnumbersuggestions) { echo '<li>...</li>'; break; } } print '</ul>'; }
function _custom_delete_page($id, $summary) { global $ID, $INFO, $conf; // mark as nonexist to prevent indexerWebBug if ($id == $ID) { $INFO['exists'] = 0; } // delete page, meta and attic $file = wikiFN($id); $old = @filemtime($file); // from page if (file_exists($file)) { unlink($file); } $opts['oldname'] = $this->_FN(noNS($id)); $opts['oldns'] = $this->_FN(getNS($id)); if ($opts['oldns']) { $opts['oldns'] .= '/'; } $this->_locate_filepairs($opts, 'metadir', '/^' . $opts['oldname'] . '\\.(?!mlist)\\w*?$/'); $this->_locate_filepairs($opts, 'olddir', '/^' . $opts['oldname'] . '\\.\\d{10}\\.txt(\\.gz|\\.bz2)?$/'); $this->_apply_deletes($opts); io_sweepNS($id, 'datadir'); io_sweepNS($id, 'metadir'); io_sweepNS($id, 'olddir'); // send notify mails notify($id, 'admin', $old, $summary); notify($id, 'subscribers', $old, $summary); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
/** * Output all needed JavaScript * * @author Andreas Gohr <*****@*****.**> */ function js_out() { global $conf; global $lang; global $config_cascade; // The generated script depends on some dynamic options $cache = getCacheName('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'], '.js'); // array of core files $files = array(DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/events.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/tw-sack.js', DOKU_INC . 'lib/scripts/ajax.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/drag.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/subscriptions.js', DOKU_TPLINC . 'script.js'); // add possible plugin scripts and userscript $files = array_merge($files, js_pluginscripts()); if (isset($config_cascade['userscript']['default'])) { $files[] = $config_cascade['userscript']['default']; } // check cache age & handle conditional request header('Cache-Control: public, max-age=3600'); header('Pragma: public'); if (js_cacheok($cache, $files)) { http_conditionalRequest(filemtime($cache)); if ($conf['allowdebug']) { header("X-CacheUsed: {$cache}"); } // finally send output if ($conf['gzip_output'] && http_gzip_valid($cache)) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); readfile($cache . ".gz"); } else { if (!http_sendfile($cache)) { readfile($cache); } } return; } else { http_conditionalRequest(time()); } // start output buffering and build the script ob_start(); // add some global variables print "var DOKU_BASE = '" . DOKU_BASE . "';"; print "var DOKU_TPL = '" . DOKU_TPL . "';"; print "var DOKU_UHN = " . (int) useHeading('navigation') . ";"; print "var DOKU_UHC = " . (int) useHeading('content') . ";"; // load JS specific translations $json = new JSON(); $lang['js']['plugins'] = js_pluginstrings(); echo 'LANG = ' . $json->encode($lang['js']) . ";\n"; // load toolbar toolbar_JSdefines('toolbar'); // load files foreach ($files as $file) { echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; js_load($file); echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } // init stuff js_runonstart("addEvent(document,'click',closePopups)"); js_runonstart('addTocToggle()'); js_runonstart("initSizeCtl('size__ctl','wiki__text')"); js_runonstart("initToolbar('tool__bar','wiki__text',toolbar)"); if ($conf['locktime'] != 0) { js_runonstart("locktimer.init(" . ($conf['locktime'] - 60) . ",'" . js_escape($lang['willexpire']) . "'," . $conf['usedraft'] . ")"); } js_runonstart('scrollToMarker()'); js_runonstart('focusMarker()'); // init hotkeys - must have been done after init of toolbar # disabled for FS#1958 js_runonstart('initializeHotkeys()'); // end output buffering and get contents $js = ob_get_contents(); ob_end_clean(); // compress whitespace and comments if ($conf['compress']) { $js = js_compress($js); } $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 // save cache file io_saveFile($cache, $js); if (function_exists('gzopen')) { io_saveFile("{$cache}.gz", $js); } // finally send output if ($conf['gzip_output']) { header('Vary: Accept-Encoding'); header('Content-Encoding: gzip'); print gzencode($js, 9, FORCE_GZIP); } else { print $js; } }
/** * List all pages in the given namespace (and below) */ function search($query) { $regex = ''; $data = ft_pageSearch($query, $regex); $pages = array(); // prepare additional data $idx = 0; foreach ($data as $id => $score) { $file = wikiFN($id); if ($idx < FT_SNIPPET_NUMBER) { $snippet = ft_snippet($id, $regex); $idx++; } else { $snippet = ''; } $pages[] = array('id' => $id, 'score' => intval($score), 'rev' => filemtime($file), 'mtime' => filemtime($file), 'size' => filesize($file), 'snippet' => $snippet, 'title' => useHeading('navigation') ? p_get_first_heading($id) : $id); } return $pages; }
/** * Prints or returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is used. * * @author Andreas Gohr <*****@*****.**> * * @param string $id page id * @param bool $ret return content instead of printing * @return bool|string */ function tpl_pagetitle($id = null, $ret = false) { global $ACT, $INPUT, $conf, $lang; if (is_null($id)) { global $ID; $id = $ID; } $name = $id; if (useHeading('navigation')) { $first_heading = p_get_first_heading($id); if ($first_heading) { $name = $first_heading; } } // default page title is the page name, modify with the current action switch ($ACT) { // admin functions case 'admin': $page_title = $lang['btn_admin']; // try to get the plugin name /** @var $plugin DokuWiki_Admin_Plugin */ if ($plugin = plugin_getRequestAdminPlugin()) { $plugin_title = $plugin->getMenuText($conf['lang']); $page_title = $plugin_title ? $plugin_title : $plugin->getPluginName(); } break; // user functions // user functions case 'login': case 'profile': case 'register': case 'resendpwd': $page_title = $lang['btn_' . $ACT]; break; // wiki functions // wiki functions case 'search': case 'index': $page_title = $lang['btn_' . $ACT]; break; // page functions // page functions case 'edit': $page_title = "✎ " . $name; break; case 'revisions': $page_title = $name . ' - ' . $lang['btn_revs']; break; case 'backlink': case 'recent': case 'subscribe': $page_title = $name . ' - ' . $lang['btn_' . $ACT]; break; default: // SHOW and anything else not included $page_title = $name; } if ($ret) { return hsc($page_title); } else { print hsc($page_title); return true; } }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> */ function _getLinkTitle($title, $default, $id = NULL) { global $conf; $isImage = false; if (is_null($title)) { if (useHeading('content') && $id) { $heading = p_get_first_heading($id, false); if ($heading) { return $heading; } } return $default; } else { if (is_string($title)) { return $title; } else { if (is_array($title)) { return '[' . $title['title'] . ']'; } } } }
/** * Simple wrapper for tpl_getConf * * @author Giuseppe Di Terlizzi <*****@*****.**> * * @param string $key * @param mixed $default value * @return mixed */ function bootstrap3_conf($key, $default = false) { global $ACT, $INFO, $ID, $conf; $value = tpl_getConf($key, $default); switch ($key) { case 'showTools': case 'showSearchForm': case 'showPageTools': return $value !== 'never' && ($value == 'always' || !empty($_SERVER['REMOTE_USER'])); case 'showIndividualTool': case 'hideInThemeSwitcher': case 'tableStyle': return explode(',', $value); case 'showAdminMenu': return $value && $INFO['isadmin']; case 'hideLoginLink': return !$value || !empty($_SERVER['REMOTE_USER']); case 'browserTitle': if (bootstrap3_conf('browserTitleShowNS')) { $ns_parts = explode(':', $ID); $ns_pages = array(); $ns_titles = array(); $ns_separator = sprintf(' %s ', bootstrap3_conf('browserTitleCharSepNS')); if (useHeading('navigation')) { foreach ($ns_parts as $ns_part) { $ns_page .= "{$ns_part}:"; $ns_pages[] = $ns_page; } $ns_pages = array_unique($ns_pages); foreach ($ns_pages as $ns_page) { resolve_pageid(getNS($ns_page), $ns_page, $exists); $ns_page_title_heading = hsc(p_get_first_heading($ns_page)); $ns_page_title_page = noNSorNS($ns_page); $ns_page_title = $ns_page_title_heading ? $ns_page_title_heading : $ns_page_title_page; $ns_titles[] = $ns_page_title; } $ns_titles[] = tpl_pagetitle($ID, true); $ns_titles = array_unique($ns_titles); } else { $ns_titles = $ns_parts; } if (bootstrap3_conf('browserTitleOrderNS') == 'normal') { $ns_titles = array_reverse($ns_titles); } $browser_title = implode($ns_separator, $ns_titles); } else { $browser_title = tpl_pagetitle($ID, true); } return str_replace(array('@WIKI@', '@TITLE@'), array(strip_tags($conf['title']), $browser_title), $value); case 'showSidebar': return page_findnearest($conf['sidebar']) && $ACT == 'show'; case 'showRightSidebar': return page_findnearest(tpl_getConf('rightSidebar')) && $ACT == 'show'; case 'landingPages': return sprintf('/%s/', $value); } //$type = bootstrap3_metadata($key); //if ($type[0] == 'regex') { // return sprintf('/%s/', $value); //} return $value; }
public function handle_tpl_act_render(&$event, $param) { global $ID, $ACT; if ($ACT != 'show' && $ACT != '') { return; } if (!$this->getConf('show_note')) { return; } if (isset($_GET['redirect']) && $_GET['redirect'] > 0 && $_GET['redirect'] < 6) { if (isset($_SESSION[DOKU_COOKIE]['redirect']) && $_SESSION[DOKU_COOKIE]['redirect'] != '') { // we were redirected from another page, show it! $page = cleanID($_SESSION[DOKU_COOKIE]['redirect']); $title = hsc(useHeading('navigation') && p_get_first_heading($page) ? p_get_first_heading($page) : $page); echo '<div class="noteredirect">' . sprintf($this->getLang('redirected_from'), '<a href="' . wl(':' . $page, array('redirect' => 'no'), TRUE, '&') . '" class="wikilink1" title="' . $page . '">' . $title . '</a>') . '</div><br/>'; unset($_SESSION[DOKU_COOKIE]['redirect']); return true; } } return true; }
/** * Resolve a value according to its column settings * * This function is registered as a SQL function named DATARESOLVE */ function _resolveData($value, $colname) { // resolve pre and postfixes $column = $this->_column($colname); $value = $this->_addPrePostFixes($column['type'], $value); // for pages, resolve title $type = $column['type']; if (is_array($type)) { $type = $type['type']; } if ($type == 'title' || $type == 'page' && useHeading('content')) { $value = p_get_first_heading($value); } return $value; }
function tpl_pageName($id) { // page names $name = noNSorNS($id); if (useHeading('navigation')) { // get page title $title = p_get_first_heading($id, METADATA_RENDER_USING_SIMPLE_CACHE); if ($title) { $name = $title; } } return $name; }
/** * List recent edits matching the given filter */ function _list($filter) { global $conf; global $lang; echo '<hr /><br />'; echo '<form action="" method="post"><div class="no">'; echo '<input type="hidden" name="filter" value="' . hsc($filter) . '" />'; formSecurityToken(); $recents = getRecents(0, $this->max_lines); echo '<ul>'; $cnt = 0; foreach ($recents as $recent) { if ($filter) { if (strpos(rawWiki($recent['id']), $filter) === false) { continue; } } $cnt++; $date = strftime($conf['dformat'], $recent['date']); echo $recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT ? '<li class="minor">' : '<li>'; echo '<div class="li">'; echo '<input type="checkbox" name="revert[]" value="' . hsc($recent['id']) . '" checked="checked" id="revert__' . $cnt . '" />'; echo '<label for="revert__' . $cnt . '">' . $date . '</label> '; echo '<a href="' . wl($recent['id'], "do=diff") . '">'; $p = array(); $p['src'] = DOKU_BASE . 'lib/images/diff.png'; $p['width'] = 15; $p['height'] = 11; $p['title'] = $lang['diff']; $p['alt'] = $lang['diff']; $att = buildAttributes($p); echo "<img {$att} />"; echo '</a> '; echo '<a href="' . wl($recent['id'], "do=revisions") . '">'; $p = array(); $p['src'] = DOKU_BASE . 'lib/images/history.png'; $p['width'] = 12; $p['height'] = 14; $p['title'] = $lang['btn_revs']; $p['alt'] = $lang['btn_revs']; $att = buildAttributes($p); echo "<img {$att} />"; echo '</a> '; echo html_wikilink(':' . $recent['id'], useHeading('navigation') ? NULL : $recent['id']); echo ' – ' . htmlspecialchars($recent['sum']); echo ' <span class="user">'; echo $recent['user'] . ' ' . $recent['ip']; echo '</span>'; echo '</div>'; echo '</li>'; @set_time_limit(10); flush(); } echo '</ul>'; echo '<p>'; echo '<input type="submit" class="button" value="' . $this->getLang('revert') . '" /> '; printf($this->getLang('note2'), hsc($filter)); echo '</p>'; echo '</div></form>'; }
/** * Output all needed JavaScript * * @author Andreas Gohr <*****@*****.**> */ function js_out() { global $conf; global $lang; global $config_cascade; global $INPUT; // decide from where to get the template $tpl = trim(preg_replace('/[^\\w-]+/', '', $INPUT->str('t'))); if (!$tpl) { $tpl = $conf['template']; } // The generated script depends on some dynamic options $cache = new cache('scripts' . $_SERVER['HTTP_HOST'] . $_SERVER['SERVER_PORT'] . DOKU_BASE . $tpl, '.js'); $cache->_event = 'JS_CACHE_USE'; // load minified version for some files $min = $conf['compress'] ? '.min' : ''; // array of core files $files = array(DOKU_INC . "lib/scripts/jquery/jquery{$min}.js", DOKU_INC . 'lib/scripts/jquery/jquery.cookie.js', DOKU_INC . "lib/scripts/jquery/jquery-ui{$min}.js", DOKU_INC . "lib/scripts/jquery/jquery-migrate{$min}.js", DOKU_INC . 'inc/lang/' . $conf['lang'] . '/jquery.ui.datepicker.js', DOKU_INC . "lib/scripts/fileuploader.js", DOKU_INC . "lib/scripts/fileuploaderextended.js", DOKU_INC . 'lib/scripts/helpers.js', DOKU_INC . 'lib/scripts/delay.js', DOKU_INC . 'lib/scripts/cookie.js', DOKU_INC . 'lib/scripts/script.js', DOKU_INC . 'lib/scripts/qsearch.js', DOKU_INC . 'lib/scripts/tree.js', DOKU_INC . 'lib/scripts/index.js', DOKU_INC . 'lib/scripts/textselection.js', DOKU_INC . 'lib/scripts/toolbar.js', DOKU_INC . 'lib/scripts/edit.js', DOKU_INC . 'lib/scripts/editor.js', DOKU_INC . 'lib/scripts/locktimer.js', DOKU_INC . 'lib/scripts/linkwiz.js', DOKU_INC . 'lib/scripts/media.js', DOKU_INC . 'lib/scripts/compatibility.js', DOKU_INC . 'lib/scripts/behaviour.js', DOKU_INC . 'lib/scripts/page.js', tpl_incdir($tpl) . 'script.js'); // add possible plugin scripts and userscript $files = array_merge($files, js_pluginscripts()); if (!empty($config_cascade['userscript']['default'])) { foreach ($config_cascade['userscript']['default'] as $userscript) { $files[] = $userscript; } } $cache_files = array_merge($files, getConfigFiles('main')); $cache_files[] = __FILE__; // check cache age & handle conditional request // This may exit if a cache can be used $cache_ok = $cache->useCache(array('files' => $cache_files)); http_cached($cache->cache, $cache_ok); // start output buffering and build the script ob_start(); $json = new JSON(); // add some global variables print "var DOKU_BASE = '" . DOKU_BASE . "';"; print "var DOKU_TPL = '" . tpl_basedir($tpl) . "';"; print "var DOKU_COOKIE_PARAM = " . $json->encode(array('path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'], 'secure' => $conf['securecookie'] && is_ssl())) . ";"; // FIXME: Move those to JSINFO print "var DOKU_UHN = " . (int) useHeading('navigation') . ";"; print "var DOKU_UHC = " . (int) useHeading('content') . ";"; // load JS specific translations $lang['js']['plugins'] = js_pluginstrings(); $templatestrings = js_templatestrings($tpl); if (!empty($templatestrings)) { $lang['js']['template'] = $templatestrings; } echo 'LANG = ' . $json->encode($lang['js']) . ";\n"; // load toolbar toolbar_JSdefines('toolbar'); // load files foreach ($files as $file) { if (!file_exists($file)) { continue; } $ismin = substr($file, -7) == '.min.js'; $debugjs = $conf['allowdebug'] && strpos($file, DOKU_INC . 'lib/scripts/') !== 0; echo "\n\n/* XXXXXXXXXX begin of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; if ($ismin) { echo "\n/* BEGIN NOCOMPRESS */\n"; } if ($debugjs) { echo "\ntry {\n"; } js_load($file); if ($debugjs) { echo "\n} catch (e) {\n logError(e, '" . str_replace(DOKU_INC, '', $file) . "');\n}\n"; } if ($ismin) { echo "\n/* END NOCOMPRESS */\n"; } echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n"; } // init stuff if ($conf['locktime'] != 0) { js_runonstart("dw_locktimer.init(" . ($conf['locktime'] - 60) . "," . $conf['usedraft'] . ")"); } // init hotkeys - must have been done after init of toolbar # disabled for FS#1958 js_runonstart('initializeHotkeys()'); // end output buffering and get contents $js = ob_get_contents(); ob_end_clean(); // strip any source maps stripsourcemaps($js); // compress whitespace and comments if ($conf['compress']) { $js = js_compress($js); } $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033 http_cached_finish($cache->cache, $js); }
function tpl_arctic_mbo_pagename($sep = ' » ') { global $conf; global $ID; global $lang; $parts = explode(':', $ID); $count = count($parts); if ($GLOBALS['ACT'] == 'search') { $parts = array($conf['start']); $count = 1; } // always print the site title tpl_link(wl(), $conf['title'], 'name="dokuwiki__top" id="dokuwiki__top" title="' . $conf['start'] . '"'); // print intermediate namespace links $part = ''; for ($i = 0; $i < $count - 1; $i++) { $part .= $parts[$i] . ':'; $page = $part; resolve_pageid('', $page, $exists); if ($page == $conf['start']) { continue; } // Skip startpage // output echo $sep; if ($exists && auth_quickaclcheck($page) >= AUTH_READ) { $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; tpl_link(wl($page), hsc($title), 'title="' . $page . '"'); } else { tpl_link(wl($page), $parts[$i], 'title="' . $page . '" class="wikilink2" rel="nofollow"'); } } // print current page, skipping start page, skipping for namespace index if (isset($page) && $page == $part . $parts[$i]) { return; } $page = $part . $parts[$i]; if ($page == $conf['start']) { return; } echo $sep; if (page_exists($page) && auth_quickaclcheck($page) >= AUTH_READ) { $title = useHeading('navigation') ? p_get_first_heading($page) : $parts[$i]; tpl_link(wl($page), hsc($title), 'title="' . $page . '"'); } else { tpl_link(wl($page), $parts[$i], 'title="' . $page . '" class="wikilink2" rel="nofollow"'); } return true; }
/** * Saves a wikitext by calling io_writeWikiPage. * Also directs changelog and attic updates. * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> * * @param string $id page id * @param string $text wikitext being saved * @param string $summary summary of text update * @param bool $minor mark this saved version as minor update */ function saveWikiText($id, $text, $summary, $minor = false) { /* Note to developers: This code is subtle and delicate. Test the behavior of the attic and changelog with dokuwiki and external edits after any changes. External edits change the wiki page directly without using php or dokuwiki. */ global $conf; global $lang; global $REV; /* @var Input $INPUT */ global $INPUT; // prepare data for event $svdta = array(); $svdta['id'] = $id; $svdta['file'] = wikiFN($id); $svdta['revertFrom'] = $REV; $svdta['oldRevision'] = @filemtime($svdta['file']); $svdta['newRevision'] = 0; $svdta['newContent'] = $text; $svdta['oldContent'] = rawWiki($id); $svdta['summary'] = $summary; $svdta['contentChanged'] = $svdta['newContent'] != $svdta['oldContent']; $svdta['changeInfo'] = ''; $svdta['changeType'] = DOKU_CHANGE_TYPE_EDIT; $svdta['sizechange'] = null; // select changelog line type if ($REV) { $svdta['changeType'] = DOKU_CHANGE_TYPE_REVERT; $svdta['changeInfo'] = $REV; } else { if (!file_exists($svdta['file'])) { $svdta['changeType'] = DOKU_CHANGE_TYPE_CREATE; } else { if (trim($text) == '') { // empty or whitespace only content deletes $svdta['changeType'] = DOKU_CHANGE_TYPE_DELETE; // autoset summary on deletion if (blank($svdta['summary'])) { $svdta['summary'] = $lang['deleted']; } } else { if ($minor && $conf['useacl'] && $INPUT->server->str('REMOTE_USER')) { //minor edits only for logged in users $svdta['changeType'] = DOKU_CHANGE_TYPE_MINOR_EDIT; } } } } $event = new Doku_Event('COMMON_WIKIPAGE_SAVE', $svdta); if (!$event->advise_before()) { return; } // if the content has not been changed, no save happens (plugins may override this) if (!$svdta['contentChanged']) { return; } detectExternalEdit($id); if ($svdta['changeType'] == DOKU_CHANGE_TYPE_CREATE || $svdta['changeType'] == DOKU_CHANGE_TYPE_REVERT && !file_exists($svdta['file'])) { $filesize_old = 0; } else { $filesize_old = filesize($svdta['file']); } if ($svdta['changeType'] == DOKU_CHANGE_TYPE_DELETE) { // Send "update" event with empty data, so plugins can react to page deletion $data = array(array($svdta['file'], '', false), getNS($id), noNS($id), false); trigger_event('IO_WIKIPAGE_WRITE', $data); // pre-save deleted revision @touch($svdta['file']); clearstatcache(); $data['newRevision'] = saveOldRevision($id); // remove empty file @unlink($svdta['file']); $filesize_new = 0; // don't remove old meta info as it should be saved, plugins can use IO_WIKIPAGE_WRITE for removing their metadata... // purge non-persistant meta data p_purge_metadata($id); // remove empty namespaces io_sweepNS($id, 'datadir'); io_sweepNS($id, 'mediadir'); } else { // save file (namespace dir is created in io_writeWikiPage) io_writeWikiPage($svdta['file'], $svdta['newContent'], $id); // pre-save the revision, to keep the attic in sync $svdta['newRevision'] = saveOldRevision($id); $filesize_new = filesize($svdta['file']); } $svdta['sizechange'] = $filesize_new - $filesize_old; $event->advise_after(); addLogEntry($svdta['newRevision'], $svdta['id'], $svdta['changeType'], $svdta['summary'], $svdta['changeInfo'], null, $svdta['sizechange']); // send notify mails notify($svdta['id'], 'admin', $svdta['oldRevision'], $svdta['summary'], $minor); notify($svdta['id'], 'subscribers', $svdta['oldRevision'], $svdta['summary'], $minor); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id, true); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
/** * Resolve a value according to its column settings * * This function is registered as a SQL function named DATARESOLVE */ function _resolveData($value, $colname) { // resolve pre and postfixes $column = $this->_column($colname); $value = $this->_addPrePostFixes($column['type'], $value); // for pages, resolve title $type = $column['type']; if (is_array($type)) { $type = $type['type']; } if ($type == 'title' || $type == 'page' && useHeading('content')) { $id = $value; if ($type == 'title') { list($id, ) = explode('|', $value, 2); } //DATARESOLVE is only used with the 'LIKE' comparator, so concatenate the different strings is fine. $value .= ' ' . p_get_first_heading($id); } return $value; }
/** * Saves a wikitext by calling io_writeWikiPage. * Also directs changelog and attic updates. * * @author Andreas Gohr <*****@*****.**> * @author Ben Coburn <*****@*****.**> */ function saveWikiText($id, $text, $summary, $minor = false) { /* Note to developers: This code is subtle and delicate. Test the behavior of the attic and changelog with dokuwiki and external edits after any changes. External edits change the wiki page directly without using php or dokuwiki. */ global $conf; global $lang; global $REV; // ignore if no changes were made if ($text == rawWiki($id, '')) { return; } $file = wikiFN($id); $old = @filemtime($file); // from page $wasRemoved = trim($text) == ''; // check for empty or whitespace only $wasCreated = !@file_exists($file); $wasReverted = $REV == true; $newRev = false; $oldRev = getRevisions($id, -1, 1, 1024); // from changelog $oldRev = (int) (empty($oldRev) ? 0 : $oldRev[0]); if (!@file_exists(wikiFN($id, $old)) && @file_exists($file) && $old >= $oldRev) { // add old revision to the attic if missing saveOldRevision($id); // add a changelog entry if this edit came from outside dokuwiki if ($old > $oldRev) { addLogEntry($old, $id, DOKU_CHANGE_TYPE_EDIT, $lang['external_edit'], '', array('ExternalEdit' => true)); // remove soon to be stale instructions $cache = new cache_instructions($id, $file); $cache->removeCache(); } } if ($wasRemoved) { // Send "update" event with empty data, so plugins can react to page deletion $data = array(array($file, '', false), getNS($id), noNS($id), false); trigger_event('IO_WIKIPAGE_WRITE', $data); // pre-save deleted revision @touch($file); clearstatcache(); $newRev = saveOldRevision($id); // remove empty file @unlink($file); // don't remove old meta info as it should be saved, plugins can use IO_WIKIPAGE_WRITE for removing their metadata... // purge non-persistant meta data p_purge_metadata($id); $del = true; // autoset summary on deletion if (empty($summary)) { $summary = $lang['deleted']; } // remove empty namespaces io_sweepNS($id, 'datadir'); io_sweepNS($id, 'mediadir'); } else { // save file (namespace dir is created in io_writeWikiPage) io_writeWikiPage($file, $text, $id); // pre-save the revision, to keep the attic in sync $newRev = saveOldRevision($id); $del = false; } // select changelog line type $extra = ''; $type = DOKU_CHANGE_TYPE_EDIT; if ($wasReverted) { $type = DOKU_CHANGE_TYPE_REVERT; $extra = $REV; } else { if ($wasCreated) { $type = DOKU_CHANGE_TYPE_CREATE; } else { if ($wasRemoved) { $type = DOKU_CHANGE_TYPE_DELETE; } else { if ($minor && $conf['useacl'] && $_SERVER['REMOTE_USER']) { $type = DOKU_CHANGE_TYPE_MINOR_EDIT; } } } } //minor edits only for logged in users addLogEntry($newRev, $id, $type, $summary, $extra); // send notify mails notify($id, 'admin', $old, $summary, $minor); notify($id, 'subscribers', $old, $summary, $minor); // update the purgefile (timestamp of the last time anything within the wiki was changed) io_saveFile($conf['cachedir'] . '/purgefile', time()); // if useheading is enabled, purge the cache of all linking pages if (useHeading('content')) { $pages = ft_backlinks($id); foreach ($pages as $page) { $cache = new cache_renderer($page, wikiFN($page), 'xhtml'); $cache->removeCache(); } } }
function render($mode, &$R, $data) { global $ID; if ($data == array()) { return false; } if ($mode == 'xhtml') { list($currentPosition, $previousPosition, $nextPosition) = $this->getPositions($data); // render table header $R->doc .= '<div class="strata-entry" ' . (isset($currentPosition) ? 'id="' . $currentPosition . '"' : '') . '>'; $R->table_open(); $R->tablerow_open(); $R->tableheader_open(2); // determine actual header text $heading = ''; if (isset($data['data'][$this->util->getTitleKey()])) { // use title triple if possible $heading = $data['data'][$this->util->getTitleKey()][0]['value']; } elseif (!empty($data['title candidate'])) { // use title candidate if possible $heading = $data['title candidate']['value']; } else { if (useHeading('content')) { // fall back to page title, depending on wiki configuration $heading = p_get_first_heading($ID); } if (!$heading) { // use page id if all else fails $heading = noNS($ID); } } $R->doc .= $R->_xmlEntities($heading); // display a comma-separated list of classes if the entry has classes if (isset($data['data'][$this->util->getIsaKey()])) { $R->emphasis_open(); $R->doc .= ' ('; $values = $data['data'][$this->util->getIsaKey()]; $this->util->openField($mode, $R, $this->util->getIsaKey()); for ($i = 0; $i < count($values); $i++) { $triple =& $values[$i]; if ($i != 0) { $R->doc .= ', '; } $type = $this->util->loadType($triple['type']); $this->util->renderValue($mode, $R, $this->triples, $triple['value'], $triple['type'], $type, $triple['hint']); } $this->util->closeField($mode, $R); $R->doc .= ')'; $R->emphasis_close(); } $R->tableheader_close(); $R->tablerow_close(); // render a row for each key, displaying the values as comma-separated list foreach ($data['data'] as $key => $values) { // skip isa and title keys if ($key == $this->util->getTitleKey() || $key == $this->util->getIsaKey()) { continue; } // render row header $R->tablerow_open(); $R->tableheader_open(); $this->util->renderPredicate($mode, $R, $this->triples, $key); $R->tableheader_close(); // render row content $R->tablecell_open(); $this->util->openField($mode, $R, $key); for ($i = 0; $i < count($values); $i++) { $triple =& $values[$i]; if ($i != 0) { $R->doc .= ', '; } $this->util->renderValue($mode, $R, $this->triples, $triple['value'], $triple['type'], $triple['hint']); } $this->util->closeField($mode, $R); $R->tablecell_close(); $R->tablerow_close(); } if ($previousPosition || $nextPosition) { $R->tablerow_open(); $R->tableheader_open(2); if ($previousPosition) { $R->doc .= '<span class="strata-data-fragment-link-previous">'; $R->locallink($previousPosition, $this->util->getLang('data_entry_previous')); $R->doc .= '</span>'; } $R->doc .= ' '; if ($nextPosition) { $R->doc .= '<span class="strata-data-fragment-link-next">'; $R->locallink($nextPosition, $this->util->getLang('data_entry_next')); $R->doc .= '</span>'; } $R->tableheader_close(); $R->tablerow_close(); } $R->table_close(); $R->doc .= '</div>'; return true; } elseif ($mode == 'metadata' || $mode == 'preview_metadata') { $triples = array(); $subject = $ID . '#' . $data['entry']; // resolve the subject to normalize everything resolve_pageid(getNS($ID), $subject, $exists); $titleKey = $this->util->getTitleKey(); $fixTitle = false; // we only use the title determination if no explicit title was given if (empty($data['data'][$titleKey])) { if (!empty($data['title candidate'])) { // we have a candidate from somewhere $data['data'][$titleKey][] = $data['title candidate']; } else { if (!empty($R->meta['title'])) { // we do not have a candidate, so we use the page title // (this is possible because fragments set the candidate) $data['data'][$titleKey][] = array('value' => $R->meta['title'], 'type' => 'text', 'hint' => null); } else { // we were added before the page title is known // however, we do require a page title (iff we actually store data) $fixTitle = true; } } } // store positions information if ($mode == 'preview_metadata') { self::$previewMetadata[$ID]['strata']['positions'][$data['entry']][] = $data['position']; } else { $R->meta['strata']['positions'][$data['entry']][] = $data['position']; } // process triples foreach ($data['data'] as $property => $bucket) { $this->util->renderPredicate($mode, $R, $this->triples, $property); foreach ($bucket as $triple) { // render values for things like backlinks $type = $this->util->loadType($triple['type']); $type->render($mode, $R, $this->triples, $triple['value'], $triple['hint']); // prepare triples for storage $triples[] = array('subject' => $subject, 'predicate' => $property, 'object' => $triple['value']); } } // we're done if nodata is flagged. if (!isset($R->info['data']) || $R->info['data'] == true) { // batch-store triples if we're allowed to store $this->triples->addTriples($triples, $ID); // set flag for title addendum if ($fixTitle) { $R->meta['strata']['fixTitle'] = true; } } return true; } return false; }
/** * Prints or returns the name of the given page (current one if none given). * * If useheading is enabled this will use the first headline else * the given ID is used. * * @author Andreas Gohr <*****@*****.**> * @param string $id page id * @param bool $ret return content instead of printing * @return bool|string */ function tpl_pagetitle($id = null, $ret = false) { if (is_null($id)) { global $ID; $id = $ID; } $name = $id; if (useHeading('navigation')) { $title = p_get_first_heading($id); if ($title) { $name = $title; } } if ($ret) { return hsc($name); } else { print hsc($name); return true; } }
function _handle_ajax($event) { if (strpos($event->data, 'data_page_') !== 0) { return; } $event->preventDefault(); $type = substr($event->data, 10); $aliases = $this->dthlp->_aliases(); if (!isset($aliases[$type])) { echo 'Unknown type'; return; } if ($aliases[$type]['type'] !== 'page') { echo 'AutoCompletion is only supported for page types'; return; } if (substr($aliases[$type]['postfix'], -1, 1) === ':') { // Resolve namespace start page ID global $conf; $aliases[$type]['postfix'] .= $conf['start']; } require_once DOKU_INC . 'inc/fulltext.php'; $search = cleanID($_POST['search']); $pages = ft_pageLookup($search, false); $result = array(); foreach ($pages as $page) { if ($aliases[$type]['prefix'] !== '' && stripos($page, $aliases[$type]['prefix']) !== 0 || $aliases[$type]['postfix'] !== '' && strripos($page, $aliases[$type]['postfix']) !== strlen($page) - strlen($aliases[$type]['postfix'])) { continue; } $rtrim = -strlen($aliases[$type]['postfix']); if ($rtrim === 0) { // trimming with -0 gives the empty string, not the untrimmed // string $id = substr($page, strlen($aliases[$type]['prefix'])); } else { $id = substr($page, strlen($aliases[$type]['prefix']), $rtrim); } if (useHeading('content')) { $heading = p_get_first_heading($page, true); } if (!isset($heading) || $heading === '') { $heading = $id; } if ($search !== '' && (stripos($id, $search) === false && stripos($heading, $search) === false) || strpos($id, ':') !== false) { continue; } $result[hsc($id)] = hsc($heading); } require_once DOKU_INC . 'inc/JSON.php'; $json = new JSON(); echo '(' . $json->encode($result) . ')'; }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> * @param string|array $title either string title or media array * @param string $default default title if nothing else is found * @param bool $isImage will be set to true if it's a media file * @param null|string $id linked page id (used to extract title from first heading) * @param string $linktype content|navigation * @return string HTML of the title, might be full image tag or just escaped text */ function _getLinkTitle($title, $default, &$isImage, $id = null, $linktype = 'content') { $isImage = false; if (is_array($title)) { $isImage = true; return $this->_imageTitle($title); } elseif (is_null($title) || trim($title) == '') { if (useHeading($linktype) && $id) { $heading = p_get_first_heading($id); if ($heading) { return $this->_xmlEntities($heading); } } return $this->_xmlEntities($default); } else { return $this->_xmlEntities($title); } }
/** * Construct a title and handle images in titles * * @author Harry Fuecks <*****@*****.**> */ function _getLinkTitle($title, $default, $id = null) { global $conf; $isImage = false; if (is_array($title)) { if ($title['title']) { return '[' . $title['title'] . ']'; } } else { if (is_null($title) || trim($title) == '') { if (useHeading('content') && $id) { $heading = p_get_first_heading($id, METADATA_DONT_RENDER); if ($heading) { return $heading; } } return $default; } else { return $title; } } }
/** * display backlinks * * @author Andreas Gohr <*****@*****.**> * @author Michael Klier <*****@*****.**> */ function html_backlinks() { global $ID; global $conf; global $lang; print p_locale_xhtml('backlinks'); $data = ft_backlinks($ID); if (!empty($data)) { print '<ul class="idx">'; foreach ($data as $blink) { print '<li><div class="li">'; print html_wikilink(':' . $blink, useHeading('navigation') ? null : $blink); print '</div></li>'; } print '</ul>'; } else { print '<div class="level1"><p>' . $lang['nothingfound'] . '</p></div>'; } }
function bootstrap3_page_browser_title() { global $conf, $ACT, $ID; if (bootstrap3_conf('browserTitleShowNS') && $ACT == 'show') { $ns_parts = explode(':', $ID); $ns_pages = array(); $ns_titles = array(); $ns_separator = sprintf(' %s ', bootstrap3_conf('browserTitleCharSepNS')); if (useHeading('navigation')) { if (count($ns_parts) > 1) { foreach ($ns_parts as $ns_part) { $ns_page .= "{$ns_part}:"; $ns_pages[] = $ns_page; } $ns_pages = array_unique($ns_pages); foreach ($ns_pages as $ns_page) { resolve_pageid(getNS($ns_page), $ns_page, $exists); $ns_page_title_heading = hsc(p_get_first_heading($ns_page)); $ns_page_title_page = noNSorNS($ns_page); $ns_page_title = $exists ? $ns_page_title_heading : $ns_page_title_page; if ($ns_page_title !== $conf['start']) { $ns_titles[] = $ns_page_title; } } } resolve_pageid(getNS($ID), $ID, $exists); if ($exists) { $ns_titles[] = tpl_pagetitle($ID, true); } $ns_titles = array_filter(array_unique($ns_titles)); } else { $ns_titles = $ns_parts; } if (bootstrap3_conf('browserTitleOrderNS') == 'normal') { $ns_titles = array_reverse($ns_titles); } $browser_title = implode($ns_separator, $ns_titles); } else { $browser_title = tpl_pagetitle($ID, true); } return str_replace(array('@WIKI@', '@TITLE@'), array(strip_tags($conf['title']), $browser_title), bootstrap3_conf('browserTitle')); }