]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
Transform API cleanup.
[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.25 2002-02-08 03:01:11 dairiki 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     $splitname = split_pagename($pagename);
58     $pagetitle = HTML($actionpage->getName(), ": ",
59                       $Theme->linkExistingWikiWord($pagename, false, $version));
60
61     $template = Template('browse', array('CONTENT' => TransformText($actionrev)));
62     
63     GeneratePage($template, $pagetitle, $revision);
64     flush();
65 }
66
67 function displayPage(&$request, $tmpl = 'browse') {
68     $pagename = $request->getArg('pagename');
69     $version = $request->getArg('version');
70     $page = $request->getPage();
71     if ($version) {
72         $page = $request->getPage();
73         $revision = $page->getRevision($version);
74         if (!$revision)
75             NoSuchRevision($request, $page, $version);
76     }
77     else {
78         $revision = $page->getCurrentRevision();
79     }
80
81     $splitname = split_pagename($pagename);
82     $pagetitle = HTML::a(array('href' => WikiURL($pagename,
83                                                  array('action' => _("BackLinks"))),
84                                'class' => 'backlinks'),
85                          $splitname);
86     $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
87
88     include_once('lib/BlockParser.php');
89     $template = Template($tmpl, array('CONTENT' => TransformText($revision)));
90
91     GeneratePage($template, $pagetitle, $revision,
92                  array('ROBOTS_META'    => 'index,follow',
93                        'PAGE_DESCRIPTION' => GleanDescription($revision)));
94     flush();
95
96     $page->increaseHitCount();
97 }
98
99 // For emacs users
100 // Local Variables:
101 // mode: php
102 // tab-width: 8
103 // c-basic-offset: 4
104 // c-hanging-comment-ender-p: nil
105 // indent-tabs-mode: nil
106 // End:
107
108 ?>