]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
Two convenient RecentChanges extensions
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id: RelatedChanges.php,v 1.1 2004-04-21 04:29:10 rurban Exp $');
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
9 require_once("lib/plugin/RecentChanges.php");
10
11 class WikiPlugin_RelatedChanges
12 extends WikiPlugin_RecentChanges
13 {
14     function getName () {
15         return _("RecentEdits");
16     }
17
18     function getVersion() {
19         return preg_replace("/[Revision: $]/", '',
20                             "\$Revision: 1.1 $");
21     }
22
23     function getDefaultArguments() {
24         $args = parent::getDefaultArguments();
25         $args['page'] = '[pagename]';
26         $args['show_minor'] = true;
27         $args['show_all'] = true;
28         $args['caption'] = _("Related Changes");
29         return $args;
30     }
31
32     function getChanges ($dbi, $args) {
33         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
34
35         $show_deleted = $args['show_deleted'];
36         if ($show_deleted == 'sometimes')
37             $show_deleted = $args['show_minor'];
38         if (!$show_deleted)
39             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
40
41         // sort out pages not linked from our page
42         $changes = new RelatedChangesRevisionIterator($changes, $dbi, $args['page']);
43         return $changes;
44     }
45
46     // box is used to display a fixed-width, narrow version with common header.
47     // just a numbered list of limit pagenames, without date.
48     function box($args = false, $request = false, $basepage = false) {
49         if (!$request) $request =& $GLOBALS['request'];
50         if (!isset($args['limit'])) $args['limit'] = 15;
51         $args['format'] = 'box';
52         $args['show_minor'] = false;
53         $args['show_major'] = true;
54         $args['show_deleted'] = false;
55         $args['show_all'] = false;
56         $args['days'] = 90;
57         return $this->makeBox(WikiLink(_("RelatedChanges"),'',_("Related Changes")),
58                               $this->format($this->getChanges($request->_dbi, $args), $args));
59     }
60 }
61
62 /**
63  * list of pages which are linked from the current page.
64  * i.e. sort out all non-linked pages.
65  */
66 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
67 {
68     function RelatedChangesRevisionIterator ($revisions, &$dbi, $pagename) {
69         $this->_revisions = $revisions;
70         $this->_wikidb = $dbi;
71         $page = $dbi->getPage($pagename);
72         $links = $page->getLinks();
73         $this->_links = array();
74         while ($linked_page = $links->next()) {
75             $this->_links[$linked_page->_pagename] = 1;
76         }
77         $links->free();
78     }
79
80     function next () {
81         while (($rev = $this->_revisions->next())) {
82             if (isset($this->_links[$rev->_pagename]))
83                 return $rev;
84         }
85         $this->free();
86         return false;
87     }
88 }
89
90 // $Log: not supported by cvs2svn $
91
92 // (c-file-style: "gnu")
93 // Local Variables:
94 // mode: php
95 // tab-width: 8
96 // c-basic-offset: 4
97 // c-hanging-comment-ender-p: nil
98 // indent-tabs-mode: nil
99 // End:
100 ?>