]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
fixed login, theme selection, UserPreferences.
[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.35 2002-08-23 18:29:30 rurban Exp $');
4
5 require_once('lib/Template.php');
6 require_once('lib/BlockParser.php');
7
8 /**
9  * Guess a short description of the page.
10  *
11  * Algorithm:
12  *
13  * This algorithm was suggested on MeatballWiki by
14  * Alex Schroeder <kensanata@yahoo.com>.
15  *
16  * Use the first paragraph in the page which contains at least two
17  * sentences.
18  *
19  * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
20  */
21 function GleanDescription ($rev) {
22     $two_sentences
23         = pcre_fix_posix_classes("/[.?!]\s+[[:upper:])]"
24                                  . ".*"
25                                  . "[.?!]\s*([[:upper:])]|$)/sx");
26     // Escape strings
27     $content = preg_replace("/(['\"])/", "\$1", $rev->getPackedContent());
28
29     // Iterate through paragraphs.
30     while (preg_match('/(?: ^ \w .* $ \n? )+/mx', $content, $m)) {
31         $paragraph = $m[0];
32
33         // Return paragraph if it contains at least two sentences.
34         if (preg_match($two_sentences, $paragraph)) {
35             return preg_replace("/\s*\n\s*/", " ", trim($paragraph));
36         }
37
38         $content = substr(strstr($content, $paragraph), strlen($paragraph));
39     }
40     return '';
41 }
42
43
44 function actionPage(&$request, $action) {
45     global $Theme;
46
47     $pagename = $request->getArg('pagename');
48     $version = $request->getArg('version');
49
50     $page = $request->getPage();
51     $revision = $page->getCurrentRevision();
52
53     $dbi = $request->getDbh();
54     $actionpage = $dbi->getPage($action);
55     $actionrev = $actionpage->getCurrentRevision();
56
57     // $splitname = split_pagename($pagename);
58
59     $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
60                           $Theme->linkExistingWikiWord($pagename, false, $version)));
61
62     require_once('lib/PageType.php');
63     $transformedContent = PageType($actionrev);
64     $template = Template('browse', array('CONTENT' => $transformedContent));
65
66     header("Content-Type: text/html; charset=" . CHARSET);
67     if (!defined('DEBUG')) {
68         header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
69     }
70
71     // $template = Template('browse', array('CONTENT' => TransformText($actionrev)));
72     
73     GeneratePage($template, $pagetitle, $revision);
74     flush();
75 }
76
77 function displayPage(&$request, $tmpl = 'browse') {
78     $pagename = $request->getArg('pagename');
79     $version = $request->getArg('version');
80     $page = $request->getPage();
81     if ($version) {
82         $revision = $page->getRevision($version);
83         if (!$revision)
84             NoSuchRevision($request, $page, $version);
85     }
86     else {
87         $revision = $page->getCurrentRevision();
88     }
89
90     $splitname = split_pagename($pagename);
91     if (isSubPage($pagename)) {
92         $pages = explode(SUBPAGE_SEPARATOR,$pagename);
93         $last_page = array_pop($pages); // deletes last element from array as side-effect
94         $pagetitle = HTML::span(HTML::a(array('href' => WikiURL($pages[0]),
95                                               //'class' => 'backlinks'
96                                               ),
97                                         split_pagename($pages[0] . SUBPAGE_SEPARATOR)));
98         $first_pages = $pages[0] . SUBPAGE_SEPARATOR;
99         array_shift($pages);
100         foreach ($pages as $p)  {
101             $pagetitle->pushContent(HTML::a(array('href' => WikiURL($first_pages . $p),
102                                                   'class' => 'backlinks'),
103                                        split_pagename($p . SUBPAGE_SEPARATOR)));
104             $first_pages .= $p . SUBPAGE_SEPARATOR;
105         }
106         $backlink = HTML::a(array('href' => WikiURL($pagename,
107                                                     array('action' => _("BackLinks"))),
108                                   'class' => 'backlinks'),
109                             split_pagename($last_page));
110         $backlink->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
111         $pagetitle->pushContent($backlink);
112     } else {
113         $pagetitle = HTML::a(array('href' => WikiURL($pagename,
114                                                      array('action' => _("BackLinks"))),
115                                    'class' => 'backlinks'),
116                              $splitname);
117         $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
118     }
119
120     //include_once('lib/BlockParser.php');
121
122     require_once('lib/PageType.php');
123     if ($frame = $request->getArg('frame')) {
124         if (in_array($frame,array('body','browse','editpage')))
125             $template = Template($frame, array('CONTENT' => PageType($revision)));
126         elseif ($frame == 'top')
127             $template = Template($frame, array('framesrc' => $request->getArg('framesrc')));
128         else
129             $template = Template($frame);
130     } else {
131         $transformedContent = PageType($revision);
132         $template = Template('browse', array('CONTENT' => $transformedContent));
133     }
134
135     header("Content-Type: text/html; charset=" . CHARSET);
136     // don't clobber date header given by RC
137     if ( ! ($pagename == _("RecentChanges") || $pagename == _("RecentEdits") || defined('DEBUG')) )
138         header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
139
140     GeneratePage($template, $pagetitle, $revision,
141                  array('ROBOTS_META'    => 'index,follow',
142                        'PAGE_DESCRIPTION' => GleanDescription($revision)));
143     flush();
144
145     $page->increaseHitCount();
146 }
147
148 // For emacs users
149 // Local Variables:
150 // mode: php
151 // tab-width: 8
152 // c-basic-offset: 4
153 // c-hanging-comment-ender-p: nil
154 // indent-tabs-mode: nil
155 // End:
156 ?>