]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
minor code optimizations (removed an unused line and a duplicate line)
[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.30 2002-03-06 03:52:22 carstenklapp 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
27     $content = $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     $pagetitle = HTML(fmt("%s: %s", $actionpage->getName(),
58                           $Theme->linkExistingWikiWord($pagename, false, $version)));
59
60     require_once('lib/PageType.php');
61     $transformedContent = PageType($actionrev);
62     $template = Template('browse', array('CONTENT' => $transformedContent));
63
64     header("Content-Type: text/html; charset=" . CHARSET);
65     header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
66
67     GeneratePage($template, $pagetitle, $revision);
68     flush();
69 }
70
71 function displayPage(&$request, $tmpl = 'browse') {
72     $pagename = $request->getArg('pagename');
73     $version = $request->getArg('version');
74     $page = $request->getPage();
75     if ($version) {
76         $revision = $page->getRevision($version);
77         if (!$revision)
78             NoSuchRevision($request, $page, $version);
79     }
80     else {
81         $revision = $page->getCurrentRevision();
82     }
83
84     $splitname = split_pagename($pagename);
85     $pagetitle = HTML::a(array('href' => WikiURL($pagename,
86                                                  array('action' => _("BackLinks"))),
87                                'class' => 'backlinks'),
88                          $splitname);
89     $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
90
91     require_once('lib/PageType.php');
92     $transformedContent = PageType($revision);
93     $template = Template('browse', array('CONTENT' => $transformedContent));
94
95     header("Content-Type: text/html; charset=" . CHARSET);
96     // don't clobber date header given by RC
97     if ( ! ($pagename == _("RecentChanges") || $pagename == _("RecentEdits")) )
98         header("Last-Modified: ".Rfc2822DateTime($revision->get('mtime')));
99
100     GeneratePage($template, $pagetitle, $revision,
101                  array('ROBOTS_META'    => 'index,follow',
102                        'PAGE_DESCRIPTION' => GleanDescription($revision)));
103     flush();
104
105     $page->increaseHitCount();
106 }
107
108 // For emacs users
109 // Local Variables:
110 // mode: php
111 // tab-width: 8
112 // c-basic-offset: 4
113 // c-hanging-comment-ender-p: nil
114 // indent-tabs-mode: nil
115 // End:
116 ?>