2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.41 2003-02-16 20:04:47 dairiki 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 /** Make a link back to redirecting page.
46 * @param $pagename string Name of redirecting page.
47 * @return XmlContent Link to the redirecting page.
49 function RedirectorLink($pagename) {
50 $url = WikiURL($pagename, array('redirectfrom' => ''));
51 return HTML::a(array('class' => 'redirectfrom wiki',
57 function actionPage(&$request, $action) {
60 $pagename = $request->getArg('pagename');
61 $version = $request->getArg('version');
63 $page = $request->getPage();
64 $revision = $page->getCurrentRevision();
66 $dbi = $request->getDbh();
67 $actionpage = $dbi->getPage($action);
68 $actionrev = $actionpage->getCurrentRevision();
70 // $splitname = split_pagename($pagename);
72 $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
73 $Theme->linkExistingWikiWord($pagename, false, $version)));
75 $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
76 '%mtime' => $revision->get('mtime')));
78 $request->appendValidators(array('pagerev' => $revision->getVersion(),
79 '%mtime' => $revision->get('mtime')));
80 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
81 '%mtime' => $actionrev->get('mtime')));
83 require_once('lib/PageType.php');
84 $transformedContent = PageType($actionrev);
85 $template = Template('browse', array('CONTENT' => $transformedContent));
87 header("Content-Type: text/html; charset=" . CHARSET);
88 $request->checkValidators();
90 // $template = Template('browse', array('CONTENT' => TransformText($actionrev)));
92 GeneratePage($template, $pagetitle, $revision);
96 function displayPage(&$request, $tmpl = 'browse') {
97 $pagename = $request->getArg('pagename');
98 $version = $request->getArg('version');
99 $page = $request->getPage();
101 $revision = $page->getRevision($version);
103 NoSuchRevision($request, $page, $version);
106 $revision = $page->getCurrentRevision();
109 $splitname = split_pagename($pagename);
110 if (isSubPage($pagename)) {
111 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
112 $last_page = array_pop($pages); // deletes last element from array as side-effect
113 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
114 'class' => 'pagetitle'
116 split_pagename($pages[0] . SUBPAGE_SEPARATOR)));
117 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
119 foreach ($pages as $p) {
120 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
121 'class' => 'backlinks'),
122 split_pagename($p . SUBPAGE_SEPARATOR)));
123 $first_pages .= $p . SUBPAGE_SEPARATOR;
125 $backlink = HTML::a(array('href' => WikiURL($pagename,
126 array('action' => _("BackLinks"))),
127 'class' => 'backlinks'),
128 split_pagename($last_page));
129 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
130 $pagetitle->pushContent($backlink);
132 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
133 array('action' => _("BackLinks"))),
134 'class' => 'backlinks'),
136 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
139 $redirect_from = $request->getArg('redirectfrom');
140 if ($redirect_from) {
141 $redirect_from = fmt("Redirected from %s", RedirectorLink($redirect_from));
144 //include_once('lib/BlockParser.php');
146 $request->appendValidators(array('pagerev' => $revision->getVersion(),
147 '%mtime' => $revision->get('mtime')));
149 require_once('lib/PageType.php');
150 if ($frame = $request->getArg('frame')) {
151 if (in_array($frame, array('body','browse','editpage')))
152 $template = Template($frame, array('CONTENT' => PageType($revision)));
153 elseif ($frame == 'top')
154 $template = Template($frame, array('framesrc' => $request->getArg('framesrc')));
156 $template = Template($frame);
158 $transformedContent = PageType($revision);
159 $template = Template('browse', array('CONTENT' => $transformedContent));
162 header("Content-Type: text/html; charset=" . CHARSET); // FIXME: this gets done twice?
163 $request->checkValidators();
165 GeneratePage($template, $pagetitle, $revision,
166 array('ROBOTS_META' => 'index,follow',
167 'PAGE_DESCRIPTION' => GleanDescription($revision),
168 'REDIRECT_FROM' => $redirect_from));
171 $page->increaseHitCount();
179 // c-hanging-comment-ender-p: nil
180 // indent-tabs-mode: nil