2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.54 2004-09-17 14:19:41 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",
55 $actionpage->getName(),
56 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
58 $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
59 '%mtime' => $revision->get('mtime')));
61 $request->appendValidators(array('pagerev' => $revision->getVersion(),
62 '%mtime' => $revision->get('mtime')));
63 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
64 '%mtime' => $actionrev->get('mtime')));
66 $transformedContent = $actionrev->getTransformedContent();
67 $template = Template('browse', array('CONTENT' => $transformedContent));
69 if (!headers_sent()) {
70 //FIXME: does not work yet. document.write not supported (signout button)
71 // http://www.w3.org/People/mimasa/test/xhtml/media-types/results
73 and (!isBrowserIE() and
74 strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
75 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
77 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
80 GeneratePage($template, $pagetitle, $revision);
81 $request->checkValidators();
85 function displayPage(&$request, $template=false) {
86 $pagename = $request->getArg('pagename');
87 $version = $request->getArg('version');
88 $page = $request->getPage();
90 $revision = $page->getRevision($version);
92 NoSuchRevision($request, $page, $version);
95 $revision = $page->getCurrentRevision();
98 $splitname = SplitPagename($pagename);
99 if (isSubPage($pagename)) {
100 $pages = explode(SUBPAGE_SEPARATOR,$pagename);
101 $last_page = array_pop($pages); // deletes last element from array as side-effect
102 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
103 'class' => 'pagetitle'
105 SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
106 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
108 foreach ($pages as $p) {
109 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
110 'class' => 'backlinks'),
111 SplitPagename($p . SUBPAGE_SEPARATOR)));
112 $first_pages .= $p . SUBPAGE_SEPARATOR;
114 $backlink = HTML::a(array('href' => WikiURL($pagename,
115 array('action' => _("BackLinks"))),
116 'class' => 'backlinks'),
117 SplitPagename($last_page));
118 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
119 $pagetitle->pushContent($backlink);
121 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
122 array('action' => _("BackLinks"))),
123 'class' => 'backlinks'),
125 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
126 if ($request->getArg('frame'))
127 $pagetitle->setAttr('target', '_top');
130 $pageheader = $pagetitle;
131 if (($redirect_from = $request->getArg('redirectfrom'))) {
132 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
133 fmt("(Redirected from %s)",
134 RedirectorLink($redirect_from)));
137 $request->appendValidators(array('pagerev' => $revision->getVersion(),
138 '%mtime' => $revision->get('mtime')));
140 // FIXME: This is also in the template...
141 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
142 // FIXME: enable MathML/SVG/... support
145 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
146 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
148 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
151 $page_content = $revision->getTransformedContent();
153 $toks['CONTENT'] = new Template('browse', $request, $page_content);
155 $toks['TITLE'] = $pagetitle;
156 $toks['HEADER'] = $pageheader;
157 $toks['revision'] = $revision;
158 if (!empty($redirect_message))
159 $toks['redirected'] = $redirect_message;
160 $toks['ROBOTS_META'] = 'index,follow';
161 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
162 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
165 $template = new Template('html', $request);
167 $template->printExpansion($toks);
168 $page->increaseHitCount();
170 if ($request->getArg('action') != 'pdf')
171 $request->checkValidators();
175 // $Log: not supported by cvs2svn $
176 // Revision 1.53 2004/06/25 14:29:20 rurban
177 // WikiGroup refactoring:
178 // global group attached to user, code for not_current user.
179 // improved helpers for special groups (avoid double invocations)
180 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
181 // fixed a XHTML validation error on userprefs.tmpl
183 // Revision 1.52 2004/06/14 11:31:37 rurban
184 // renamed global $Theme to $WikiTheme (gforge nameclash)
185 // inherit PageList default options from PageList
186 // default sortby=pagename
187 // use options in PageList_Selectable (limit, sortby, ...)
188 // added action revert, with button at action=diff
189 // added option regex to WikiAdminSearchReplace
191 // Revision 1.51 2004/05/18 16:23:39 rurban
192 // rename split_pagename to SplitPagename
194 // Revision 1.50 2004/05/04 22:34:25 rurban
197 // Revision 1.49 2004/04/18 01:11:52 rurban
198 // more numeric pagename fixes.
199 // fixed action=upload with merge conflict warnings.
200 // charset changed from constant to global (dynamic utf-8 switching)
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil