]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
Minor reindenting & rewrapping.
[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.13 2002-01-09 17:30:39 carstenklapp Exp $');
5
6 require_once('lib/Template.php');
7 require_once('lib/transform.php');
8
9 /**
10  * Guess a short description of the page.
11  *
12  * Algorithm:
13  *
14  * This algorithm was suggested on MeatballWiki by
15  * Alex Schroeder <kensanata@yahoo.com>.
16  *
17  * Use the first paragraph in the page which contains at least two
18  * sentences.
19  *
20  * @see http://www.usemod.com/cgi-bin/mb.pl?MeatballWikiSuggestions
21  */
22 function GleanDescription ($rev) {
23     $two_sentences
24         = pcre_fix_posix_classes("/[.?!]\s+[[:upper:])]"
25                                  . ".*"
26                                  . "[.?!]\s*([[:upper:])]|$)/sx");
27         
28     $content = $rev->getPackedContent();
29
30     // Iterate through paragraphs.
31     while (preg_match('/(?: ^ \w .* $ \n? )+/mx', $content, $m)) {
32         $paragraph = $m[0];
33         
34         // Return paragraph if it contains at least two sentences.
35         if (preg_match($two_sentences, $paragraph)) {
36             return preg_replace("/\s*\n\s*/", " ", trim($paragraph));
37         }
38
39         $content = substr(strstr($content, $paragraph), strlen($paragraph));
40     }
41     return '';
42 }
43
44 function displayPage($dbi, $request) {
45     $pagename = $request->getArg('pagename');
46     $version = $request->getArg('version');
47    
48     $page = $dbi->getPage($pagename);
49     if ($version) {
50         $revision = $page->getRevision($version);
51         if (!$revision)
52             NoSuchRevision($page, $version);
53     }
54     else {
55         $revision = $page->getCurrentRevision();
56     }
57
58     $template = new WikiTemplate('BROWSE');
59     $template->setPageRevisionTokens($revision);
60     $template->replace('CONTENT', do_transform($revision->getContent()));
61     $template->qreplace('PAGE_DESCRIPTION', GleanDescription($revision));
62     echo $template->getExpansion();
63     flush();
64     $page->increaseHitCount();
65 }
66
67 // For emacs users
68 // Local Variables:
69 // mode: php
70 // tab-width: 8
71 // c-basic-offset: 4
72 // c-hanging-comment-ender-p: nil
73 // indent-tabs-mode: nil
74 // End:
75
76 ?>