]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
Replace tabs by spaces; remove EOL spaces
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /*
4  * Copyright (C) 2004 $ThePhpWikiProgrammingTeam
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with PhpWiki; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23 /**
24  * List of changes on all pages which are linked to from this page.
25  * This is good usage for an action button, similar to LikePages.
26  *
27  * DONE: days links requires action=RelatedChanges arg
28  */
29
30 require_once("lib/plugin/RecentChanges.php");
31
32 class _RelatedChanges_HtmlFormatter
33 extends _RecentChanges_HtmlFormatter
34 {
35     function description() {
36         return HTML::p(false, $this->pre_description(),
37          fmt(" (to pages linked from \"%s\")",$this->_args['page']));
38     }
39 }
40
41
42 class WikiPlugin_RelatedChanges
43 extends WikiPlugin_RecentChanges
44 {
45     function getName () {
46         return _("RecentEdits");
47     }
48
49     function getDescription () {
50         return _("List of changes on all pages which are linked to from this page.");
51     }
52
53     function getVersion() {
54         return preg_replace("/[Revision: $]/", '',
55                             "\$Revision$");
56     }
57
58     function getDefaultArguments() {
59             //php-4.0.4pl1 breaks at the parent:: line even if the
60             // code doesn't reach this line
61         //if (!check_php_version(4,0,6))
62         $args = WikiPlugin_RecentChanges::getDefaultArguments();
63         //else $args = parent::getDefaultArguments();
64         $args['page'] = '[pagename]';
65         $args['show_minor'] = true;
66         $args['show_all'] = true;
67         $args['caption'] = _("Related Changes");
68         return $args;
69     }
70
71     function getChanges ($dbi, $args) {
72         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
73
74         $show_deleted = $args['show_deleted'];
75         if ($show_deleted == 'sometimes')
76             $show_deleted = $args['show_minor'];
77         if (!$show_deleted)
78             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
79
80         // sort out pages not linked from our page
81         $changes = new RelatedChangesRevisionIterator($changes, $dbi, $args['page']);
82         return $changes;
83     }
84
85     // box is used to display a fixed-width, narrow version with common header.
86     // just a numbered list of limit pagenames, without date.
87     function box($args = false, $request = false, $basepage = false) {
88         if (!$request) $request =& $GLOBALS['request'];
89         if (!isset($args['limit'])) $args['limit'] = 15;
90         $args['format'] = 'box';
91         $args['show_minor'] = false;
92         $args['show_major'] = true;
93         $args['show_deleted'] = false;
94         $args['show_all'] = false;
95         $args['days'] = 90;
96         return $this->makeBox(WikiLink(_("RelatedChanges"),'',_("Related Changes")),
97                               $this->format($this->getChanges($request->_dbi, $args), $args));
98     }
99
100     function format ($changes, $args) {
101         global $WikiTheme;
102         $format = $args['format'];
103
104         $fmt_class = $WikiTheme->getFormatter('RelatedChanges', $format);
105         if (!$fmt_class) {
106             if ($format == 'rss')
107                 $fmt_class = '_RecentChanges_RssFormatter';
108             elseif ($format == 'rss2')
109                 $fmt_class = '_RecentChanges_Rss2Formatter';
110             elseif ($format == 'rss091') {
111                 include_once "lib/RSSWriter091.php";
112                 $fmt_class = '_RecentChanges_RssFormatter091';
113             }
114             elseif ($format == 'sidebar')
115                 $fmt_class = '_RecentChanges_SideBarFormatter';
116             elseif ($format == 'box')
117                 $fmt_class = '_RecentChanges_BoxFormatter';
118             else
119                 $fmt_class = '_RelatedChanges_HtmlFormatter';
120         }
121
122         $fmt = new $fmt_class($args);
123         return $fmt->format($changes);
124     }
125 }
126
127 /**
128  * list of pages which are linked from the current page.
129  * i.e. sort out all non-linked pages.
130  */
131 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
132 {
133     function RelatedChangesRevisionIterator ($revisions, &$dbi, $pagename) {
134         $this->_revisions = $revisions;
135         $this->_wikidb = $dbi;
136         $page = $dbi->getPage($pagename);
137         $links = $page->getLinks();
138         $this->_links = array();
139         while ($linked_page = $links->next()) {
140             $this->_links[$linked_page->_pagename] = 1;
141         }
142         $links->free();
143     }
144
145     function next () {
146         while (($rev = $this->_revisions->next())) {
147             if (isset($this->_links[$rev->_pagename]))
148                 return $rev;
149         }
150         $this->free();
151         return false;
152     }
153 }
154
155 // (c-file-style: "gnu")
156 // Local Variables:
157 // mode: php
158 // tab-width: 8
159 // c-basic-offset: 4
160 // c-hanging-comment-ender-p: nil
161 // indent-tabs-mode: nil
162 // End:
163 ?>