]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php // -*-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         return HTML::p(false, $this->pre_description(),
37          fmt(" (to pages linked from \"%s\")",$this->_args['page']));
38     }
39 }
40
41 class WikiPlugin_RelatedChanges
42 extends WikiPlugin_RecentChanges
43 {
44     function getName () {
45         return _("RecentEdits");
46     }
47
48     function getDescription () {
49         return _("List of changes on all pages which are linked to from this page.");
50     }
51
52     function getDefaultArguments() {
53         $args = parent::getDefaultArguments();
54         $args['page'] = '[pagename]';
55         $args['show_minor'] = true;
56         $args['show_all'] = true;
57         $args['caption'] = _("Related Changes");
58         return $args;
59     }
60
61     function getChanges ($dbi, $args) {
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         if (!$request) $request =& $GLOBALS['request'];
79         if (!isset($args['limit'])) $args['limit'] = 15;
80         $args['format'] = 'box';
81         $args['show_minor'] = false;
82         $args['show_major'] = true;
83         $args['show_deleted'] = false;
84         $args['show_all'] = false;
85         $args['days'] = 90;
86         return $this->makeBox(WikiLink(_("RelatedChanges"),'',_("Related Changes")),
87                               $this->format($this->getChanges($request->_dbi, $args), $args));
88     }
89
90     function format ($changes, $args) {
91         global $WikiTheme;
92         $format = $args['format'];
93
94         $fmt_class = $WikiTheme->getFormatter('RelatedChanges', $format);
95         if (!$fmt_class) {
96             if ($format == 'rss')
97                 $fmt_class = '_RecentChanges_RssFormatter';
98             elseif ($format == 'rss2')
99                 $fmt_class = '_RecentChanges_Rss2Formatter';
100             elseif ($format == 'rss091') {
101                 include_once 'lib/RSSWriter091.php';
102                 $fmt_class = '_RecentChanges_RssFormatter091';
103             }
104             elseif ($format == 'sidebar')
105                 $fmt_class = '_RecentChanges_SideBarFormatter';
106             elseif ($format == 'box')
107                 $fmt_class = '_RecentChanges_BoxFormatter';
108             else
109                 $fmt_class = '_RelatedChanges_HtmlFormatter';
110         }
111
112         $fmt = new $fmt_class($args);
113         return $fmt->format($changes);
114     }
115 }
116
117 /**
118  * list of pages which are linked from the current page.
119  * i.e. sort out all non-linked pages.
120  */
121 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
122 {
123     function RelatedChangesRevisionIterator ($revisions, &$dbi, $pagename) {
124         $this->_revisions = $revisions;
125         $this->_wikidb = $dbi;
126         $page = $dbi->getPage($pagename);
127         $links = $page->getLinks();
128         $this->_links = array();
129         while ($linked_page = $links->next()) {
130             $this->_links[$linked_page->_pagename] = 1;
131         }
132         $links->free();
133     }
134
135     function next () {
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: