2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.73 2007-05-30 20:43:31 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 ($pagename == _("LinkDatabase")) {
83 $template = Template('browse', array('CONTENT' => $transformedContent));
84 GeneratePage($template, $pagetitle, $revision, $args);
85 } elseif (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') {
86 $template = Template('browse', array('CONTENT' => $transformedContent));
87 GeneratePage($template, $pagetitle, $revision, $args);
88 } elseif ($format == 'xml') {
89 $template = Template('browse', array('CONTENT' => $transformedContent));
90 GeneratePageAsXML($template, $pagetitle, $revision, $args);
93 include_once('lib/WikiPlugin.php');
94 // Then the multi-page formats
95 // rss (if not already handled by RecentChanges)
96 // Need the pagelist from the first plugin
97 foreach($transformedContent->_content as $cached_element) {
98 if (is_a($cached_element, "Cached_PluginInvocation")) {
99 $loader = new WikiPluginLoader;
101 // return the first found pagelist
102 $pagelist = $loader->expandPI($cached_element->_pi, $request, $markup, $pagename);
103 if (is_a($pagelist, 'PageList'))
107 if (!$pagelist or !is_a($pagelist, 'PageList')) {
108 if (!in_array($format, array("rss91","rss2","rss","atom","rdf")))
109 trigger_error(sprintf("Format %s requires an actionpage returning a pagelist.", $format)
110 ."\n".("Fall back to single page mode"), E_USER_WARNING);
111 $pagelist = new PageList();
112 $pagelist->addPage($page);
114 if ($format == 'pdf') {
115 include_once("lib/pdf.php");
116 ConvertAndDisplayPdfPageList($request, $pagelist);
117 } elseif (in_array($format, array("rss91","rss2","rss"))) {
118 if ($pagename == _("RecentChanges")) {
119 $template->printExpansion($toks);
121 include_once("lib/plugin/RecentChanges.php");
122 $plugin = new WikiPlugin_RecentChanges();
123 $args = $request->getargs();
124 return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
126 } elseif ($format == 'atom') {
127 include_once("lib/RssWriter.php");
128 $rdf = new AtomFeed($request, $pagelist);
130 } elseif ($format == 'rdf') { // all semantic relations and attributes
131 include_once("lib/SemanticWeb.php");
132 $rdf = new RdfWriter($request, $pagelist);
134 } elseif ($format == 'owl') {
135 include_once("lib/SemanticWeb.php");
136 $rdf = new OwlWriter($request, $pagelist);
138 } elseif ($format == 'kbmodel') {
139 include_once("lib/SemanticWeb.php");
140 $model = new ModelWriter($request, $pagelist);
143 $template = Template('browse', array('CONTENT' => $transformedContent));
144 GeneratePage($template, $pagetitle, $revision, $args);
147 $request->checkValidators();
151 function displayPage(&$request, $template=false) {
153 $pagename = $request->getArg('pagename');
154 $version = $request->getArg('version');
155 $page = $request->getPage();
157 $revision = $page->getRevision($version);
159 NoSuchRevision($request, $page, $version);
160 /* Tell Google (and others) to ignore old versions of pages */
161 $toks['ROBOTS_META'] = "noindex,nofollow";
164 $revision = $page->getCurrentRevision();
167 if (isSubPage($pagename)) {
168 $pages = explode(SUBPAGE_SEPARATOR, $pagename);
169 $last_page = array_pop($pages); // deletes last element from array as side-effect
170 $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
171 'class' => 'pagetitle'
173 $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
174 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
176 foreach ($pages as $p) {
177 $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
178 'class' => 'backlinks'),
179 $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
180 $first_pages .= $p . SUBPAGE_SEPARATOR;
182 $backlink = HTML::a(array('href' => WikiURL($pagename,
183 array('action' => _("BackLinks"))),
184 'class' => 'backlinks'),
185 $WikiTheme->maybeSplitWikiWord($last_page));
186 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
187 $pageheader->pushContent($backlink);
189 $pageheader = HTML::a(array('href' => WikiURL($pagename,
190 array('action' => _("BackLinks"))),
191 'class' => 'backlinks'),
192 $WikiTheme->maybeSplitWikiWord($pagename));
193 $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
194 if ($request->getArg('frame'))
195 $pageheader->setAttr('target', '_top');
198 $pagetitle = SplitPagename($pagename);
199 if (($redirect_from = $request->getArg('redirectfrom'))) {
200 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
201 fmt("(Redirected from %s)",
202 RedirectorLink($redirect_from)));
203 // abuse the $redirected template var for some status update notice
204 } elseif ($request->getArg('errormsg')) {
205 $redirect_message = $request->getArg('errormsg');
206 $request->setArg('errormsg', false);
209 $request->appendValidators(array('pagerev' => $revision->getVersion(),
210 '%mtime' => $revision->get('mtime')));
212 // FIXME: This is also in the template...
213 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
214 // FIXME: enable MathML/SVG/... support
217 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
218 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
220 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
224 $toks['TITLE'] = $pagetitle; // <title> tag
225 $toks['HEADER'] = $pageheader; // h1 with backlink
226 $toks['revision'] = $revision;
228 // On external searchengine (google) referrer, highlight the searchterm and
229 // pass through the Searchhighlight actionpage.
230 if ($result = isExternalReferrer($request)) {
231 if (!empty($result['query'])) {
232 if (ENABLE_SEARCHHIGHLIGHT) {
233 $request->_searchhighlight = $result;
234 $request->appendValidators(array('%mtime' => time())); // force no cache(?)
235 // Should be changed to check the engine and search term only
236 // $request->setArg('nocache', 1);
237 $page_content = new TransformedText($revision->getPage(),
238 $revision->getPackedContent(),
239 $revision->getMetaData());
240 /* Now add the SearchHighlight plugin to the top of the page, in memory only.
241 You can parametrize this by changing the SearchHighlight action page.
243 if ($actionpage = $request->findActionPage('SearchHighlight')) {
244 $actionpage = $request->getPage($actionpage);
245 $actionrev = $actionpage->getCurrentRevision();
246 $pagetitle = HTML(fmt("%s: %s",
247 $actionpage->getName(),
248 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
249 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
250 '%mtime' => $actionrev->get('mtime')));
251 $toks['SEARCH_ENGINE'] = $result['engine'];
252 $toks['SEARCH_ENGINE_URL'] = $result['engine_url'];
253 $toks['SEARCH_TERM'] = $result['query'];
254 //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink
255 $actioncontent = new TransformedText($actionrev->getPage(),
256 $actionrev->getPackedContent(),
257 $actionrev->getMetaData());
258 // prepend the actionpage in front of the hightlighted content
259 $toks['CONTENT'] = HTML($actioncontent, $page_content);
263 $page_content = $revision->getTransformedContent();
266 $page_content = $revision->getTransformedContent();
269 /* Check for special pagenames, which are no actionpages. */
271 if ( $pagename == _("RecentVisitors")) {
272 $toks['ROBOTS_META']="noindex,follow";
275 if ($pagename == _("SandBox")) {
276 $toks['ROBOTS_META']="noindex,nofollow";
277 } else if (!isset($toks['ROBOTS_META'])) {
278 $toks['ROBOTS_META'] = "index,follow";
280 if (!isset($toks['CONTENT']))
281 $toks['CONTENT'] = new Template('browse', $request, $page_content);
282 if (!empty($redirect_message))
283 $toks['redirected'] = $redirect_message;
285 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
286 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
288 $template = new Template('html', $request);
290 // Handle other formats: So far we had html only.
291 // xml is requested by loaddump, rss is handled by RecentChanges,
292 // pdf is a special action, but should be a format to dump multiple pages
293 // if the actionpage plugin returns a pagelist.
294 // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb.
295 $format = $request->getArg('format');
296 /* Only single page versions. rss only if not already handled by RecentChanges.
298 if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') {
299 $template->printExpansion($toks);
300 } elseif ($format == 'xml') {
301 $template = new Template('htmldump', $request);
302 $template->printExpansion($toks);
304 // No pagelist here. Single page version only
305 include_once("lib/PageList.php");
306 $pagelist = new PageList();
307 $pagelist->addPage($page);
308 if ($format == 'pdf') {
309 include_once("lib/pdf.php");
310 ConvertAndDisplayPdfPageList($request, $pagelist);
311 } elseif (in_array($format, array("rss91","rss2","rss"))) {
312 if ($pagename == _("RecentChanges"))
313 $template->printExpansion($toks);
315 include_once("lib/plugin/RecentChanges.php");
316 $plugin = new WikiPlugin_RecentChanges();
317 $args = $request->getargs();
318 return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
320 /*} elseif ($format == 'atom') {
321 include_once("lib/RssWriter.php");
322 $rdf = new AtomWriter($request, $pagelist);
324 } elseif ($format == 'rdf') { // all semantic relations and attributes
325 include_once("lib/SemanticWeb.php");
326 $rdf = new RdfWriter($request, $pagelist);
328 } elseif ($format == 'owl') {
329 include_once("lib/SemanticWeb.php");
330 $rdf = new OwlWriter($request, $pagelist);
332 } elseif ($format == 'kbmodel') {
333 include_once("lib/SemanticWeb.php");
334 $model = new ModelWriter($request, $pagelist);
337 if (!in_array($pagename, array(_("LinkDatabase"))))
338 trigger_error(sprintf("Unhandled format %s. Reverting to html", $format), E_USER_WARNING);
339 $template->printExpansion($toks);
343 $page->increaseHitCount();
345 if ($request->getArg('action') != 'pdf')
346 $request->checkValidators();
350 // $Log: not supported by cvs2svn $
351 // Revision 1.72 2007/05/13 18:13:12 rurban
352 // LinkDatabase format exceptions
354 // Revision 1.71 2007/02/17 22:39:05 rurban
355 // format=rss overhaul
357 // Revision 1.70 2007/01/22 23:43:06 rurban
358 // Add RecentChanges format=sidebar
360 // Revision 1.69 2007/01/20 15:53:51 rurban
361 // Rewrite of SearchHighlight: through ActionPage and InlineParser
363 // Revision 1.68 2007/01/20 11:25:19 rurban
364 // actionPage: request is already global
366 // Revision 1.67 2007/01/07 18:44:20 rurban
367 // Support format handlers for single- and multi-page: pagelists from actionpage plugins. Use USE_SEARCHHIGHLIGHT. Fix InlineHighlight (still experimental).
369 // Revision 1.66 2006/03/19 14:26:29 rurban
370 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
372 // Revision 1.65 2005/05/05 08:54:40 rurban
373 // fix pagename split for title and header
375 // Revision 1.64 2005/04/23 11:21:55 rurban
376 // honor theme-specific SplitWikiWord in the HEADER
378 // Revision 1.63 2004/11/30 17:48:38 rurban
381 // Revision 1.62 2004/11/30 09:51:35 rurban
382 // changed KEYWORDS from pageprefix to search term. added installer detection.
384 // Revision 1.61 2004/11/21 11:59:19 rurban
385 // remove final \n to be ob_cache independent
387 // Revision 1.60 2004/11/19 19:22:03 rurban
388 // ModeratePage part1: change status
390 // Revision 1.59 2004/11/17 20:03:58 rurban
391 // Typo: call SearchHighlight not SearchHighLight
393 // Revision 1.58 2004/11/09 17:11:16 rurban
394 // * revert to the wikidb ref passing. there's no memory abuse there.
395 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
396 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
397 // are also needed at the rendering for linkExistingWikiWord().
398 // pass options to pageiterator.
399 // use this cache also for _get_pageid()
400 // This saves about 8 SELECT count per page (num all pagelinks).
401 // * fix passing of all page fields to the pageiterator.
402 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
404 // Revision 1.57 2004/11/01 10:43:57 rurban
405 // seperate PassUser methods into seperate dir (memory usage)
406 // fix WikiUser (old) overlarge data session
407 // remove wikidb arg from various page class methods, use global ->_dbi instead
410 // Revision 1.56 2004/10/14 13:44:14 rurban
411 // fix lib/display.php:159: Warning[2]: Argument to array_reverse() should be an array
413 // Revision 1.55 2004/09/26 14:58:35 rurban
414 // naive SearchHighLight implementation
416 // Revision 1.54 2004/09/17 14:19:41 rurban
417 // disable Content-Type header for now, until it is fixed
419 // Revision 1.53 2004/06/25 14:29:20 rurban
420 // WikiGroup refactoring:
421 // global group attached to user, code for not_current user.
422 // improved helpers for special groups (avoid double invocations)
423 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
424 // fixed a XHTML validation error on userprefs.tmpl
426 // Revision 1.52 2004/06/14 11:31:37 rurban
427 // renamed global $Theme to $WikiTheme (gforge nameclash)
428 // inherit PageList default options from PageList
429 // default sortby=pagename
430 // use options in PageList_Selectable (limit, sortby, ...)
431 // added action revert, with button at action=diff
432 // added option regex to WikiAdminSearchReplace
434 // Revision 1.51 2004/05/18 16:23:39 rurban
435 // rename split_pagename to SplitPagename
437 // Revision 1.50 2004/05/04 22:34:25 rurban
440 // Revision 1.49 2004/04/18 01:11:52 rurban
441 // more numeric pagename fixes.
442 // fixed action=upload with merge conflict warnings.
443 // charset changed from constant to global (dynamic utf-8 switching)
451 // c-hanging-comment-ender-p: nil
452 // indent-tabs-mode: nil