]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
Remove unused
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php
2
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 along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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     {
37         return HTML::p(false, $this->pre_description(),
38             fmt(" (to pages linked from \"%s\")", $this->_args['page']));
39     }
40 }
41
42 class WikiPlugin_RelatedChanges
43     extends WikiPlugin_RecentChanges
44 {
45     function getName()
46     {
47         return _("RecentEdits");
48     }
49
50     function getDescription()
51     {
52         return _("List of changes on all pages which are linked to from this page.");
53     }
54
55     function getDefaultArguments()
56     {
57         $args = parent::getDefaultArguments();
58         $args['page'] = '[pagename]';
59         $args['show_minor'] = true;
60         $args['show_all'] = true;
61         $args['caption'] = _("Related Changes");
62         return $args;
63     }
64
65     function getChanges($dbi, $args)
66     {
67         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
68
69         $show_deleted = $args['show_deleted'];
70         if ($show_deleted == 'sometimes')
71             $show_deleted = $args['show_minor'];
72         if (!$show_deleted)
73             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
74
75         // sort out pages not linked from our page
76         $changes = new RelatedChangesRevisionIterator($changes, $dbi, $args['page']);
77         return $changes;
78     }
79
80     // box is used to display a fixed-width, narrow version with common header.
81     // just a numbered list of limit pagenames, without date.
82     function box($args = false, $request = false, $basepage = false)
83     {
84         if (!$request) $request =& $GLOBALS['request'];
85         if (!isset($args['limit'])) $args['limit'] = 15;
86         $args['format'] = 'box';
87         $args['show_minor'] = false;
88         $args['show_major'] = true;
89         $args['show_deleted'] = false;
90         $args['show_all'] = false;
91         $args['days'] = 90;
92         return $this->makeBox(WikiLink(_("RelatedChanges"), '', _("Related Changes")),
93             $this->format($this->getChanges($request->_dbi, $args), $args));
94     }
95
96     function format($changes, $args)
97     {
98         global $WikiTheme;
99         $format = $args['format'];
100
101         $fmt_class = $WikiTheme->getFormatter('RelatedChanges', $format);
102         if (!$fmt_class) {
103             if ($format == 'rss')
104                 $fmt_class = '_RecentChanges_RssFormatter';
105             elseif ($format == 'rss2')
106                 $fmt_class = '_RecentChanges_Rss2Formatter'; elseif ($format == 'rss091') {
107                 include_once 'lib/RSSWriter091.php';
108                 $fmt_class = '_RecentChanges_RssFormatter091';
109             } elseif ($format == 'sidebar')
110                 $fmt_class = '_RecentChanges_SideBarFormatter'; elseif ($format == 'box')
111                 $fmt_class = '_RecentChanges_BoxFormatter'; else
112                 $fmt_class = '_RelatedChanges_HtmlFormatter';
113         }
114
115         $fmt = new $fmt_class($args);
116         return $fmt->format($changes);
117     }
118 }
119
120 /**
121  * list of pages which are linked from the current page.
122  * i.e. sort out all non-linked pages.
123  */
124 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
125 {
126     function RelatedChangesRevisionIterator($revisions, &$dbi, $pagename)
127     {
128         $this->_revisions = $revisions;
129         $this->_wikidb = $dbi;
130         $page = $dbi->getPage($pagename);
131         $links = $page->getLinks();
132         $this->_links = array();
133         while ($linked_page = $links->next()) {
134             $this->_links[$linked_page->_pagename] = 1;
135         }
136         $links->free();
137     }
138
139     function next()
140     {
141         while (($rev = $this->_revisions->next())) {
142             if (isset($this->_links[$rev->_pagename]))
143                 return $rev;
144         }
145         $this->free();
146         return false;
147     }
148 }
149
150 // Local Variables:
151 // mode: php
152 // tab-width: 8
153 // c-basic-offset: 4
154 // c-hanging-comment-ender-p: nil
155 // indent-tabs-mode: nil
156 // End: