]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
disable Content-Type header for now, until it is fixed
[SourceForge/phpwiki.git] / lib / display.php
1 <?php
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 $');
4
5 require_once('lib/Template.php');
6
7 /**
8  * Extract keywords from Category* links on page. 
9  */
10 function GleanKeywords ($page) {
11     global $KeywordLinkRegexp;
12
13     $links = $page->getLinks(false);
14
15     $keywords[] = SplitPagename($page->getName());
16     
17     while ($link = $links->next())
18         if (preg_match("/${KeywordLinkRegexp}/x", $link->getName(), $m))
19             $keywords[] = SplitPagename($m[0]);
20
21     $keywords[] = WIKI_NAME;
22     
23     return join(', ', $keywords);
24 }
25
26 /** Make a link back to redirecting page.
27  *
28  * @param $pagename string  Name of redirecting page.
29  * @return XmlContent Link to the redirecting page.
30  */
31 function RedirectorLink($pagename) {
32     $url = WikiURL($pagename, array('redirectfrom' => ''));
33     return HTML::a(array('class' => 'redirectfrom wiki',
34                          'href' => $url),
35                    $pagename);
36 }
37
38     
39 function actionPage(&$request, $action) {
40     global $WikiTheme;
41
42     $pagename = $request->getArg('pagename');
43     $version = $request->getArg('version');
44
45     $page = $request->getPage();
46     $revision = $page->getCurrentRevision();
47
48     $dbi = $request->getDbh();
49     $actionpage = $dbi->getPage($action);
50     $actionrev = $actionpage->getCurrentRevision();
51
52     // $splitname = SplitPagename($pagename);
53
54     $pagetitle = HTML(fmt("%s: %s", 
55                           $actionpage->getName(),
56                           $WikiTheme->linkExistingWikiWord($pagename, false, $version)));
57
58     $validators = new HTTP_ValidatorSet(array('pageversion' => $revision->getVersion(),
59                                               '%mtime' => $revision->get('mtime')));
60                                         
61     $request->appendValidators(array('pagerev' => $revision->getVersion(),
62                                      '%mtime' => $revision->get('mtime')));
63     $request->appendValidators(array('actionpagerev' => $actionrev->getVersion(),
64                                      '%mtime' => $actionrev->get('mtime')));
65
66     $transformedContent = $actionrev->getTransformedContent();
67     $template = Template('browse', array('CONTENT' => $transformedContent));
68 /*
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
72         if (ENABLE_XHTML_XML 
73             and (!isBrowserIE() and
74                  strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
75             header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
76         else
77             header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
78     }
79 */    
80     GeneratePage($template, $pagetitle, $revision);
81     $request->checkValidators();
82     flush();
83 }
84
85 function displayPage(&$request, $template=false) {
86     $pagename = $request->getArg('pagename');
87     $version = $request->getArg('version');
88     $page = $request->getPage();
89     if ($version) {
90         $revision = $page->getRevision($version);
91         if (!$revision)
92             NoSuchRevision($request, $page, $version);
93     }
94     else {
95         $revision = $page->getCurrentRevision();
96     }
97
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'
104                                               ),
105                                         SplitPagename($pages[0] . SUBPAGE_SEPARATOR)));
106         $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
107         array_shift($pages);
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;
113         }
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);
120     } else {
121         $pagetitle = HTML::a(array('href' => WikiURL($pagename,
122                                                      array('action' => _("BackLinks"))),
123                                    'class' => 'backlinks'),
124                              $splitname);
125         $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
126         if ($request->getArg('frame'))
127             $pagetitle->setAttr('target', '_top');
128     }
129
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)));
135     }
136
137     $request->appendValidators(array('pagerev' => $revision->getVersion(),
138                                      '%mtime' => $revision->get('mtime')));
139 /*
140     // FIXME: This is also in the template...
141     if ($request->getArg('action') != 'pdf' and !headers_sent()) {
142       // FIXME: enable MathML/SVG/... support
143       if (ENABLE_XHTML_XML
144              and (!isBrowserIE()
145                   and strstr($request->get('HTTP_ACCEPT'),'application/xhtml+xml')))
146             header("Content-Type: application/xhtml+xml; charset=" . $GLOBALS['charset']);
147         else
148             header("Content-Type: text/html; charset=" . $GLOBALS['charset']);
149     }
150 */
151     $page_content = $revision->getTransformedContent();
152     
153     $toks['CONTENT'] = new Template('browse', $request, $page_content);
154     
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);
163     
164     if (!$template)
165         $template = new Template('html', $request);
166
167     $template->printExpansion($toks);
168     $page->increaseHitCount();
169
170     if ($request->getArg('action') != 'pdf')
171         $request->checkValidators();
172     flush();
173 }
174
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
182 //
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
190 //
191 // Revision 1.51  2004/05/18 16:23:39  rurban
192 // rename split_pagename to SplitPagename
193 //
194 // Revision 1.50  2004/05/04 22:34:25  rurban
195 // more pdf support
196 //
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)
201 //
202
203 // For emacs users
204 // Local Variables:
205 // mode: php
206 // tab-width: 8
207 // c-basic-offset: 4
208 // c-hanging-comment-ender-p: nil
209 // indent-tabs-mode: nil
210 // End:
211 ?>