2 // display.php: fetch page or get default content
3 rcs_id('$Id: display.php,v 1.56 2004-10-14 13:44:14 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 $pagetitle = HTML(fmt("%s: %s",
53 $actionpage->getName(),
54 $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
56 $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
57 '%mtime' => $revision->get('mtime')));
59 $request->appendValidators(array('pagerev' => $revision->getVersion(),
60 '%mtime' => $revision->get('mtime')));
61 $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
62 '%mtime' => $actionrev->get('mtime')));
64 $transformedContent = $actionrev->getTransformedContent();
65 $template = Template('browse', array('CONTENT' => $transformedContent));
67 if (!headers_sent()) {
68 //FIXME: does not work yet. document.write not supported (signout button)
69 // http://www.w3.org/People/mimasa/test/xhtml/media-types/results
71 and (!isBrowserIE() and
72 strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
73 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
75 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
78 GeneratePage($template, $pagetitle, $revision);
79 $request->checkValidators();
83 function displayPage(&$request, $template=false) {
84 $pagename = $request->getArg('pagename');
85 $version = $request->getArg('version');
86 $page = $request->getPage();
88 $revision = $page->getRevision($version);
90 NoSuchRevision($request, $page, $version);
93 $revision = $page->getCurrentRevision();
96 if (isSubPage($pagename)) {
97 $pages = explode(SUBPAGE_SEPARATOR, $pagename);
98 $last_page = array_pop($pages); // deletes last element from array as side-effect
99 $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
100 'class' => 'pagetitle'
102 SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
103 $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
105 foreach ($pages as $p) {
106 $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
107 'class' => 'backlinks'),
108 SplitPagename($p . SUBPAGE_SEPARATOR)));
109 $first_pages .= $p . SUBPAGE_SEPARATOR;
111 $backlink = HTML::a(array('href' => WikiURL($pagename,
112 array('action' => _("BackLinks"))),
113 'class' => 'backlinks'),
114 SplitPagename($last_page));
115 $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
116 $pagetitle->pushContent($backlink);
118 $pagetitle = HTML::a(array('href' => WikiURL($pagename,
119 array('action' => _("BackLinks"))),
120 'class' => 'backlinks'),
121 SplitPagename($pagename));
122 $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
123 if ($request->getArg('frame'))
124 $pagetitle->setAttr('target', '_top');
127 $pageheader = $pagetitle;
128 if (($redirect_from = $request->getArg('redirectfrom'))) {
129 $redirect_message = HTML::span(array('class' => 'redirectfrom'),
130 fmt("(Redirected from %s)",
131 RedirectorLink($redirect_from)));
134 $request->appendValidators(array('pagerev' => $revision->getVersion(),
135 '%mtime' => $revision->get('mtime')));
137 // FIXME: This is also in the template...
138 if ($request->getArg('action') != 'pdf' and !headers_sent()) {
139 // FIXME: enable MathML/SVG/... support
142 and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
143 header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
145 header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
148 $page_content = $revision->getTransformedContent();
150 // if external searchengine (google) referrer, highlight the searchterm
151 // FIXME: move that to the transformer?
152 // OR: add the searchhightplugin line to the content?
153 if ($result = isExternalReferrer($request)) {
154 if (DEBUG and !empty($result['query'])) {
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'])));
166 require_once("lib/TextSearchQuery.php");
167 $query = new TextSearchQuery($result['query']);
168 $hilight_re = $query->getHighlightRegexp();
169 $matches = preg_grep("/$hilight_re/i", $revision->getContent());
171 foreach ($page_content->_content as $line) {
172 if (is_string($line)) {
174 while (preg_match("/^(.*?)($hilight_re)/i", $line, $m)) {
175 $line = substr($line, strlen($m[0]));
176 $html[] = $m[1]; // prematch
177 $html[] = HTML::strong(array('class' => 'search-term'), $m[2]); // match
180 $html[] = $line; // postmatch
181 //$html = HTML::dd(HTML::small(array('class' => 'search-context'),
188 $toks['CONTENT'] = new Template('browse', $request, $page_content);
190 $toks['TITLE'] = $pagetitle;
191 $toks['HEADER'] = $pageheader;
192 $toks['revision'] = $revision;
193 if (!empty($redirect_message))
194 $toks['redirected'] = $redirect_message;
195 $toks['ROBOTS_META'] = 'index,follow';
196 $toks['PAGE_DESCRIPTION'] = $page_content->getDescription();
197 $toks['PAGE_KEYWORDS'] = GleanKeywords($page);
199 $template = new Template('html', $request);
201 $template->printExpansion($toks);
202 $page->increaseHitCount();
204 if ($request->getArg('action') != 'pdf')
205 $request->checkValidators();
209 // $Log: not supported by cvs2svn $
210 // Revision 1.55 2004/09/26 14:58:35 rurban
211 // naive SearchHighLight implementation
213 // Revision 1.54 2004/09/17 14:19:41 rurban
214 // disable Content-Type header for now, until it is fixed
216 // Revision 1.53 2004/06/25 14:29:20 rurban
217 // WikiGroup refactoring:
218 // global group attached to user, code for not_current user.
219 // improved helpers for special groups (avoid double invocations)
220 // new experimental config option ENABLE_XHTML_XML (fails with IE, and document.write())
221 // fixed a XHTML validation error on userprefs.tmpl
223 // Revision 1.52 2004/06/14 11:31:37 rurban
224 // renamed global $Theme to $WikiTheme (gforge nameclash)
225 // inherit PageList default options from PageList
226 // default sortby=pagename
227 // use options in PageList_Selectable (limit, sortby, ...)
228 // added action revert, with button at action=diff
229 // added option regex to WikiAdminSearchReplace
231 // Revision 1.51 2004/05/18 16:23:39 rurban
232 // rename split_pagename to SplitPagename
234 // Revision 1.50 2004/05/04 22:34:25 rurban
237 // Revision 1.49 2004/04/18 01:11:52 rurban
238 // more numeric pagename fixes.
239 // fixed action=upload with merge conflict warnings.
240 // charset changed from constant to global (dynamic utf-8 switching)
248 // c-hanging-comment-ender-p: nil
249 // indent-tabs-mode: nil