]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
Update to use new ActionPage paradigm for backlinks.
[SourceForge/phpwiki.git] / lib / display.php
1 <?php
2 // display.php: fetch page or get default content
3 // calls transform.php for actual transformation of wiki markup to HTML
4 rcs_id('$Id: display.php,v 1.24 2002-01-30 00:36:19 dairiki Exp $');
5
6 require_once('lib/Template.php');
7 //require_once('lib/transform.php');
8 require_once('lib/BlockParser.php');
9
10 /**
11  * Guess a short description of the page.
12  *
13  * Algorithm:
14  *
15  * This algorithm was suggested on MeatballWiki by
16  * Alex Schroeder <kensanata@yahoo.com>.
17  *
18  * Use the first paragraph in the page which contains at least two
19  * sentences.
20  *
21  * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
22  */
23 function GleanDescription ($rev) {
24     $two_sentences
25         = pcre_fix_posix_classes("/[.?!]\s+[[:upper:])]"
26                                  . ".*"
27                                  . "[.?!]\s*([[:upper:])]|$)/sx");
28         
29     $content = $rev->getPackedContent();
30
31     // Iterate through paragraphs.
32     while (preg_match('/(?: ^ \w .* $ \n? )+/mx', $content, $m)) {
33         $paragraph = $m[0];
34         
35         // Return paragraph if it contains at least two sentences.
36         if (preg_match($two_sentences, $paragraph)) {
37             return preg_replace("/\s*\n\s*/", " ", trim($paragraph));
38         }
39
40         $content = substr(strstr($content, $paragraph), strlen($paragraph));
41     }
42     return '';
43 }
44
45
46 function actionPage(&$request, $action) {
47     global $Theme;
48     
49     $pagename = $request->getArg('pagename');
50     $version = $request->getArg('version');
51
52     $page = $request->getPage();
53     $revision = $page->getCurrentRevision();
54
55     $dbi = $request->getDbh();
56     $actionpage = $dbi->getPage($action);
57     $actionrev = $actionpage->getCurrentRevision();
58
59     $splitname = split_pagename($pagename);
60     $pagetitle = HTML($actionpage->getName(), ": ",
61                       $Theme->linkExistingWikiWord($pagename, false, $version));
62
63     $template = Template('browse', array('CONTENT' => TransformRevision($actionrev)));
64     
65     GeneratePage($template, $pagetitle, $revision);
66     flush();
67 }
68
69 function displayPage(&$request, $tmpl = 'browse') {
70     $pagename = $request->getArg('pagename');
71     $version = $request->getArg('version');
72     $page = $request->getPage();
73     if ($version) {
74         $page = $request->getPage();
75         $revision = $page->getRevision($version);
76         if (!$revision)
77             NoSuchRevision($request, $page, $version);
78     }
79     else {
80         $revision = $page->getCurrentRevision();
81     }
82
83     $splitname = split_pagename($pagename);
84     $pagetitle = HTML::a(array('href' => WikiURL($pagename,
85                                                  array('action' => _("BackLinks"))),
86                                'class' => 'backlinks'),
87                          $splitname);
88     $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
89
90     include_once('lib/BlockParser.php');
91     $template = Template($tmpl, array('CONTENT' => TransformRevision($revision)));
92
93     GeneratePage($template, $pagetitle, $revision,
94                  array('ROBOTS_META'    => 'index,follow',
95                        'PAGE_DESCRIPTION' => GleanDescription($revision)));
96     flush();
97
98     $page->increaseHitCount();
99 }
100
101 // For emacs users
102 // Local Variables:
103 // mode: php
104 // tab-width: 8
105 // c-basic-offset: 4
106 // c-hanging-comment-ender-p: nil
107 // indent-tabs-mode: nil
108 // End:
109
110 ?>