2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.58 2004-11-09 17:11:16 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->getPageLinks();
14 $keywords[] = SplitPagename($page->getName());
15 while ($link = $links->next()) {
16 if (preg_match("/${KeywordLinkRegexp}/x", $link->getName(), $m))
17 $keywords[] = SplitPagename($m[0]);
19 $keywords[] = WIKI_NAME;
20 return join(', ', $keywords);
23 /** Make a link back to redirecting page.
25 * @param $pagename string Name of redirecting page.
26 * @return XmlContent Link to the redirecting page.
28 function RedirectorLink($pagename) {
29 $url = WikiURL($pagename, array('redirectfrom' => ''));
30 return HTML::a(array('class' => 'redirectfrom wiki',
36 function actionPage(&$request, $action) {
39 $pagename = $request->getArg('pagename');
40 $version = $request->getArg('version');
42 $page = $request->getPage();
43 $revision = $page->getCurrentRevision();
45 $dbi = $request->getDbh();
46 $actionpage = $dbi->getPage($action);
47 $actionrev = $actionpage->getCurrentRevision();
49 $pagetitle = HTML(fmt("%s: %s",
50 $actionpage->getName(),
51 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
53 $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
54 '%mtime' => $revision->get('mtime')));
56 $request->appendValidators(array('pagerev' => $revision->getVersion(),
57 '%mtime' => $revision->get('mtime')));
58 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
59 '%mtime' => $actionrev->get('mtime')));
61 $transformedContent = $actionrev->getTransformedContent();
62 $template = Template('browse', array('CONTENT' => $transformedContent));
64 if (!headers_sent()) {
65 //FIXME: does not work yet. document.write not supported (signout button)
66 // http://www.w3.org/People/mimasa/test/xhtml/media-types/results
68 and (!isBrowserIE() and
69 strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
70 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
72 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
75 GeneratePage($template, $pagetitle, $revision);
76 $request->checkValidators();
80 function displayPage(&$request, $template=false) {
81 $pagename = $request->getArg('pagename');
82 $version = $request->getArg('version');
83 $page = $request->getPage();
85 $revision = $page->getRevision($version);
87 NoSuchRevision($request, $page, $version);
90 $revision = $page->getCurrentRevision();
93 if (isSubPage($pagename)) {
94 $pages = explode(SUBPAGE_SEPARATOR, $pagename);
95 $last_page = array_pop($pages); // deletes last element from array as side-effect
96 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
97 'class' => 'pagetitle'
99 SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
100 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
102 foreach ($pages as $p) {
103 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
104 'class' => 'backlinks'),
105 SplitPagename($p . SUBPAGE_SEPARATOR)));
106 $first_pages .= $p . SUBPAGE_SEPARATOR;
108 $backlink = HTML::a(array('href' => WikiURL($pagename,
109 array('action' => _("BackLinks"))),
110 'class' => 'backlinks'),
111 SplitPagename($last_page));
112 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
113 $pagetitle->pushContent($backlink);
115 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
116 array('action' => _("BackLinks"))),
117 'class' => 'backlinks'),
118 SplitPagename($pagename));
119 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
120 if ($request->getArg('frame'))
121 $pagetitle->setAttr('target', '_top');
124 $pageheader = $pagetitle;
125 if (($redirect_from = $request->getArg('redirectfrom'))) {
126 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
127 fmt("(Redirected from %s)",
128 RedirectorLink($redirect_from)));
131 $request->appendValidators(array('pagerev' => $revision->getVersion(),
132 '%mtime' => $revision->get('mtime')));
134 // FIXME: This is also in the template...
135 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
136 // FIXME: enable MathML/SVG/... support
139 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
140 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
142 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
145 $page_content = $revision->getTransformedContent();
147 // if external searchengine (google) referrer, highlight the searchterm
148 // FIXME: move that to the transformer?
149 // OR: add the searchhightplugin line to the content?
150 if ($result = isExternalReferrer($request)) {
151 if (DEBUG and !empty($result['query'])) {
152 //$GLOBALS['SearchHighLightQuery'] = $result['query'];
153 /* simply add the SearchHighLight plugin to the top of the page.
154 This just parses the wikitext, and doesn't highlight the markup */
155 include_once('lib/WikiPlugin.php');
156 $loader = new WikiPluginLoader;
157 $xml = $loader->expandPI('<'.'?plugin SearchHighLight s="'.$result['query'].'"?'.'>', $request, $markup);
158 if ($xml and is_array($xml)) {
159 foreach (array_reverse($xml) as $line) {
160 array_unshift($page_content->_content, $line);
162 array_unshift($page_content->_content,
163 HTML::div(_("You searched for: "), HTML::strong($result['query'])));
167 /* Parse the transformed (mixed HTML links + strings) lines?
168 This looks like overkill.
170 require_once("lib/TextSearchQuery.php");
171 $query = new TextSearchQuery($result['query']);
172 $hilight_re = $query->getHighlightRegexp();
173 //$matches = preg_grep("/$hilight_re/i", $revision->getContent());
175 for ($i=0; $i < count($page_content->_content); $i++) {
177 $line = $page_content->_content[$i];
178 if (is_string($line)) {
179 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
181 $line = substr($line, strlen($m[0]));
182 $html[] = $m[1]; // prematch
183 $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match
187 $html[] = $line; // postmatch
188 $page_content->_content[$i] = HTML::span(array('class' => 'search-context'),
196 $toks['CONTENT'] = new Template('browse', $request, $page_content);
198 $toks['TITLE'] = $pagetitle;
199 $toks['HEADER'] = $pageheader;
200 $toks['revision'] = $revision;
201 if (!empty($redirect_message))
202 $toks['redirected'] = $redirect_message;
203 $toks['ROBOTS_META'] = 'index,follow';
204 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
205 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
207 $template = new Template('html', $request);
209 $template->printExpansion($toks);
210 $page->increaseHitCount();
212 if ($request->getArg('action') != 'pdf')
213 $request->checkValidators();
217 // $Log: not supported by cvs2svn $
218 // Revision 1.57 2004/11/01 10:43:57 rurban
219 // seperate PassUser methods into seperate dir (memory usage)
220 // fix WikiUser (old) overlarge data session
221 // remove wikidb arg from various page class methods, use global ->_dbi instead
224 // Revision 1.56 2004/10/14 13:44:14 rurban
225 // fix lib/display.php:159: Warning[2]: Argument to array_reverse() should be an array
227 // Revision 1.55 2004/09/26 14:58:35 rurban
228 // naive SearchHighLight implementation
230 // Revision 1.54 2004/09/17 14:19:41 rurban
231 // disable Content-Type header for now, until it is fixed
233 // Revision 1.53 2004/06/25 14:29:20 rurban
234 // WikiGroup refactoring:
235 // global group attached to user, code for not_current user.
236 // improved helpers for special groups (avoid double invocations)
237 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
238 // fixed a XHTML validation error on userprefs.tmpl
240 // Revision 1.52 2004/06/14 11:31:37 rurban
241 // renamed global $Theme to $WikiTheme (gforge nameclash)
242 // inherit PageList default options from PageList
243 // default sortby=pagename
244 // use options in PageList_Selectable (limit, sortby, ...)
245 // added action revert, with button at action=diff
246 // added option regex to WikiAdminSearchReplace
248 // Revision 1.51 2004/05/18 16:23:39 rurban
249 // rename split_pagename to SplitPagename
251 // Revision 1.50 2004/05/04 22:34:25 rurban
254 // Revision 1.49 2004/04/18 01:11:52 rurban
255 // more numeric pagename fixes.
256 // fixed action=upload with merge conflict warnings.
257 // charset changed from constant to global (dynamic utf-8 switching)
265 // c-hanging-comment-ender-p: nil
266 // indent-tabs-mode: nil