function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); $pagename = $page; $page = $request->getPage(); $current = $page->getCurrentRevision(); if ($current->getVersion() < 1) { return fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown')); } if (!empty($version)) { if (!($revision = $page->getRevision($version))) { NoSuchRevision($request, $page, $version); } } else { $revision = $current; } $template = new Template('info', $request, array('revision' => $revision)); return $template; }
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 run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if (is_array($versions)) { // Version selection from pageinfo.php display: rsort($versions); list($version, $previous) = $versions; } // abort if page doesn't exist $page = $request->getPage($pagename); $current = $page->getCurrentRevision(); if ($current->getVersion() < 1) { $html = HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown')))); return $html; //early return } if ($version) { if (!($new = $page->getRevision($version))) { NoSuchRevision($request, $page, $version); } $new_version = fmt("version %d", $version); } else { $new = $current; $new_version = _("current version"); } if (preg_match('/^\\d+$/', $previous)) { if (!($old = $page->getRevision($previous))) { NoSuchRevision($request, $page, $previous); } $old_version = fmt("version %d", $previous); $others = array('major', 'minor', 'author'); } else { switch ($previous) { case 'author': $old = $new; while ($old = $page->getRevisionBefore($old)) { if ($old->get('author') != $new->get('author')) { break; } } $old_version = _("revision by previous author"); $others = array('major', 'minor'); break; case 'minor': $previous = 'minor'; $old = $page->getRevisionBefore($new); $old_version = _("previous revision"); $others = array('major', 'author'); break; case 'major': default: $old = $new; while ($old && $old->get('is_minor_edit')) { $old = $page->getRevisionBefore($old); } if ($old) { $old = $page->getRevisionBefore($old); } $old_version = _("predecessor to the previous major change"); $others = array('minor', 'author'); break; } } $new_link = WikiLink($new, '', $new_version); $old_link = $old ? WikiLink($old, '', $old_version) : $old_version; $page_link = WikiLink($page); $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link))); $otherdiffs = HTML::p(_("Other diffs:")); $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author")); foreach ($others as $other) { $args = array('pagename' => $pagename, 'previous' => $other); if ($version) { $args['version'] = $version; } if (count($otherdiffs->getContent()) > 1) { $otherdiffs->pushContent(", "); } else { $otherdiffs->pushContent(" "); } $otherdiffs->pushContent(Button($args, $label[$other])); } $html->pushContent($otherdiffs); if ($old and $old->getVersion() == 0) { $old = false; } $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new, $request), $this->PageInfoRow(_("Older page:"), $old, $request))); if ($new && $old) { $diff = new Diff($old->getContent(), $new->getContent()); if ($diff->isEmpty()) { $html->pushContent(HTML::hr(), HTML::p('[', _("Versions are identical"), ']')); } else { // New CSS formatted unified diffs (ugly in NS4). $fmt = new HtmlUnifiedDiffFormatter(); // Use this for old table-formatted diffs. //$fmt = new TableUnifiedDiffFormatter; $html->pushContent($fmt->format($diff)); } } //$html = HTML::tt(fmt('%s: %s', $salutation, WikiLink($name, 'auto')), // THE_END); return $html; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); if (is_array($versions)) { // Version selection from pageinfo.php display: rsort($versions); list($version, $previous) = $versions; } // Check if user is allowed to get the Page. if (!mayAccessPage('view', $pagename)) { return $this->error(sprintf(_("Illegal access to page %s: no read access"), $pagename)); } // abort if page doesn't exist $page = $request->getPage($pagename); $current = $page->getCurrentRevision(); if ($current->getVersion() < 1) { $html = HTML(HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown')))); return $html; //early return } if ($version) { if (!($new = $page->getRevision($version))) { NoSuchRevision($request, $page, $version); } $new_version = fmt("version %d", $version); } else { $new = $current; $new_version = _("current version"); } if (preg_match('/^\\d+$/', $previous)) { if (!($old = $page->getRevision($previous))) { NoSuchRevision($request, $page, $previous); } $old_version = fmt("version %d", $previous); $others = array('major', 'minor', 'author'); } else { switch ($previous) { case 'author': $old = $new; while ($old = $page->getRevisionBefore($old)) { if ($old->get('author') != $new->get('author')) { break; } } $old_version = _("revision by previous author"); $others = array('major', 'minor'); break; case 'minor': $previous = 'minor'; $old = $page->getRevisionBefore($new); $old_version = _("previous revision"); $others = array('major', 'author'); break; case 'major': default: $old = $new; while ($old && $old->get('is_minor_edit')) { $old = $page->getRevisionBefore($old); } if ($old) { $old = $page->getRevisionBefore($old); } $old_version = _("predecessor to the previous major change"); $others = array('minor', 'author'); break; } } $new_link = WikiLink($new, '', $new_version); $old_link = $old ? WikiLink($old, '', $old_version) : $old_version; $page_link = WikiLink($page); $html = HTML(HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link))); $otherdiffs = HTML::p(_("Other diffs:")); $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author")); foreach ($others as $other) { $args = array('pagename' => $pagename, 'previous' => $other); if ($version) { $args['version'] = $version; } if (count($otherdiffs->getContent()) > 1) { $otherdiffs->pushContent(", "); } else { $otherdiffs->pushContent(" "); } $otherdiffs->pushContent(Button($args, $label[$other])); } $html->pushContent($otherdiffs); if ($old and $old->getVersion() == 0) { $old = false; } $html->pushContent(HTML::Table($this->PageInfoRow(_("Newer page:"), $new, $request), $this->PageInfoRow(_("Older page:"), $old, $request))); if ($new && $old) { $diff = new Diff($old->getContent(), $new->getContent()); if ($diff->isEmpty()) { $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical."))); // If two consecutive versions have the same content, it is because the page was // renamed, or metadata changed: ACL, owner, markup. // We give the reason by printing the summary. if ($new->getVersion() - $old->getVersion() == 1) { $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary'))); } } else { $fmt = new HtmlUnifiedDiffFormatter(); $html->pushContent($fmt->format($diff)); } } return $html; }
function showDiff(&$request) { $pagename = $request->getArg('pagename'); if (is_array($versions = $request->getArg('versions'))) { // Version selection from pageinfo.php display: rsort($versions); list($version, $previous) = $versions; } else { $version = $request->getArg('version'); $previous = $request->getArg('previous'); } // abort if page doesn't exist $dbi = $request->getDbh(); $page = $request->getPage(); $current = $page->getCurrentRevision(false); if ($current->getVersion() < 1) { $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("I'm sorry, there is no such page as %s.", WikiLink($pagename, 'unknown')))); require_once 'lib/Template.php'; GeneratePage($html, sprintf(_("Diff: %s"), $pagename), false); return; //early return } if ($version) { if (!($new = $page->getRevision($version))) { NoSuchRevision($request, $page, $version); } $new_version = fmt("version %d", $version); } else { $new = $current; $new_version = _("current version"); } if (preg_match('/^\\d+$/', $previous)) { if (!($old = $page->getRevision($previous))) { NoSuchRevision($request, $page, $previous); } $old_version = fmt("version %d", $previous); $others = array('major', 'minor', 'author'); } else { switch ($previous) { case 'author': $old = $new; while ($old = $page->getRevisionBefore($old)) { if ($old->get('author') != $new->get('author')) { break; } } $old_version = _("revision by previous author"); $others = array('major', 'minor'); break; case 'minor': $previous = 'minor'; $old = $page->getRevisionBefore($new); $old_version = _("previous revision"); $others = array('major', 'author'); break; case 'major': default: $old = $new; while ($old && $old->get('is_minor_edit')) { $old = $page->getRevisionBefore($old); } if ($old) { $old = $page->getRevisionBefore($old); } $old_version = _("predecessor to the previous major change"); $others = array('minor', 'author'); break; } } $new_link = WikiLink($new, '', $new_version); $old_link = $old ? WikiLink($old, '', $old_version) : $old_version; $page_link = WikiLink($page); $html = HTML::div(array('class' => 'wikitext', 'id' => 'difftext'), HTML::p(fmt("Differences between %s and %s of %s.", $new_link, $old_link, $page_link))); $otherdiffs = HTML::p(_("Other diffs:")); $label = array('major' => _("Previous Major Revision"), 'minor' => _("Previous Revision"), 'author' => _("Previous Author")); foreach ($others as $other) { $args = array('action' => 'diff', 'previous' => $other); if ($version) { $args['version'] = $version; } if (count($otherdiffs->getContent()) > 1) { $otherdiffs->pushContent(", "); } else { $otherdiffs->pushContent(" "); } $otherdiffs->pushContent(Button($args, $label[$other])); } $html->pushContent($otherdiffs); if ($old and $old->getVersion() == 0) { $old = false; } $html->pushContent(HTML::Table(PageInfoRow(_("Newer page:"), $new, $request, empty($version)), PageInfoRow(_("Older page:"), $old, $request, false))); if ($new && $old) { $diff = new Diff($old->getContent(), $new->getContent()); if ($diff->isEmpty()) { $html->pushContent(HTML::hr(), HTML::p(_("Content of versions "), $old->getVersion(), _(" and "), $new->getVersion(), _(" is identical."))); // If two consecutive versions have the same content, it is because the page was // renamed, or metadata changed: ACL, owner, markup. // We give the reason by printing the summary. if ($new->getVersion() - $old->getVersion() == 1) { $html->pushContent(HTML::p(_("Version "), $new->getVersion(), _(" was created because: "), $new->get('summary'))); } } else { $fmt = new HtmlUnifiedDiffFormatter(); $html->pushContent($fmt->format($diff)); } $html->pushContent(HTML::hr(), HTML::h2($new_version)); require_once "lib/BlockParser.php"; $html->pushContent(TransformText($new, $new->get('markup'), $pagename)); } require_once 'lib/Template.php'; GeneratePage($html, sprintf(_("Diff: %s"), $pagename), $new); }
function _initializeState() { $request =& $this->request; $current =& $this->current; $selected =& $this->selected; $user =& $this->user; if (!$selected) { NoSuchRevision($request, $this->page, $this->version); } // noreturn $this->_currentVersion = $current->getVersion(); $this->_content = $selected->getPackedContent(); $this->locked = $this->page->get('locked'); // If author same as previous author, default minor_edit to on. $age = $this->meta['mtime'] - $current->get('mtime'); $this->meta['is_minor_edit'] = $age < MINOR_EDIT_TIMEOUT && $current->get('author') == $user->getId(); // Default for new pages is new-style markup. if ($selected->hasDefaultContents()) { $is_new_markup = true; } else { $is_new_markup = $selected->get('markup') >= 2.0; } $this->meta['markup'] = $is_new_markup ? 2.0 : false; $this->meta['pagetype'] = $selected->get('pagetype'); if ($this->meta['pagetype'] == 'wikiblog') { $this->meta['summary'] = $selected->get('summary'); } else { $this->meta['summary'] = ''; } $this->editaction = 'edit'; }
function run($dbi, $argstr, &$request, $basepage) { extract($this->getArgs($argstr, $request)); $page = $dbi->getPage($pagename); $current = $page->getCurrentRevision(); $source = $current->getPackedContent(); if (empty($source)) { return $this->error(fmt("empty source")); } if ($basepage == _("SpellCheck")) { return $this->error(fmt("Cannot SpellCheck myself")); } $lang = $page->get('lang'); if (empty($lang)) { $lang = $GLOBALS['LANG']; } $html = HTML(); if (!function_exists('pspell_new_config')) { // use the aspell commandline interface include_once "lib/WikiPluginCached.php"; $args = ""; $source = preg_replace("/^/m", "^", $source); if (ASPELL_DATA_DIR) { $args .= " --data-dir=" . ASPELL_DATA_DIR; } // MAYBE TODO: do we have the language dictionary? $args .= " --lang=" . $lang; // use -C or autosplit wikiwords in the text $commandLine = ASPELL_EXE . " -a -C {$args} "; $cache = new WikiPluginCached(); $code = $cache->filterThroughCmd($source, $commandLine); if (empty($code)) { return $this->error(fmt("Couldn't start commandline '%s'", $commandLine)); } $sugg = array(); foreach (preg_split("/\n/", $code) as $line) { if (preg_match("/^& (\\w+) \\d+ \\d+: (.+)\$/", $line, $m)) { $sugg[$m[1]] = preg_split("/, /", $m[2]); } } /*$pre = HTML::pre(HTML::raw($code)); $html->pushContent($pre);*/ } else { $sugg = pspell_check($source, $lang); } //$html->pushContent(HTML::hr(),HTML::h1(_("Spellcheck"))); $page = $request->getPage(); if ($version) { $revision = $page->getRevision($version); if (!$revision) { NoSuchRevision($request, $page, $version); } } else { $revision = $page->getCurrentRevision(); } $GLOBALS['request']->setArg('suggestions', $sugg); include_once "lib/BlockParser.php"; $ori_html = TransformText($revision, $revision->get('markup'), $page); $GLOBALS['request']->setArg('suggestions', false); $html->pushContent($ori_html, HTML::hr(), HTML::h1(_("SpellCheck result"))); $list = HTML::ul(); foreach ($sugg as $word => $suggs) { $w = HTML::span(array('class' => 'spell-wrong'), $word); // TODO: optional replace-link. jscript or request button with word replace. $r = HTML(); foreach ($suggs as $s) { $r->pushContent(HTML::a(array('class' => 'spell-sugg', 'href' => "javascript:do_replace('{$word}','{$s}')"), $s), ", "); } $list->pushContent(HTML::li($w, ": ", $r)); } $html->pushContent($list); return $html; }
function displayPage(&$request, $template = false) { global $WikiTheme; global $robots; $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 */ $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { $revision = $page->getCurrentRevision(); } $format = $request->getArg('format'); if ($format == 'xml') { // fast ajax: include page content asynchronously global $charset; header("Content-Type: text/xml"); echo "<", "?xml version=\"1.0\" encoding=\"{$charset}\"?", ">\n"; // DOCTYPE html needed to allow unencoded entities like without !CDATA[] echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n"; if ($page->exists()) { header("Last-Modified: " . Rfc1123DateTime($revision->get('mtime'))); $request->cacheControl(); $request->setArg('format', ''); $page_content = $revision->getTransformedContent(); $page_content->printXML(); $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); } else { $request->cacheControl(); echo '<div style="display:none;" />'; $request->_is_buffering_output = false; // avoid wrong Content-Length with errors $request->finish(); exit; } } 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']); } */ $toks['TITLE'] = $pagetitle; // <title> tag $toks['HEADER'] = $pageheader; // h1 with backlink $toks['revision'] = $revision; // On external searchengine (google) referrer, highlight the searchterm and // pass through the Searchhighlight actionpage. if ($result = isExternalReferrer($request)) { if (!empty($result['query'])) { if (ENABLE_SEARCHHIGHLIGHT) { $request->_searchhighlight = $result; $request->appendValidators(array('%mtime' => time())); // force no cache(?) // Should be changed to check the engine and search term only // $request->setArg('nocache', 1); $page_content = new TransformedText($revision->getPage(), $revision->getPackedContent(), $revision->getMetaData()); /* Now add the SearchHighlight plugin to the top of the page, in memory only. You can parametrize this by changing the SearchHighlight action page. */ if ($actionpage = $request->findActionPage('SearchHighlight')) { $actionpage = $request->getPage($actionpage); $actionrev = $actionpage->getCurrentRevision(); $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(), $WikiTheme->linkExistingWikiWord($pagename, false, $version))); $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(), '%mtime' => $actionrev->get('mtime'))); $toks['SEARCH_ENGINE'] = $result['engine']; $toks['SEARCH_ENGINE_URL'] = $result['engine_url']; $toks['SEARCH_TERM'] = $result['query']; //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink $actioncontent = new TransformedText($actionrev->getPage(), $actionrev->getPackedContent(), $actionrev->getMetaData()); // prepend the actionpage in front of the hightlighted content $toks['CONTENT'] = HTML($actioncontent, $page_content); } } } else { $page_content = $revision->getTransformedContent(); } } else { $page_content = $revision->getTransformedContent(); } /* Check for special pagenames, which are no actionpages. */ /* if ( $pagename == _("RecentVisitors")) { $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else */ if ($pagename == _("SandBox")) { $robots = "noindex,nofollow"; $toks['ROBOTS_META'] = $robots; } else { if (isActionPage($pagename)) { // AllPages must not be indexed, but must be followed to get all pages $robots = "noindex,follow"; $toks['ROBOTS_META'] = $robots; } else { if (!isset($toks['ROBOTS_META'])) { $robots = "index,follow"; $toks['ROBOTS_META'] = $robots; } } } if (!isset($toks['CONTENT'])) { $toks['CONTENT'] = new Template('browse', $request, $page_content); } if (!empty($redirect_message)) { $toks['redirected'] = $redirect_message; } // Massive performance problem parsing at run-time into all xml objects // looking for p's. Should be optional, if not removed at all. //$toks['PAGE_DESCRIPTION'] = $page_content->getDescription(); $toks['PAGE_KEYWORDS'] = GleanKeywords($page); if (!$template) { $template = new Template('html', $request); } // 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, owl, kbmodel, daml, ... are handled by SemanticWeb. /* Only single page versions. rss only if not already handled by RecentChanges. */ if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') { $template->printExpansion($toks); } else { // No pagelist here. Single page version only require_once "lib/PageList.php"; $pagelist = new PageList(); $pagelist->addPage($page); if ($format == 'pdf') { require_once "lib/pdf.php"; $request->setArg('format', ''); ConvertAndDisplayPdfPageList($request, $pagelist); // time-sorted rdf a la RecentChanges } elseif (in_array($format, array("rss91", "rss2", "rss", "atom"))) { //$request->setArg('format',''); if ($pagename == _("RecentChanges")) { $template->printExpansion($toks); } else { require_once "lib/plugin/RecentChanges.php"; $plugin = new WikiPlugin_RecentChanges(); $args = $request->getArgs(); return $plugin->format($plugin->getChanges($request->_dbi, $args), $args); } } elseif ($format == 'rdf') { // all semantic relations and attributes require_once "lib/SemanticWeb.php"; $rdf = new RdfWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'owl') { // or daml? require_once "lib/SemanticWeb.php"; $rdf = new OwlWriter($request, $pagelist); $rdf->format(); } elseif ($format == 'json') { // include page content asynchronously $request->setArg('format', ''); if ($page->exists()) { $content = $page_content->asXML(); } else { $content = ''; } $req_args = $request->args; unset($req_args['format']); // no meta-data so far, just the content $json = array('content' => $content, '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); } else { if (!in_array($pagename, array(_("LinkDatabase")))) { trigger_error(sprintf(_("Unsupported argument: %s=%s"), "format", $format), E_USER_WARNING); } $template->printExpansion($toks); } } $page->increaseHitCount(); if ($request->getArg('action') != 'pdf') { $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(); }