function _printPlugin($pi) { include_once "lib/WikiPlugin.php"; static $loader; if (empty($loader)) { $loader = new WikiPluginLoader(); } $this->_print($loader->expandPI($pi, $this->_request, $this, $this->_basepage)); }
function displayPage(&$request, $template = false) { global $WikiTheme, $pv; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } } else { $revision = $page->getCurrentRevision(); } if (isSubPage($pagename)) { $pages = explode(SUBPAGE_SEPARATOR, $pagename); $last_page = array_pop($pages); // deletes last element from array as side-effect $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR))); $first_pages = $pages[0] . SUBPAGE_SEPARATOR; array_shift($pages); foreach ($pages as $p) { if ($pv != 2) { //Add the Backlink in page title $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); } else { // Remove Backlinks $pageheader->pushContent(HTML::h1($pagename)); } $first_pages .= $p . SUBPAGE_SEPARATOR; } if ($pv != 2) { $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $backlink = HTML::h1($pagename); } $pageheader->pushContent($backlink); } else { if ($pv != 2) { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); } else { $pageheader = HTML::h1($pagename); //Remove Backlinks } if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } // {{{ Codendi hook to insert stuff between navbar and header $eM =& EventManager::instance(); $ref_html = ''; $crossref_fact = new CrossReferenceFactory($pagename, ReferenceManager::REFERENCE_NATURE_WIKIPAGE, GROUP_ID); $crossref_fact->fetchDatas(); if ($crossref_fact->getNbReferences() > 0) { $ref_html .= '<h3>' . $GLOBALS['Language']->getText('cross_ref_fact_include', 'references') . '</h3>'; $ref_html .= $crossref_fact->getHTMLDisplayCrossRefs(); } $additional_html = false; $eM->processEvent('wiki_before_content', array('html' => &$additional_html, 'group_id' => GROUP_ID, 'wiki_page' => $pagename)); if ($additional_html) { $beforeHeader = HTML(); $beforeHeader->pushContent($additional_html); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } else { $beforeHeader = HTML(); $beforeHeader->pushContent(HTML::raw($ref_html)); $toks['BEFORE_HEADER'] = $beforeHeader; } // }}} /Codendi hook $pagetitle = SplitPagename($pagename); if ($redirect_from = $request->getArg('redirectfrom')) { $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from))); // abuse the $redirected template var for some status update notice } elseif ($request->getArg('errormsg')) { $redirect_message = $request->getArg('errormsg'); $request->setArg('errormsg', false); } $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); /* // FIXME: This is also in the template... if ($request->getArg('action') != 'pdf' and !headers_sent()) { // FIXME: enable MathML/SVG/... support if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ $page_content = $revision->getTransformedContent(); // if external searchengine (google) referrer, highlight the searchterm // FIXME: move that to the transformer? // OR: add the searchhightplugin line to the content? if ($result = isExternalReferrer($request)) { if (DEBUG and !empty($result['query'])) { //$GLOBALS['SearchHighlightQuery'] = $result['query']; /* simply add the SearchHighlight plugin to the top of the page. This just parses the wikitext, and doesn't highlight the markup */ include_once 'lib/WikiPlugin.php'; $loader = new WikiPluginLoader(); $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup); if ($xml and is_array($xml)) { foreach (array_reverse($xml) as $line) { array_unshift($page_content->_content, $line); } array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query']))); } if (0) { /* Parse the transformed (mixed HTML links + strings) lines? This looks like overkill. */ require_once "lib/TextSearchQuery.php"; $query = new TextSearchQuery($result['query']); $hilight_re = $query->getHighlightRegexp(); //$matches = preg_grep("/$hilight_re/i", $revision->getContent()); // FIXME! for ($i = 0; $i < count($page_content->_content); $i++) { $found = false; $line = $page_content->_content[$i]; if (is_string($line)) { while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) { $found = true; $line = substr($line, strlen($m[0])); $html[] = $m[1]; // prematch $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match } } if ($found) { $html[] = $line; // postmatch $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html); } } } } } $toks['CONTENT'] = new Template('browse', $request, $page_content); $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } $toks['ROBOTS_META'] = 'index,follow'; $toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } $template->printExpansion($toks); $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); } flush(); }
function handle_plugin_args_cruft($argstr, $args) { $allowed = array("editbox", "hidden", "checkbox", "radiobutton", "radio", "pulldown", "submit", "reset", "combobox"); // no editbox[] = array(...) allowed (space) $arg_array = preg_split("/\n/", $argstr); // for security we should check this better $arg = ''; for ($i = 0; $i < count($arg_array); $i++) { //TODO: we require an name=value pair here, but submit may go without also. if (preg_match("/^\\s*(" . join("|", $allowed) . ")\\[\\](.*)\$/", $arg_array[$i], $m)) { $name = $m[1]; // one of the allowed input types $this->inputbox[][$name] = array(); $j = count($this->inputbox) - 1; $curargs = trim($m[2]); // must match name=NAME and also value=<!plugin-list name !> while (preg_match("/^(\\w+)=((?:\".*\")|(?:\\w+)|(?:\"?<!plugin-list.+!>\"?))\\s*/", $curargs, $m)) { $attr = $m[1]; $value = $m[2]; $curargs = substr($curargs, strlen($m[0])); if (preg_match("/^\"(.*)\"\$/", $value, $m)) { $value = $m[1]; } if (in_array($name, array("pulldown", "checkbox", "radio", "radiobutton", "combobox")) and preg_match('/^<!plugin-list.+!>$/', $value, $m)) { $loader = new WikiPluginLoader(); $markup = null; $basepage = null; $plugin_str = preg_replace(array("/^<!/", "/!>\$/"), array("<?", "?>"), $value); // will return a pagelist object! pulldown,checkbox,radiobutton $value = $loader->expandPI($plugin_str, $GLOBALS['request'], $markup, $basepage); if (isa($value, 'PageList')) { $value = $value->_pages; } elseif (!is_array($value)) { trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])), E_USER_WARNING); } } elseif (defined($value)) { $value = constant($value); } $this->inputbox[$j][$name][$attr] = $value; } //trigger_error("not yet finished"); //eval('$this->inputbox[]["'.$m[1].'"]='.$m[2].';'); } else { trigger_error(sprintf("Invalid argument %s ignored", htmlentities($arg_array[$i])), E_USER_WARNING); } } return; }
function getHtml($dbi, $argarray, $request, $basepage) { $loader = new WikiPluginLoader(); return $loader->expandPI('<?plugin RecentChanges ' . WikiPluginCached::glueArgs($argarray) . ' ?>', $request, $this, $basepage); }
function parseArgStr($argstr) { $args = array(); $defaults = array(); if (empty($argstr)) { return array($args, $defaults); } $arg_p = '\\w+'; $op_p = '(?:\\|\\|)?='; $word_p = '\\S+'; $opt_ws = '\\s*'; $qq_p = '" ( (?:[^"\\\\]|\\\\.)* ) "'; //"<--kludge for brain-dead syntax coloring $q_p = "' ( (?:[^'\\\\]|\\\\.)* ) '"; $gt_p = "_\\( {$opt_ws} {$qq_p} {$opt_ws} \\)"; $argspec_p = "({$arg_p}) {$opt_ws} ({$op_p}) {$opt_ws} (?: {$qq_p}|{$q_p}|{$gt_p}|({$word_p}))"; // handle plugin-list arguments seperately $plugin_p = '<!plugin-list\\s+\\w+.*?!>'; while (preg_match("/^({$arg_p}) {$opt_ws} ({$op_p}) {$opt_ws} ({$plugin_p}) {$opt_ws}/x", $argstr, $m)) { @(list(, $arg, $op, $plugin_val) = $m); $argstr = substr($argstr, strlen($m[0])); $loader = new WikiPluginLoader(); $markup = null; $basepage = null; $plugin_val = preg_replace(array("/^<!/", "/!>\$/"), array("<?", "?>"), $plugin_val); $val = $loader->expandPI($plugin_val, $GLOBALS['request'], $markup, $basepage); if ($op == '=') { $args[$arg] = $val; // comma delimited pagenames or array()? } else { assert($op == '||='); $defaults[$arg] = $val; } } while (preg_match("/^{$opt_ws} {$argspec_p} {$opt_ws}/x", $argstr, $m)) { @(list(, $arg, $op, $qq_val, $q_val, $gt_val, $word_val) = $m); $argstr = substr($argstr, strlen($m[0])); // Remove quotes from string values. if ($qq_val) { $val = stripslashes($qq_val); } elseif ($q_val) { $val = stripslashes($q_val); } elseif ($gt_val) { $val = _(stripslashes($gt_val)); } else { $val = $word_val; } if ($op == '=') { $args[$arg] = $val; } else { // NOTE: This does work for multiple args. Use the // separator character defined in your webserver // configuration, usually & or & (See // http://www.htmlhelp.com/faq/cgifaq.4.html) // e.g. <plugin RecentChanges days||=1 show_all||=0 show_minor||=0> // url: RecentChanges?days=1&show_all=1&show_minor=0 assert($op == '||='); $defaults[$arg] = $val; } } if ($argstr) { $this->handle_plugin_args_cruft($argstr, $args); } return array($args, $defaults); }
function actionPage(&$request, $action) { global $WikiTheme; global $robots; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); $revision = $page->getCurrentRevision(); $dbi = $request->getDbh(); $actionpage = $dbi->getPage($action); $actionrev = $actionpage->getCurrentRevision(); $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version))); $request->setValidators(array('pageversion' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime'))); $transformedContent = $actionrev->getTransformedContent(); /* Optionally tell google (and others) not to take notice of action pages. RecentChanges or AllPages might be an exception. */ $args = array(); if (GOOGLE_LINKS_NOFOLLOW) { $robots = "noindex,nofollow"; $args = array('ROBOTS_META' => $robots); } /* Handle other formats: So far we had html only. xml is requested by loaddump, rss is handled by recentchanges, pdf is a special action, but should be a format to dump multiple pages if the actionpage plugin returns a pagelist. rdf and owl are handled by SemanticWeb. */ $format = $request->getArg('format'); /* At first the single page formats: html, xml */ if ($pagename == _("LinkDatabase")) { $template = Template('browse', array('CONTENT' => $transformedContent)); GeneratePage($template, $pagetitle, $revision, $args); } elseif (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') { $template = Template('browse', array('CONTENT' => $transformedContent)); GeneratePage($template, $pagetitle, $revision, $args); } elseif ($format == 'xml') { $request->setArg('format', ''); $template = new Template('browse', $request, array('revision' => $revision, 'CONTENT' => $transformedContent)); $html = GeneratePageAsXML($template, $pagename, $revision); header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); echo $html; } else { $pagelist = null; require_once 'lib/WikiPlugin.php'; // Then the multi-page formats // rss (if not already handled by RecentChanges) // Need the pagelist from the first plugin foreach ($transformedContent->_content as $cached_element) { if (is_a($cached_element, "Cached_PluginInvocation")) { $loader = new WikiPluginLoader(); $markup = null; // return the first found pagelist $pagelist = $loader->expandPI($cached_element->_pi, $request, $markup, $pagename); if (is_a($pagelist, 'PageList')) { break; } } } if (!$pagelist or !is_a($pagelist, 'PageList')) { if (!in_array($format, array("rss91", "rss2", "rss", "atom", "rdf"))) { trigger_error(sprintf("Format %s requires an actionpage returning a pagelist.", $format) . "\n" . "Fall back to single page mode", E_USER_WARNING); } require_once 'lib/PageList.php'; $pagelist = new PageList(); if ($format == 'pdf') { $pagelist->addPage($page); } } else { foreach ($pagelist->_pages as $page) { $name = $page->getName(); if ($name != $pagename and $page->exists()) { $args['VALID_LINKS'][] = $name; } } } if ($format == 'pdf') { require_once "lib/pdf.php"; array_unshift($args['VALID_LINKS'], $pagename); ConvertAndDisplayPdfPageList($request, $pagelist, $args); } elseif ($format == 'ziphtml') { // need to fix links require_once 'lib/loadsave.php'; array_unshift($args['VALID_LINKS'], $pagename); $request->setArg('zipname', FilenameForPage($pagename) . ".zip"); $request->setArg('pages', $args['VALID_LINKS']); $request->setArg('format', ''); MakeWikiZipHtml($request); } elseif (in_array($format, array("rss91", "rss2", "rss", "atom"))) { $args = $request->getArgs(); //$request->setArg('format',''); if ($pagename == _("RecentChanges")) { $template->printExpansion($args); } else { require_once "lib/plugin/RecentChanges.php"; $plugin = new WikiPlugin_RecentChanges(); return $plugin->format($plugin->getChanges($request->_dbi, $args), $args); } } elseif ($format == 'json') { // for faster autocompletion on searches $req_args =& $request->args; unset($req_args['format']); $json = array('count' => count($pagelist->_pages), 'list' => $args['VALID_LINKS'], 'args' => $req_args, 'phpwiki-version' => PHPWIKI_VERSION); if (loadPhpExtension('json')) { $json_enc = json_encode($json); } else { require_once "lib/pear/JSON.php"; $j = new Services_JSON(); $json_enc = $j->encode($json); } header("Content-Type: application/json"); die($json_enc); } elseif ($format == 'rdf') { // all semantic relations and attributes require_once "lib/SemanticWeb.php"; $rdf = new RdfWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'rdfs') { require_once "lib/SemanticWeb.php"; $rdf = new RdfsWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'owl') { // or daml? require_once "lib/SemanticWeb.php"; $rdf = new OwlWriter($request, $pagelist); $rdf->format(); } else { if (!in_array($pagename, array(_("LinkDatabase")))) { trigger_error(sprintf(_("Unsupported argument: %s=%s"), "format", $format), E_USER_WARNING); } $template = Template('browse', array('CONTENT' => $transformedContent)); GeneratePage($template, $pagetitle, $revision, $args); } } $request->checkValidators(); flush(); return ''; }
function displayPage(&$request, $template = false) { global $WikiTheme; $pagename = $request->getArg('pagename'); $version = $request->getArg('version'); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } /* Tell Google (and others) to ignore old versions of pages */ $toks['ROBOTS_META'] = "noindex,nofollow"; } else { $revision = $page->getCurrentRevision(); } if (isSubPage($pagename)) { $pages = explode(SUBPAGE_SEPARATOR, $pagename); $last_page = array_pop($pages); // deletes last element from array as side-effect $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]), 'class' => 'pagetitle'), $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR))); $first_pages = $pages[0] . SUBPAGE_SEPARATOR; array_shift($pages); foreach ($pages as $p) { $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR))); $first_pages .= $p . SUBPAGE_SEPARATOR; } $backlink = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($last_page)); $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); $pageheader->pushContent($backlink); } else { $pageheader = HTML::a(array('href' => WikiURL($pagename, array('action' => _("BackLinks"))), 'class' => 'backlinks'), $WikiTheme->maybeSplitWikiWord($pagename)); $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename)); if ($request->getArg('frame')) { $pageheader->setAttr('target', '_top'); } } $pagetitle = SplitPagename($pagename); if ($redirect_from = $request->getArg('redirectfrom')) { $redirect_message = HTML::span(array('class' => 'redirectfrom'), fmt("(Redirected from %s)", RedirectorLink($redirect_from))); // abuse the $redirected template var for some status update notice } elseif ($request->getArg('errormsg')) { $redirect_message = $request->getArg('errormsg'); $request->setArg('errormsg', false); } $request->appendValidators(array('pagerev' => $revision->getVersion(), '%mtime' => $revision->get('mtime'))); /* // FIXME: This is also in the template... if ($request->getArg('action') != 'pdf' and !headers_sent()) { // FIXME: enable MathML/SVG/... support if (ENABLE_XHTML_XML and (!isBrowserIE() and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml'))) header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']); else header("Content-Type: text/html; charset=" . $GLOBALS['charset']); } */ $page_content = $revision->getTransformedContent(); // if external searchengine (google) referrer, highlight the searchterm // FIXME: move that to the transformer? // OR: add the searchhightplugin line to the content? if ($result = isExternalReferrer($request)) { if (DEBUG and !empty($result['query'])) { //$GLOBALS['SearchHighlightQuery'] = $result['query']; /* simply add the SearchHighlight plugin to the top of the page. This just parses the wikitext, and doesn't highlight the markup */ include_once 'lib/WikiPlugin.php'; $loader = new WikiPluginLoader(); $xml = $loader->expandPI('<' . '?plugin SearchHighlight s="' . $result['query'] . '"?' . '>', $request, $markup); if ($xml and is_array($xml)) { foreach (array_reverse($xml) as $line) { array_unshift($page_content->_content, $line); } array_unshift($page_content->_content, HTML::div(_("You searched for: "), HTML::strong($result['query']))); } if (0) { /* Parse the transformed (mixed HTML links + strings) lines? This looks like overkill. */ require_once "lib/TextSearchQuery.php"; $query = new TextSearchQuery($result['query']); $hilight_re = $query->getHighlightRegexp(); //$matches = preg_grep("/$hilight_re/i", $revision->getContent()); // FIXME! for ($i = 0; $i < count($page_content->_content); $i++) { $found = false; $line = $page_content->_content[$i]; if (is_string($line)) { while (preg_match("/^(.*?)({$hilight_re})/i", $line, $m)) { $found = true; $line = substr($line, strlen($m[0])); $html[] = $m[1]; // prematch $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match } } if ($found) { $html[] = $line; // postmatch $page_content->_content[$i] = HTML::span(array('class' => 'search-context'), $html); } } } } } /* Check for special pagenames */ /* if ( $pagename == _("RecentChanges") || $pagename == _("RecentEdits") || $pagename == _("RecentVisitors")) { $toks['ROBOTS_META']="noindex,follow"; } else */ if ($pagename == _("SandBox")) { $toks['ROBOTS_META'] = "noindex,nofollow"; } else { if (!isset($toks['ROBOTS_META'])) { $toks['ROBOTS_META'] = "index,follow"; } } $toks['CONTENT'] = new Template('browse', $request, $page_content); $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } $toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } $template->printExpansion($toks); $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $request->checkValidators(); } flush(); }