2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.76 2007-08-10 21:59:27 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 require_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()) {
21 if (preg_match($KeywordLinkRegexp, $link->getName(), $m))
22 $keywords[] = SplitPagename($m[0]);
24 $keywords[] = WIKI_NAME;
25 return join(', ', $keywords);
28 /** Make a link back to redirecting page.
30 * @param $pagename string Name of redirecting page.
31 * @return XmlContent Link to the redirecting page.
33 function RedirectorLink($pagename) {
34 $url = WikiURL($pagename, array('redirectfrom' => ''));
35 return HTML::a(array('class' => 'redirectfrom wiki',
41 function actionPage(&$request, $action) {
44 $pagename = $request->getArg('pagename');
45 $version = $request->getArg('version');
47 $page = $request->getPage();
48 $revision = $page->getCurrentRevision();
50 $dbi = $request->getDbh();
51 $actionpage = $dbi->getPage($action);
52 $actionrev = $actionpage->getCurrentRevision();
54 $pagetitle = HTML(fmt("%s: %s",
55 $actionpage->getName(),
56 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
58 $request->setValidators(array('pageversion' => $revision->getVersion(),
59 '%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 require_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 require_once('lib/PageList.php');
112 $pagelist = new PageList();
113 $pagelist->addPage($page);
115 if ($format == 'pdf') {
116 require_once("lib/pdf.php");
117 ConvertAndDisplayPdfPageList($request, $pagelist);
118 // time-sorted RDF รก la RecentChanges
119 } elseif (in_array($format, array("rss91","rss2","rss","atom"))) {
120 $args = $request->getArgs();
121 if ($pagename == _("RecentChanges")) {
122 $template->printExpansion($args);
124 require_once("lib/plugin/RecentChanges.php");
125 $plugin = new WikiPlugin_RecentChanges();
126 return $plugin->format($plugin->getChanges($request->_dbi, $args), $args);
128 } elseif ($format == 'rdf') { // all semantic relations and attributes
129 require_once("lib/SemanticWeb.php");
130 $rdf = new RdfWriter($request, $pagelist);
132 } elseif ($format == 'rdfs') {
133 require_once("lib/SemanticWeb.php");
134 $rdf = new RdfsWriter($request, $pagelist);
136 } elseif ($format == 'owl') { // or daml?
137 require_once("lib/SemanticWeb.php");
138 $rdf = new OwlWriter($request, $pagelist);
141 $template = Template('browse', array('CONTENT' => $transformedContent));
142 GeneratePage($template, $pagetitle, $revision, $args);
145 $request->checkValidators();
150 function displayPage(&$request, $template=false) {
152 $pagename = $request->getArg('pagename');
153 $version = $request->getArg('version');
154 $page = $request->getPage();
156 $revision = $page->getRevision($version);
158 NoSuchRevision($request, $page, $version);
159 /* Tell Google (and others) to ignore old versions of pages */
160 $toks['ROBOTS_META'] = "noindex,nofollow";
163 $revision = $page->getCurrentRevision();
166 if (isSubPage($pagename)) {
167 $pages = explode(SUBPAGE_SEPARATOR, $pagename);
168 $last_page = array_pop($pages); // deletes last element from array as side-effect
169 $pageheader = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
170 'class' => 'pagetitle'
172 $WikiTheme->maybeSplitWikiWord($pages[0] . SUBPAGE_SEPARATOR)));
173 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
175 foreach ($pages as $p) {
176 $pageheader->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
177 'class' => 'backlinks'),
178 $WikiTheme->maybeSplitWikiWord($p . SUBPAGE_SEPARATOR)));
179 $first_pages .= $p . SUBPAGE_SEPARATOR;
181 $backlink = HTML::a(array('href' => WikiURL($pagename,
182 array('action' => _("BackLinks"))),
183 'class' => 'backlinks'),
184 $WikiTheme->maybeSplitWikiWord($last_page));
185 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
186 $pageheader->pushContent($backlink);
188 $pageheader = HTML::a(array('href' => WikiURL($pagename,
189 array('action' => _("BackLinks"))),
190 'class' => 'backlinks'),
191 $WikiTheme->maybeSplitWikiWord($pagename));
192 $pageheader->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
193 if ($request->getArg('frame'))
194 $pageheader->setAttr('target', '_top');
197 $pagetitle = SplitPagename($pagename);
198 if (($redirect_from = $request->getArg('redirectfrom'))) {
199 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
200 fmt("(Redirected from %s)",
201 RedirectorLink($redirect_from)));
202 // abuse the $redirected template var for some status update notice
203 } elseif ($request->getArg('errormsg')) {
204 $redirect_message = $request->getArg('errormsg');
205 $request->setArg('errormsg', false);
208 $request->appendValidators(array('pagerev' => $revision->getVersion(),
209 '%mtime' => $revision->get('mtime')));
211 // FIXME: This is also in the template...
212 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
213 // FIXME: enable MathML/SVG/... support
216 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
217 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
219 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
223 $toks['TITLE'] = $pagetitle; // <title> tag
224 $toks['HEADER'] = $pageheader; // h1 with backlink
225 $toks['revision'] = $revision;
227 // On external searchengine (google) referrer, highlight the searchterm and
228 // pass through the Searchhighlight actionpage.
229 if ($result = isExternalReferrer($request)) {
230 if (!empty($result['query'])) {
231 if (ENABLE_SEARCHHIGHLIGHT) {
232 $request->_searchhighlight = $result;
233 $request->appendValidators(array('%mtime' => time())); // force no cache(?)
234 // Should be changed to check the engine and search term only
235 // $request->setArg('nocache', 1);
236 $page_content = new TransformedText($revision->getPage(),
237 $revision->getPackedContent(),
238 $revision->getMetaData());
239 /* Now add the SearchHighlight plugin to the top of the page, in memory only.
240 You can parametrize this by changing the SearchHighlight action page.
242 if ($actionpage = $request->findActionPage('SearchHighlight')) {
243 $actionpage = $request->getPage($actionpage);
244 $actionrev = $actionpage->getCurrentRevision();
245 $pagetitle = HTML(fmt("%s: %s",
246 $actionpage->getName(),
247 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
248 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
249 '%mtime' => $actionrev->get('mtime')));
250 $toks['SEARCH_ENGINE'] = $result['engine'];
251 $toks['SEARCH_ENGINE_URL'] = $result['engine_url'];
252 $toks['SEARCH_TERM'] = $result['query'];
253 //$toks['HEADER'] = HTML($actionpage->getName(),": ",$pageheader); // h1 with backlink
254 $actioncontent = new TransformedText($actionrev->getPage(),
255 $actionrev->getPackedContent(),
256 $actionrev->getMetaData());
257 // prepend the actionpage in front of the hightlighted content
258 $toks['CONTENT'] = HTML($actioncontent, $page_content);
262 $page_content = $revision->getTransformedContent();
265 $page_content = $revision->getTransformedContent();
268 /* Check for special pagenames, which are no actionpages. */
270 if ( $pagename == _("RecentVisitors")) {
271 $toks['ROBOTS_META']="noindex,follow";
274 if ($pagename == _("SandBox")) {
275 $toks['ROBOTS_META']="noindex,nofollow";
276 } else if (!isset($toks['ROBOTS_META'])) {
277 $toks['ROBOTS_META'] = "index,follow";
279 if (!isset($toks['CONTENT']))
280 $toks['CONTENT'] = new Template('browse', $request, $page_content);
281 if (!empty($redirect_message))
282 $toks['redirected'] = $redirect_message;
284 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
285 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
287 $template = new Template('html', $request);
289 // Handle other formats: So far we had html only.
290 // xml is requested by loaddump, rss is handled by RecentChanges,
291 // pdf is a special action, but should be a format to dump multiple pages
292 // if the actionpage plugin returns a pagelist.
293 // rdf, owl, kbmodel, daml, ... are handled by SemanticWeb.
294 $format = $request->getArg('format');
295 /* Only single page versions. rss only if not already handled by RecentChanges.
297 if (!$format or $format == 'html' or $format == 'sidebar' or $format == 'contribs') {
298 $template->printExpansion($toks);
299 } elseif ($format == 'xml') {
300 $template = new Template('htmldump', $request);
301 $template->printExpansion($toks);
303 // No pagelist here. Single page version only
304 require_once("lib/PageList.php");
305 $pagelist = new PageList();
306 $pagelist->addPage($page);
307 if ($format == 'pdf') {
308 require_once("lib/pdf.php");
309 ConvertAndDisplayPdfPageList($request, $pagelist);
310 // time-sorted rdf a la RecentChanges
311 } elseif (in_array($format, array("rss91","rss2","rss","atom"))) {
312 if ($pagename == _("RecentChanges"))
313 $template->printExpansion($toks);
315 require_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 == 'rdf') { // all semantic relations and attributes
321 require_once("lib/SemanticWeb.php");
322 $rdf = new RdfWriter($request, $pagelist);
324 } elseif ($format == 'owl') { // or daml?
325 require_once("lib/SemanticWeb.php");
326 $rdf = new OwlWriter($request, $pagelist);
329 if (!in_array($pagename, array(_("LinkDatabase"))))
330 trigger_error(sprintf("Unhandled format %s. Reverting to html", $format),
332 $template->printExpansion($toks);
336 $page->increaseHitCount();
338 if ($request->getArg('action') != 'pdf')
339 $request->checkValidators();
344 // $Log: not supported by cvs2svn $
345 // Revision 1.75 2007/07/01 09:17:45 rurban
346 // add ATOM support, a very questionable format
348 // Revision 1.74 2007/06/07 17:01:27 rurban
349 // actionPage has no toks: fix format=rss* on actionpages
351 // Revision 1.73 2007/05/30 20:43:31 rurban
352 // added MonoBook UserContribs
354 // Revision 1.72 2007/05/13 18:13:12 rurban
355 // LinkDatabase format exceptions
357 // Revision 1.71 2007/02/17 22:39:05 rurban
358 // format=rss overhaul
360 // Revision 1.70 2007/01/22 23:43:06 rurban
361 // Add RecentChanges format=sidebar
363 // Revision 1.69 2007/01/20 15:53:51 rurban
364 // Rewrite of SearchHighlight: through ActionPage and InlineParser
366 // Revision 1.68 2007/01/20 11:25:19 rurban
367 // actionPage: request is already global
369 // Revision 1.67 2007/01/07 18:44:20 rurban
370 // Support format handlers for single- and multi-page: pagelists from actionpage plugins. Use USE_SEARCHHIGHLIGHT. Fix InlineHighlight (still experimental).
372 // Revision 1.66 2006/03/19 14:26:29 rurban
373 // sf.net patch by Matt Brown: Add rel=nofollow to more actions
375 // Revision 1.65 2005/05/05 08:54:40 rurban
376 // fix pagename split for title and header
378 // Revision 1.64 2005/04/23 11:21:55 rurban
379 // honor theme-specific SplitWikiWord in the HEADER
381 // Revision 1.63 2004/11/30 17:48:38 rurban
384 // Revision 1.62 2004/11/30 09:51:35 rurban
385 // changed KEYWORDS from pageprefix to search term. added installer detection.
387 // Revision 1.61 2004/11/21 11:59:19 rurban
388 // remove final \n to be ob_cache independent
390 // Revision 1.60 2004/11/19 19:22:03 rurban
391 // ModeratePage part1: change status
393 // Revision 1.59 2004/11/17 20:03:58 rurban
394 // Typo: call SearchHighlight not SearchHighLight
396 // Revision 1.58 2004/11/09 17:11:16 rurban
397 // * revert to the wikidb ref passing. there's no memory abuse there.
398 // * use new wikidb->_cache->_id_cache[] instead of wikidb->_iwpcache, to effectively
399 // store page ids with getPageLinks (GleanDescription) of all existing pages, which
400 // are also needed at the rendering for linkExistingWikiWord().
401 // pass options to pageiterator.
402 // use this cache also for _get_pageid()
403 // This saves about 8 SELECT count per page (num all pagelinks).
404 // * fix passing of all page fields to the pageiterator.
405 // * fix overlarge session data which got broken with the latest ACCESS_LOG_SQL changes
407 // Revision 1.57 2004/11/01 10:43:57 rurban
408 // seperate PassUser methods into seperate dir (memory usage)
409 // fix WikiUser (old) overlarge data session
410 // remove wikidb arg from various page class methods, use global ->_dbi instead
413 // Revision 1.56 2004/10/14 13:44:14 rurban
414 // fix lib/display.php:159: Warning[2]: Argument to array_reverse() should be an array
416 // Revision 1.55 2004/09/26 14:58:35 rurban
417 // naive SearchHighLight implementation
419 // Revision 1.54 2004/09/17 14:19:41 rurban
420 // disable Content-Type header for now, until it is fixed
422 // Revision 1.53 2004/06/25 14:29:20 rurban
423 // WikiGroup refactoring:
424 // global group attached to user, code for not_current user.
425 // improved helpers for special groups (avoid double invocations)
426 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
427 // fixed a XHTML validation error on userprefs.tmpl
429 // Revision 1.52 2004/06/14 11:31:37 rurban
430 // renamed global $Theme to $WikiTheme (gforge nameclash)
431 // inherit PageList default options from PageList
432 // default sortby=pagename
433 // use options in PageList_Selectable (limit, sortby, ...)
434 // added action revert, with button at action=diff
435 // added option regex to WikiAdminSearchReplace
437 // Revision 1.51 2004/05/18 16:23:39 rurban
438 // rename split_pagename to SplitPagename
440 // Revision 1.50 2004/05/04 22:34:25 rurban
443 // Revision 1.49 2004/04/18 01:11:52 rurban
444 // more numeric pagename fixes.
445 // fixed action=upload with merge conflict warnings.
446 // charset changed from constant to global (dynamic utf-8 switching)
454 // c-hanging-comment-ender-p: nil
455 // indent-tabs-mode: nil