2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.36 2002-08-27 21:51:31 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 = preg_replace("/(['\"])/", "\$1", $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 // $splitname = split_pagename($pagename);
59 $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
60 $Theme->linkExistingWikiWord($pagename, false, $version)));
62 require_once('lib/PageType.php');
63 $transformedContent = PageType($actionrev);
64 $template = Template('browse', array('CONTENT' => $transformedContent));
66 header("Content-Type: text/html; charset=" . CHARSET);
67 if (!defined('DEBUG')) {
68 header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
71 // $template = Template('browse', array('CONTENT' => TransformText($actionrev)));
73 GeneratePage($template, $pagetitle, $revision);
77 function displayPage(&$request, $tmpl = 'browse') {
78 $pagename = $request->getArg('pagename');
79 $version = $request->getArg('version');
80 $page = $request->getPage();
82 $revision = $page->getRevision($version);
84 NoSuchRevision($request, $page, $version);
87 $revision = $page->getCurrentRevision();
90 $splitname = split_pagename($pagename);
91 if (isSubPage($pagename)) {
92 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
93 $last_page = array_pop($pages); // deletes last element from array as side-effect
94 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
95 'class' => 'pagetitle'
97 split_pagename($pages[0] . SUBPAGE_SEPARATOR)));
98 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
100 foreach ($pages as $p) {
101 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
102 'class' => 'backlinks'),
103 split_pagename($p . SUBPAGE_SEPARATOR)));
104 $first_pages .= $p . SUBPAGE_SEPARATOR;
106 $backlink = HTML::a(array('href' => WikiURL($pagename,
107 array('action' => _("BackLinks"))),
108 'class' => 'backlinks'),
109 split_pagename($last_page));
110 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
111 $pagetitle->pushContent($backlink);
113 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
114 array('action' => _("BackLinks"))),
115 'class' => 'backlinks'),
117 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
120 //include_once('lib/BlockParser.php');
122 require_once('lib/PageType.php');
123 if ($frame = $request->getArg('frame')) {
124 if (in_array($frame,array('body','browse','editpage')))
125 $template = Template($frame, array('CONTENT' => PageType($revision)));
126 elseif ($frame == 'top')
127 $template = Template($frame, array('framesrc' => $request->getArg('framesrc')));
129 $template = Template($frame);
131 $transformedContent = PageType($revision);
132 $template = Template('browse', array('CONTENT' => $transformedContent));
135 header("Content-Type: text/html; charset=" . CHARSET);
136 // don't clobber date header given by RC
137 if ( ! ($pagename == _("RecentChanges") || $pagename == _("RecentEdits") || defined('DEBUG')) )
138 header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
140 GeneratePage($template, $pagetitle, $revision,
141 array('ROBOTS_META' => 'index,follow',
142 'PAGE_DESCRIPTION' => GleanDescription($revision)));
145 $page->increaseHitCount();
153 // c-hanging-comment-ender-p: nil
154 // indent-tabs-mode: nil