2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.31 2002-08-17 15:52:51 rurban Exp $');
5 require_once('lib/Template.php');
6 require_once('lib/BlockParser.php');
9 * Guess a short description of the page.
13 * This algorithm was suggested on MeatballWiki by
14 * Alex Schroeder <kensanata@yahoo.com>.
16 * Use the first paragraph in the page which contains at least two
19 * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
21 function GleanDescription ($rev) {
23 = pcre_fix_posix_classes("/[.?!]\s+[[:upper:])]"
25 . "[.?!]\s*([[:upper:])]|$)/sx");
27 $content = $rev->getPackedContent();
29 // Iterate through paragraphs.
30 while (preg_match('/(?: ^ \w .* $ \n? )+/mx', $content, $m)) {
33 // Return paragraph if it contains at least two sentences.
34 if (preg_match($two_sentences, $paragraph)) {
35 return preg_replace("/\s*\n\s*/", " ", trim($paragraph));
38 $content = substr(strstr($content, $paragraph), strlen($paragraph));
44 function actionPage(&$request, $action) {
47 $pagename = $request->getArg('pagename');
48 $version = $request->getArg('version');
50 $page = $request->getPage();
51 $revision = $page->getCurrentRevision();
53 $dbi = $request->getDbh();
54 $actionpage = $dbi->getPage($action);
55 $actionrev = $actionpage->getCurrentRevision();
57 $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
58 $Theme->linkExistingWikiWord($pagename, false, $version)));
60 require_once('lib/PageType.php');
61 $transformedContent = PageType($actionrev);
62 $template = Template('browse', array('CONTENT' => $transformedContent));
64 header("Content-Type: text/html; charset=" . CHARSET);
65 header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
67 GeneratePage($template, $pagetitle, $revision);
71 function displayPage(&$request, $tmpl = 'browse') {
72 $pagename = $request->getArg('pagename');
73 $version = $request->getArg('version');
74 $page = $request->getPage();
76 $revision = $page->getRevision($version);
78 NoSuchRevision($request, $page, $version);
81 $revision = $page->getCurrentRevision();
84 $splitname = split_pagename($pagename);
85 if (strchr($pagename, '/')) {
86 $pages = explode('/',$pagename);
87 $last_page = array_pop($pages); // deletes last element from array as side-effect
88 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
89 //'class' => 'backlinks'
91 split_pagename($pages[0] . '/')));
92 $first_pages = $pages[0] . '/';
94 foreach ($pages as $p) {
95 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
96 'class' => 'backlinks'),
97 split_pagename($p . '/')));
98 $first_pages .= $p . '/';
100 $backlink = HTML::a(array('href' => WikiURL($pagename,
101 array('action' => _("BackLinks"))),
102 'class' => 'backlinks'),
103 split_pagename($last_page));
104 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
105 $pagetitle->pushContent($backlink);
107 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
108 array('action' => _("BackLinks"))),
109 'class' => 'backlinks'),
111 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
114 include_once('lib/BlockParser.php');
116 require_once('lib/PageType.php');
117 $transformedContent = PageType($revision);
118 $template = Template('browse', array('CONTENT' => $transformedContent));
120 header("Content-Type: text/html; charset=" . CHARSET);
121 // don't clobber date header given by RC
122 if ( ! ($pagename == _("RecentChanges") || $pagename == _("RecentEdits")) )
123 header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
125 GeneratePage($template, $pagetitle, $revision,
126 array('ROBOTS_META' => 'index,follow',
127 'PAGE_DESCRIPTION' => GleanDescription($revision)));
130 $page->increaseHitCount();
138 // c-hanging-comment-ender-p: nil
139 // indent-tabs-mode: nil