]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
Add getDescription function
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3
4 /**
5  * List of changes on all pages which are linked to from this page.
6  * This is good usage for an action button, similar to LikePages.
7  *
8  * DONE: days links requires action=RelatedChanges arg
9  */
10
11 require_once("lib/plugin/RecentChanges.php");
12
13 class _RelatedChanges_HtmlFormatter
14 extends _RecentChanges_HtmlFormatter
15 {
16     function description() {
17         return HTML::p(false, $this->pre_description(),
18          fmt(" (to pages linked from \"%s\")",$this->_args['page']));
19     }
20 }
21
22
23 class WikiPlugin_RelatedChanges
24 extends WikiPlugin_RecentChanges
25 {
26     function getName () {
27         return _("RecentEdits");
28     }
29
30     function getDescription () {
31         return _("List of changes on all pages which are linked to from this page.");
32     }
33
34     function getVersion() {
35         return preg_replace("/[Revision: $]/", '',
36                             "\$Revision$");
37     }
38
39     function getDefaultArguments() {
40         //php-4.0.4pl1 breaks at the parent:: line even if the 
41         // code doesn't reach this line
42         //if (!check_php_version(4,0,6))
43         $args = WikiPlugin_RecentChanges::getDefaultArguments();
44         //else $args = parent::getDefaultArguments();
45         $args['page'] = '[pagename]';
46         $args['show_minor'] = true;
47         $args['show_all'] = true;
48         $args['caption'] = _("Related Changes");
49         return $args;
50     }
51
52     function getChanges ($dbi, $args) {
53         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
54
55         $show_deleted = $args['show_deleted'];
56         if ($show_deleted == 'sometimes')
57             $show_deleted = $args['show_minor'];
58         if (!$show_deleted)
59             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
60
61         // sort out pages not linked from our page
62         $changes = new RelatedChangesRevisionIterator($changes, $dbi, $args['page']);
63         return $changes;
64     }
65
66     // box is used to display a fixed-width, narrow version with common header.
67     // just a numbered list of limit pagenames, without date.
68     function box($args = false, $request = false, $basepage = false) {
69         if (!$request) $request =& $GLOBALS['request'];
70         if (!isset($args['limit'])) $args['limit'] = 15;
71         $args['format'] = 'box';
72         $args['show_minor'] = false;
73         $args['show_major'] = true;
74         $args['show_deleted'] = false;
75         $args['show_all'] = false;
76         $args['days'] = 90;
77         return $this->makeBox(WikiLink(_("RelatedChanges"),'',_("Related Changes")),
78                               $this->format($this->getChanges($request->_dbi, $args), $args));
79     }
80
81     function format ($changes, $args) {
82         global $WikiTheme;
83         $format = $args['format'];
84
85         $fmt_class = $WikiTheme->getFormatter('RelatedChanges', $format);
86         if (!$fmt_class) {
87             if ($format == 'rss')
88                 $fmt_class = '_RecentChanges_RssFormatter';
89             elseif ($format == 'rss2')
90                 $fmt_class = '_RecentChanges_Rss2Formatter';
91             elseif ($format == 'rss091') {
92                 include_once "lib/RSSWriter091.php";
93                 $fmt_class = '_RecentChanges_RssFormatter091';
94             }
95             elseif ($format == 'sidebar')
96                 $fmt_class = '_RecentChanges_SideBarFormatter';
97             elseif ($format == 'box')
98                 $fmt_class = '_RecentChanges_BoxFormatter';
99             else
100                 $fmt_class = '_RelatedChanges_HtmlFormatter';
101         }
102   
103         $fmt = new $fmt_class($args);
104         return $fmt->format($changes);
105     }
106 }
107
108 /**
109  * list of pages which are linked from the current page.
110  * i.e. sort out all non-linked pages.
111  */
112 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
113 {
114     function RelatedChangesRevisionIterator ($revisions, &$dbi, $pagename) {
115         $this->_revisions = $revisions;
116         $this->_wikidb = $dbi;
117         $page = $dbi->getPage($pagename);
118         $links = $page->getLinks();
119         $this->_links = array();
120         while ($linked_page = $links->next()) {
121             $this->_links[$linked_page->_pagename] = 1;
122         }
123         $links->free();
124     }
125
126     function next () {
127         while (($rev = $this->_revisions->next())) {
128             if (isset($this->_links[$rev->_pagename]))
129                 return $rev;
130         }
131         $this->free();
132         return false;
133     }
134 }
135
136 // (c-file-style: "gnu")
137 // Local Variables:
138 // mode: php
139 // tab-width: 8
140 // c-basic-offset: 4
141 // c-hanging-comment-ender-p: nil
142 // indent-tabs-mode: nil
143 // End:
144 ?>