]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/display.php
Start of new parser. It doesn't work yet.
[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.18 2002-01-25 01:04:13 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
45 function displayPage(&$request, $tmpl = 'browse') {
46     $pagename = $request->getArg('pagename');
47     $version = $request->getArg('version');
48     $page = $request->getPage();
49     
50     
51     if ($version) {
52         $revision = $page->getRevision($version);
53         if (!$revision)
54             NoSuchRevision($request, $page, $version);
55     }
56     else {
57         $revision = $page->getCurrentRevision();
58     }
59
60     $splitname = split_pagename($pagename);
61     $pagetitle = HTML::a(array('href' => WikiURL(_("BackLinks"),
62                                                  array('page' => $pagename)),
63                                'class' => 'backlinks'),
64                          $splitname);
65     $pagetitle->addTooltip(sprintf(_("BackLinks for %s"), $pagename));
66
67
68     if (0) {
69         include_once('lib/BlockParser.php');
70         global $BlockParser;
71         $content = $BlockParser->parse($revision->getPackedContent());
72         //print_r($content);
73         $template = Template($tmpl, array('CONTENT' => $content));
74     }
75     else
76         $template = Template($tmpl, do_transform($revision->getContent()));
77     
78
79     GeneratePage($template, $pagetitle, $revision,
80                  array('ROBOTS_META'    => 'index,follow',
81                        'PAGE_DESCRIPTION' => GleanDescription($revision)));
82     flush();
83     $page->increaseHitCount();
84 }
85
86 // For emacs users
87 // Local Variables:
88 // mode: php
89 // tab-width: 8
90 // c-basic-offset: 4
91 // c-hanging-comment-ender-p: nil
92 // indent-tabs-mode: nil
93 // End:
94
95 ?>