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