]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/RelatedChanges.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / RelatedChanges.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
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  * DONE: days links requires action=RelatedChanges arg
9  */
10
11 require_once("lib/plugin/RecentChanges.php");
12
13 class _RelatedChanges_HtmlFormatter
14 extends _RecentChanges_HtmlFormatter
15 {
16     function description() {
17         return HTML::p(false, $this->pre_description(),
18          fmt(" (to pages linked from \"%s\")",$this->_args['page']));
19     }
20 }
21
22
23 class WikiPlugin_RelatedChanges
24 extends WikiPlugin_RecentChanges
25 {
26     function getName () {
27         return _("RecentEdits");
28     }
29
30     function getVersion() {
31         return preg_replace("/[Revision: $]/", '',
32                             "\$Revision$");
33     }
34
35     function getDefaultArguments() {
36         //php-4.0.4pl1 breaks at the parent:: line even if the 
37         // code doesn't reach this line
38         //if (!check_php_version(4,0,6))
39         $args = WikiPlugin_RecentChanges::getDefaultArguments();
40         //else $args = parent::getDefaultArguments();
41         $args['page'] = '[pagename]';
42         $args['show_minor'] = true;
43         $args['show_all'] = true;
44         $args['caption'] = _("Related Changes");
45         return $args;
46     }
47
48     function getChanges ($dbi, $args) {
49         $changes = $dbi->mostRecent($this->getMostRecentParams($args));
50
51         $show_deleted = $args['show_deleted'];
52         if ($show_deleted == 'sometimes')
53             $show_deleted = $args['show_minor'];
54         if (!$show_deleted)
55             $changes = new NonDeletedRevisionIterator($changes, !$args['show_all']);
56
57         // sort out pages not linked from our page
58         $changes = new RelatedChangesRevisionIterator($changes, $dbi, $args['page']);
59         return $changes;
60     }
61
62     // box is used to display a fixed-width, narrow version with common header.
63     // just a numbered list of limit pagenames, without date.
64     function box($args = false, $request = false, $basepage = false) {
65         if (!$request) $request =& $GLOBALS['request'];
66         if (!isset($args['limit'])) $args['limit'] = 15;
67         $args['format'] = 'box';
68         $args['show_minor'] = false;
69         $args['show_major'] = true;
70         $args['show_deleted'] = false;
71         $args['show_all'] = false;
72         $args['days'] = 90;
73         return $this->makeBox(WikiLink(_("RelatedChanges"),'',_("Related Changes")),
74                               $this->format($this->getChanges($request->_dbi, $args), $args));
75     }
76
77     function format ($changes, $args) {
78         global $WikiTheme;
79         $format = $args['format'];
80
81         $fmt_class = $WikiTheme->getFormatter('RelatedChanges', $format);
82         if (!$fmt_class) {
83             if ($format == 'rss')
84                 $fmt_class = '_RecentChanges_RssFormatter';
85             elseif ($format == 'rss2')
86                 $fmt_class = '_RecentChanges_Rss2Formatter';
87             elseif ($format == 'rss091') {
88                 include_once "lib/RSSWriter091.php";
89                 $fmt_class = '_RecentChanges_RssFormatter091';
90             }
91             elseif ($format == 'sidebar')
92                 $fmt_class = '_RecentChanges_SideBarFormatter';
93             elseif ($format == 'box')
94                 $fmt_class = '_RecentChanges_BoxFormatter';
95             else
96                 $fmt_class = '_RelatedChanges_HtmlFormatter';
97         }
98   
99         $fmt = new $fmt_class($args);
100         return $fmt->format($changes);
101     }
102 }
103
104 /**
105  * list of pages which are linked from the current page.
106  * i.e. sort out all non-linked pages.
107  */
108 class RelatedChangesRevisionIterator extends WikiDB_PageRevisionIterator
109 {
110     function RelatedChangesRevisionIterator ($revisions, &$dbi, $pagename) {
111         $this->_revisions = $revisions;
112         $this->_wikidb = $dbi;
113         $page = $dbi->getPage($pagename);
114         $links = $page->getLinks();
115         $this->_links = array();
116         while ($linked_page = $links->next()) {
117             $this->_links[$linked_page->_pagename] = 1;
118         }
119         $links->free();
120     }
121
122     function next () {
123         while (($rev = $this->_revisions->next())) {
124             if (isset($this->_links[$rev->_pagename]))
125                 return $rev;
126         }
127         $this->free();
128         return false;
129     }
130 }
131
132 // $Log: not supported by cvs2svn $
133 // Revision 1.4  2005/01/24 23:15:27  uckelman
134 // The extra description for RelatedChanges was appearing in RecentChanges
135 // and PageHistory due to a bad test in _RecentChanges_HtmlFormatter. Fixed.
136 //
137 // Revision 1.3  2004/06/03 18:58:27  rurban
138 // days links requires action=RelatedChanges arg
139 //
140 // Revision 1.2  2004/05/08 14:06:13  rurban
141 // new support for inlined image attributes: [image.jpg size=50x30 align=right]
142 // minor stability and portability fixes
143 //
144 // Revision 1.1  2004/04/21 04:29:10  rurban
145 // Two convenient RecentChanges extensions
146 //   RelatedChanges (only links from current page)
147 //   RecentEdits (just change the default args)
148 //
149
150 // (c-file-style: "gnu")
151 // Local Variables:
152 // mode: php
153 // tab-width: 8
154 // c-basic-offset: 4
155 // c-hanging-comment-ender-p: nil
156 // indent-tabs-mode: nil
157 // End:
158 ?>