2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.51 2004-05-18 16:23:39 rurban Exp $');
5 require_once('lib/Template.php');
8 * Extract keywords from Category* links on page.
10 function GleanKeywords ($page) {
11 global $KeywordLinkRegexp;
13 $links = $page->getLinks(false);
15 $keywords[] = SplitPagename($page->getName());
17 while ($link = $links->next())
18 if (preg_match("/${KeywordLinkRegexp}/x", $link->getName(), $m))
19 $keywords[] = SplitPagename($m[0]);
21 $keywords[] = WIKI_NAME;
23 return join(', ', $keywords);
26 /** Make a link back to redirecting page.
28 * @param $pagename string Name of redirecting page.
29 * @return XmlContent Link to the redirecting page.
31 function RedirectorLink($pagename) {
32 $url = WikiURL($pagename, array('redirectfrom' => ''));
33 return HTML::a(array('class' => 'redirectfrom wiki',
39 function actionPage(&$request, $action) {
42 $pagename = $request->getArg('pagename');
43 $version = $request->getArg('version');
45 $page = $request->getPage();
46 $revision = $page->getCurrentRevision();
48 $dbi = $request->getDbh();
49 $actionpage = $dbi->getPage($action);
50 $actionrev = $actionpage->getCurrentRevision();
52 // $splitname = SplitPagename($pagename);
54 $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
55 $Theme->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();
66 $template = Template('browse', array('CONTENT' => $transformedContent));
68 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
69 GeneratePage($template, $pagetitle, $revision);
70 $request->checkValidators();
74 function displayPage(&$request, $template=false) {
75 $pagename = $request->getArg('pagename');
76 $version = $request->getArg('version');
77 $page = $request->getPage();
79 $revision = $page->getRevision($version);
81 NoSuchRevision($request, $page, $version);
84 $revision = $page->getCurrentRevision();
87 $splitname = SplitPagename($pagename);
88 if (isSubPage($pagename)) {
89 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
90 $last_page = array_pop($pages); // deletes last element from array as side-effect
91 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
92 'class' => 'pagetitle'
94 SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
95 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
97 foreach ($pages as $p) {
98 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
99 'class' => 'backlinks'),
100 SplitPagename($p . SUBPAGE_SEPARATOR)));
101 $first_pages .= $p . SUBPAGE_SEPARATOR;
103 $backlink = HTML::a(array('href' => WikiURL($pagename,
104 array('action' => _("BackLinks"))),
105 'class' => 'backlinks'),
106 SplitPagename($last_page));
107 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
108 $pagetitle->pushContent($backlink);
110 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
111 array('action' => _("BackLinks"))),
112 'class' => 'backlinks'),
114 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
115 if ($request->getArg('frame'))
116 $pagetitle->setAttr('target', '_top');
119 $pageheader = $pagetitle;
120 if (($redirect_from = $request->getArg('redirectfrom'))) {
121 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
122 fmt("(Redirected from %s)",
123 RedirectorLink($redirect_from)));
126 $request->appendValidators(array('pagerev' => $revision->getVersion(),
127 '%mtime' => $revision->get('mtime')));
129 // FIXME: should probably be in a template...
130 if ($request->getArg('action') != 'pdf')
131 header("Content-Type: text/html; charset=" . $GLOBALS['charset']); // FIXME: this gets done twice?
133 $page_content = $revision->getTransformedContent();
135 $toks['CONTENT'] = new Template('browse', $request, $page_content);
137 $toks['TITLE'] = $pagetitle;
138 $toks['HEADER'] = $pageheader;
139 $toks['revision'] = $revision;
140 if (!empty($redirect_message))
141 $toks['redirected'] = $redirect_message;
142 $toks['ROBOTS_META'] = 'index,follow';
143 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
144 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
147 $template = new Template('html', $request);
149 $template->printExpansion($toks);
150 $page->increaseHitCount();
152 if ($request->getArg('action') != 'pdf')
153 $request->checkValidators();
156 // $Log: not supported by cvs2svn $
157 // Revision 1.50 2004/05/04 22:34:25 rurban
160 // Revision 1.49 2004/04/18 01:11:52 rurban
161 // more numeric pagename fixes.
162 // fixed action=upload with merge conflict warnings.
163 // charset changed from constant to global (dynamic utf-8 switching)
171 // c-hanging-comment-ender-p: nil
172 // indent-tabs-mode: nil