]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
Refactor/cleanup of login code continues.
[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.16 2002-01-23 05:10:22 dairiki 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(&$request, $tmpl = 'browse') {
45     $pagename = $request->getArg('pagename');
46     $version = $request->getArg('version');
47     $page = $request->getPage();
48     
49     
50     if ($version) {
51         $revision = $page->getRevision($version);
52         if (!$revision)
53             NoSuchRevision($request, $pagename, $version);
54     }
55     else {
56         $revision = $page->getCurrentRevision();
57     }
58
59     $splitname = split_pagename($pagename);
60     $pagetitle = HTML::a(array('href' => WikiURL(_("BackLinks"),
61                                                  array('page' => $pagename)),
62                                'class' => 'backlinks'),
63                          $splitname);
64     $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
65
66
67     $wrapper = new WikiTemplate('top');
68     $wrapper->setPageRevisionTokens($revision);
69     $wrapper->qreplace('TITLE', $splitname);
70     $wrapper->replace('HEADER', $pagetitle);
71     $wrapper->qreplace('ROBOTS_META', 'index,follow');
72
73
74     $template = new WikiTemplate($tmpl);
75     $template->replace('CONTENT', do_transform($revision->getContent()));
76     $template->qreplace('PAGE_DESCRIPTION', GleanDescription($revision));
77
78     $wrapper->printExpansion($template);
79     flush();
80     $page->increaseHitCount();
81 }
82
83 // For emacs users
84 // Local Variables:
85 // mode: php
86 // tab-width: 8
87 // c-basic-offset: 4
88 // c-hanging-comment-ender-p: nil
89 // indent-tabs-mode: nil
90 // End:
91
92 ?>