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