2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.71 2007-02-17 22:39:05 rurban Exp $');
5 require_once('lib/Template.php');
8 * Extract keywords from Category* links on page.
10 function GleanKeywords ($page) {
11 if (!defined('KEYWORDS')) return '';
12 include_once("lib/TextSearchQuery.php");
13 $search = new TextSearchQuery(KEYWORDS, true);
14 $KeywordLinkRegexp = $search->asRegexp();
15 // iterate over the pagelinks (could be a large number) [15ms on PluginManager]
16 // or do a titleSearch and check the categories if they are linked?
17 $links = $page->getPageLinks();
18 $keywords[] = SplitPagename($page->getName());
19 while ($link = $links->next()) {
20 if (preg_match($KeywordLinkRegexp, $link->getName(), $m))
21 $keywords[] = SplitPagename($m[0]);
23 $keywords[] = WIKI_NAME;
24 return join(', ', $keywords);
27 /** Make a link back to redirecting page.
29 * @param $pagename string Name of redirecting page.
30 * @return XmlContent Link to the redirecting page.
32 function RedirectorLink($pagename) {
33 $url = WikiURL($pagename, array('redirectfrom' => ''));
34 return HTML::a(array('class' => 'redirectfrom wiki',
40 function actionPage(&$request, $action) {
43 $pagename = $request->getArg('pagename');
44 $version = $request->getArg('version');
46 $page = $request->getPage();
47 $revision = $page->getCurrentRevision();
49 $dbi = $request->getDbh();
50 $actionpage = $dbi->getPage($action);
51 $actionrev = $actionpage->getCurrentRevision();
53 $pagetitle = HTML(fmt("%s: %s",
54 $actionpage->getName(),
55 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
57 $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
58 '%mtime' => $revision->get('mtime')));
60 $request->appendValidators(array('pagerev' => $revision->getVersion(),
61 '%mtime' => $revision->get('mtime')));
62 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
63 '%mtime' => $actionrev->get('mtime')));
65 $transformedContent = $actionrev->getTransformedContent();
67 /* Optionally tell google (and others) not to take notice of action pages.
68 RecentChanges or AllPages might be an exception.
71 if (GOOGLE_LINKS_NOFOLLOW)
72 $args = array('ROBOTS_META' => "noindex,nofollow");
74 /* Handle other formats: So far we had html only.
75 xml is requested by loaddump, rss is handled by recentchanges,
76 pdf is a special action, but should be a format to dump multiple pages
77 if the actionpage plugin returns a pagelist.
78 rdf and owl are handled by SemanticWeb.
80 $format = $request->getArg('format');
81 /* At first the single page formats: html, xml */
82 if (!$format or $format == 'html' or $format == 'sidebar') {
83 $template = Template('browse', array('CONTENT' => $transformedContent));
84 GeneratePage($template, $pagetitle, $revision, $args);
85 } elseif ($format == 'xml') {
86 $template = Template('browse', array('CONTENT' => $transformedContent));
87 GeneratePageAsXML($template, $pagetitle, $revision, $args);
90 include_once('lib/WikiPlugin.php');
91 // Then the multi-page formats
92 // rss (if not already handled by RecentChanges)
93 // Need the pagelist from the first plugin
94 foreach($transformedContent->_content as $cached_element) {
95 if (is_a($cached_element, "Cached_PluginInvocation")) {
96 $loader = new WikiPluginLoader;
98 // return the first found pagelist
99 $pagelist = $loader->expandPI($cached_element->_pi, $request, $markup, $pagename);
100 if (is_a($pagelist, 'PageList'))
104 if (!$pagelist or !is_a($pagelist, 'PageList')) {
105 if (!in_array($format, array("rss91","rss2","rss","atom","rdf")))
106 trigger_error(sprintf("Format %s requires an actionpage returning a pagelist.", $format)
107 ."\n".("Fall back to single page mode"), E_USER_WARNING);
108 $pagelist = new PageList();
109 $pagelist->addPage($page);
111 if ($format == 'pdf') {
112 include_once("lib/pdf.php");
113 ConvertAndDisplayPdfPageList($request, $pagelist);
114 } elseif (in_array($format, array("rss91","rss2","rss"))) {
115 if ($pagename == _("RecentChanges")) {
116 $template->printExpansion($toks);
118 include_once("lib/plugin/RecentChanges.php");
119 $plugin = new WikiPlugin_RecentChanges();
120 $args = $request->getargs();
121 return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
123 } elseif ($format == 'atom') {
124 include_once("lib/RssWriter.php");
125 $rdf = new AtomFeed($request, $pagelist);
127 } elseif ($format == 'rdf') { // all semantic relations and attributes
128 include_once("lib/SemanticWeb.php");
129 $rdf = new RdfWriter($request, $pagelist);
131 } elseif ($format == 'owl') {
132 include_once("lib/SemanticWeb.php");
133 $rdf = new OwlWriter($request, $pagelist);
135 } elseif ($format == 'kbmodel') {
136 include_once("lib/SemanticWeb.php");
137 $model = new ModelWriter($request, $pagelist);
140 trigger_error(sprintf("Unhandled format %s. Reverting to html", $format), E_USER_WARNING);
141 $template = Template('browse', array('CONTENT' => $transformedContent));
142 GeneratePage($template, $pagetitle, $revision, $args);
145 $request->checkValidators();
149 function displayPage(&$request, $template=false) {
151 $pagename = $request->getArg('pagename');
152 $version = $request->getArg('version');
153 $page = $request->getPage();
155 $revision = $page->getRevision($version);
157 NoSuchRevision($request, $page, $version);
158 /* Tell Google (and others) to ignore old versions of pages */
159 $toks['ROBOTS_META'] = "noindex,nofollow";
162 $revision = $page->getCurrentRevision();
165 if (isSubPage($pagename)) {
166 $pages = explode(SUBPAGE_SEPARATOR, $pagename);
167 $last_page = array_pop($pages); // deletes last element from array as side-effect
168 $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
169 'class' => 'pagetitle'
171 $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
172 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
174 foreach ($pages as $p) {
175 $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
176 'class' => 'backlinks'),
177 $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
178 $first_pages .= $p . SUBPAGE_SEPARATOR;
180 $backlink = HTML::a(array('href' => WikiURL($pagename,
181 array('action' => _("BackLinks"))),
182 'class' => 'backlinks'),
183 $WikiTheme->maybeSplitWikiWord($last_page));
184 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
185 $pageheader->pushContent($backlink);
187 $pageheader = HTML::a(array('href' => WikiURL($pagename,
188 array('action' => _("BackLinks"))),
189 'class' => 'backlinks'),
190 $WikiTheme->maybeSplitWikiWord($pagename));
191 $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
192 if ($request->getArg('frame'))
193 $pageheader->setAttr('target', '_top');
196 $pagetitle = SplitPagename($pagename);
197 if (($redirect_from = $request->getArg('redirectfrom'))) {
198 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
199 fmt("(Redirected from %s)",
200 RedirectorLink($redirect_from)));
201 // abuse the $redirected template var for some status update notice
202 } elseif ($request->getArg('errormsg')) {
203 $redirect_message = $request->getArg('errormsg');
204 $request->setArg('errormsg', false);
207 $request->appendValidators(array('pagerev' => $revision->getVersion(),
208 '%mtime' => $revision->get('mtime')));
210 // FIXME: This is also in the template...
211 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
212 // FIXME: enable MathML/SVG/... support
215 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
216 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
218 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
222 $toks['TITLE'] = $pagetitle; // <title> tag
223 $toks['HEADER'] = $pageheader; // h1 with backlink
224 $toks['revision'] = $revision;
226 // On external searchengine (google) referrer, highlight the searchterm and
227 // pass through the Searchhighlight actionpage.
228 if ($result = isExternalReferrer($request)) {
229 if (!empty($result['query'])) {
230 if (ENABLE_SEARCHHIGHLIGHT) {
231 $request->_searchhighlight = $result;
232 $request->appendValidators(array('%mtime' => time())); // force no cache(?)
233 // Should be changed to check the engine and search term only
234 // $request->setArg('nocache', 1);
235 $page_content = new TransformedText($revision->getPage(),
236 $revision->getPackedContent(),
237 $revision->getMetaData());
238 /* Now add the SearchHighlight plugin to the top of the page, in memory only.
239 You can parametrize this by changing the SearchHighlight action page.
241 if ($actionpage = $request->findActionPage('SearchHighlight')) {
242 $actionpage = $request->getPage($actionpage);
243 $actionrev = $actionpage->getCurrentRevision();
244 $pagetitle = HTML(fmt("%s: %s",
245 $actionpage->getName(),
246 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
247 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
248 '%mtime' => $actionrev->get('mtime')));
249 $toks['SEARCH_ENGINE'] = $result['engine'];
250 $toks['SEARCH_ENGINE_URL'] = $result['engine_url'];
251 $toks['SEARCH_TERM'] = $result['query'];
252 //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink
253 $actioncontent = new TransformedText($actionrev->getPage(),
254 $actionrev->getPackedContent(),
255 $actionrev->getMetaData());
256 // prepend the actionpage in front of the hightlighted content
257 $toks['CONTENT'] = HTML($actioncontent, $page_content);
261 $page_content = $revision->getTransformedContent();
264 $page_content = $revision->getTransformedContent();
267 /* Check for special pagenames, which are no actionpages. */
269 if ( $pagename == _("RecentVisitors")) {
270 $toks['ROBOTS_META']="noindex,follow";
273 if ($pagename == _("SandBox")) {
274 $toks['ROBOTS_META']="noindex,nofollow";
275 } else if (!isset($toks['ROBOTS_META'])) {
276 $toks['ROBOTS_META'] = "index,follow";
278 if (!isset($toks['CONTENT']))
279 $toks['CONTENT'] = new Template('browse', $request, $page_content);
280 if (!empty($redirect_message))
281 $toks['redirected'] = $redirect_message;
283 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
284 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
286 $template = new Template('html', $request);
288 // Handle other formats: So far we had html only.
289 // xml is requested by loaddump, rss is handled by RecentChanges,
290 // pdf is a special action, but should be a format to dump multiple pages
291 // if the actionpage plugin returns a pagelist.
292 // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb.
293 $format = $request->getArg('format');
294 /* Only single page versions. rss only if not already handled by RecentChanges.
296 if (!$format or $format == 'html' or $format == 'sidebar') {
297 $template->printExpansion($toks);
298 } elseif ($format == 'xml') {
299 $template = new Template('htmldump', $request);
300 $template->printExpansion($toks);
302 // No pagelist here. Single page version only
303 include_once("lib/PageList.php");
304 $pagelist = new PageList();
305 $pagelist->addPage($page);
306 if ($format == 'pdf') {
307 include_once("lib/pdf.php");
308 ConvertAndDisplayPdfPageList($request, $pagelist);
309 } elseif (in_array($format, array("rss91","rss2","rss"))) {
310 if ($pagename == _("RecentChanges"))
311 $template->printExpansion($toks);
313 include_once("lib/plugin/RecentChanges.php");
314 $plugin = new WikiPlugin_RecentChanges();
315 $args = $request->getargs();
316 return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
318 /*} elseif ($format == 'atom') {
319 include_once("lib/RssWriter.php");
320 $rdf = new AtomWriter($request, $pagelist);
322 } elseif ($format == 'rdf') { // all semantic relations and attributes
323 include_once("lib/SemanticWeb.php");
324 $rdf = new RdfWriter($request, $pagelist);
326 } elseif ($format == 'owl') {
327 include_once("lib/SemanticWeb.php");
328 $rdf = new OwlWriter($request, $pagelist);
330 } elseif ($format == 'kbmodel') {
331 include_once("lib/SemanticWeb.php");
332 $model = new ModelWriter($request, $pagelist);
335 trigger_error(sprintf("Unhandled format %s. Reverting to html", $format), E_USER_WARNING);
336 $template->printExpansion($toks);
340 $page->increaseHitCount();
342 if ($request->getArg('action') != 'pdf')
343 $request->checkValidators();
347 // $Log: not supported by cvs2svn $
348 // Revision 1.70 2007/01/22 23:43:06 rurban
349 // Add RecentChanges format=sidebar
351 // Revision 1.69 2007/01/20 15:53:51 rurban
352 // Rewrite of SearchHighlight: through ActionPage and InlineParser
354 // Revision 1.68 2007/01/20 11:25:19 rurban
355 // actionPage: request is already global
357 // Revision 1.67 2007/01/07 18:44:20 rurban
358 // Support format handlers for single- and multi-page: pagelists from actionpage plugins. Use USE_SEARCHHIGHLIGHT. Fix InlineHighlight (still experimental).
360 // Revision 1.66 2006/03/19 14:26:29 rurban
361 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
363 // Revision 1.65 2005/05/05 08:54:40 rurban
364 // fix pagename split for title and header
366 // Revision 1.64 2005/04/23 11:21:55 rurban
367 // honor theme-specific SplitWikiWord in the HEADER
369 // Revision 1.63 2004/11/30 17:48:38 rurban
372 // Revision 1.62 2004/11/30 09:51:35 rurban
373 // changed KEYWORDS from pageprefix to search term. added installer detection.
375 // Revision 1.61 2004/11/21 11:59:19 rurban
376 // remove final \n to be ob_cache independent
378 // Revision 1.60 2004/11/19 19:22:03 rurban
379 // ModeratePage part1: change status
381 // Revision 1.59 2004/11/17 20:03:58 rurban
382 // Typo: call SearchHighlight not SearchHighLight
384 // Revision 1.58 2004/11/09 17:11:16 rurban
385 // * revert to the wikidb ref passing. there's no memory abuse there.
386 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
387 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
388 // are also needed at the rendering for linkExistingWikiWord().
389 // pass options to pageiterator.
390 // use this cache also for _get_pageid()
391 // This saves about 8 SELECT count per page (num all pagelinks).
392 // * fix passing of all page fields to the pageiterator.
393 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
395 // Revision 1.57 2004/11/01 10:43:57 rurban
396 // seperate PassUser methods into seperate dir (memory usage)
397 // fix WikiUser (old) overlarge data session
398 // remove wikidb arg from various page class methods, use global ->_dbi instead
401 // Revision 1.56 2004/10/14 13:44:14 rurban
402 // fix lib/display.php:159: Warning[2]: Argument to array_reverse() should be an array
404 // Revision 1.55 2004/09/26 14:58:35 rurban
405 // naive SearchHighLight implementation
407 // Revision 1.54 2004/09/17 14:19:41 rurban
408 // disable Content-Type header for now, until it is fixed
410 // Revision 1.53 2004/06/25 14:29:20 rurban
411 // WikiGroup refactoring:
412 // global group attached to user, code for not_current user.
413 // improved helpers for special groups (avoid double invocations)
414 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
415 // fixed a XHTML validation error on userprefs.tmpl
417 // Revision 1.52 2004/06/14 11:31:37 rurban
418 // renamed global $Theme to $WikiTheme (gforge nameclash)
419 // inherit PageList default options from PageList
420 // default sortby=pagename
421 // use options in PageList_Selectable (limit, sortby, ...)
422 // added action revert, with button at action=diff
423 // added option regex to WikiAdminSearchReplace
425 // Revision 1.51 2004/05/18 16:23:39 rurban
426 // rename split_pagename to SplitPagename
428 // Revision 1.50 2004/05/04 22:34:25 rurban
431 // Revision 1.49 2004/04/18 01:11:52 rurban
432 // more numeric pagename fixes.
433 // fixed action=upload with merge conflict warnings.
434 // charset changed from constant to global (dynamic utf-8 switching)
442 // c-hanging-comment-ender-p: nil
443 // indent-tabs-mode: nil