]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
Activated Revision substitution for Subversion
[SourceForge/phpwiki.git] / lib / plugin / AuthorHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $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
19  along with PhpWiki; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22
23
24 /*
25  *** EXPERIMENTAL PLUGIN ******************
26  Needs a lot of work! Use at your own risk.
27  ****************************************** 
28    
29  try this in a page called AuthorHistory:
30     
31 <?plugin AuthorHistory page=username includeminor=true ?>
32 ----
33 <?plugin AuthorHistory page=all ?>
34
35
36  try this in a subpage of your UserName: (UserName/AuthorHistory)
37
38 <?plugin AuthorHistory page=all includeminor=true ?>
39     
40
41 * Displays a list of revision edits by one particular user, for the
42 * current page, a specified page, or all pages.
43
44 * This is a big hack to create a PageList like table. (PageList
45 * doesn't support page revisions yet, only pages.)
46
47 * Make a new subclass of PageHistory to filter changes of one (or all)
48 * page(s) by a single author?
49
50 */
51
52 /*
53  reference
54  _PageHistory_PageRevisionIter
55  WikiDB_PageIterator(&$wikidb, &$pages
56  WikiDB_PageRevisionIterator(&$wikidb, &$revisions)
57 */
58
59
60 /**
61  */
62 require_once('lib/PageList.php');
63
64 //include_once('lib/debug.php');
65
66 class WikiPlugin_AuthorHistory
67 extends WikiPlugin
68 {
69     function getName() {
70         return _("AuthorHistory");
71     }
72
73     function getDescription() {
74         return sprintf(_("List all page revisions edited by one user with diff links, or show a PageHistory-like list of a single page for only one user."));
75     }
76     
77     function getVersion() {
78         return preg_replace("/[Revision: $]/", '',
79                             "\$Revision$");
80     }
81     
82     function getDefaultArguments() {
83         global $request;
84         return array('exclude'      => '',
85                      'noheader'     => false,
86                      'includeminor' => false,
87                      'includedeleted' => false,
88                      'author'       => $request->_user->UserName(),
89                      'page'         => '[pagename]',
90                      'info'         => 'version,minor,author,summary,mtime'
91                      );
92     }
93     // info arg allows multiple columns
94     // info=mtime,hits,summary,version,author,locked,minor
95     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
96     
97     function run($dbi, $argstr, &$request, $basepage) {
98         $this->_args = $this->getArgs($argstr, $request);
99         extract($this->_args);
100         //trigger_error("1 p= $page a= $author");
101         if ($page && $page == 'username') //FIXME: use [username]!!!!!
102             $page = $author;
103         //trigger_error("2 p= $page a= $author");
104         if (!$page || !$author) //user not signed in or no author specified
105             return '';
106         //$pagelist = new PageList($info, $exclude);
107         ///////////////////////////
108         
109         $nbsp = HTML::raw('&nbsp;');
110         
111         global $WikiTheme; // date & time formatting
112         
113         if (! ($page == 'all')) {
114             $p = $dbi->getPage($page);
115             
116             $t = HTML::table(array('class'=> 'pagelist',
117                                    'style' => 'font-size:smaller'));
118             $th = HTML::thead();
119             $tb = HTML::tbody();
120             
121             
122             $th->pushContent(HTML::tr(HTML::td(array('align'=> 'right'),
123                                                _("Version")),
124                                       $includeminor ? HTML::td(_("Minor")) : "",
125                                       HTML::td(_("Author")),
126                                       HTML::td(_("Summary")),
127                                       HTML::td(_("Modified"))
128                                       ));
129             
130             $allrevisions_iter = $p->getAllRevisions();
131             while ($rev = $allrevisions_iter->next()) {
132                 
133                 $isminor = $rev->get('is_minor_edit');
134                 $authordoesmatch = $author == $rev->get('author');
135                 
136                 if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
137                     $difflink = Button(array('action' => 'diff',
138                                              'previous' => 'minor'),
139                                        $rev->getversion(), $rev);
140                     $tr = HTML::tr(HTML::td(array('align'=> 'right'),
141                                             $difflink, $nbsp),
142                                    $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
143                                    HTML::td($nbsp, WikiLink($rev->get('author'),
144                                                             'if_known'), $nbsp),
145                                    HTML::td($nbsp, $rev->get('summary')),
146                                    HTML::td(array('align'=> 'right'),
147                                             $WikiTheme->formatdatetime($rev->get('mtime')))
148                                    );
149                     
150                     $class = $isminor ? 'evenrow' : 'oddrow';
151                     $tr->setAttr('class', $class);
152                     $tb->pushContent($tr);
153                     //$pagelist->addPage($rev->getPage());
154                 }
155             }
156             $captext = fmt($includeminor ? "History of all major and minor edits by %s to page %s."  : "History of all major edits by %s to page %s." ,
157                            WikiLink($author, 'auto'),
158                            WikiLink($page, 'auto'));
159             $t->pushContent(HTML::caption($captext));
160             $t->pushContent($th, $tb);
161         }
162         else {
163             
164             //search all pages for all edits by this author
165             
166             /////////////////////////////////////////////////////////////
167             
168             $t = HTML::table(array('class'=> 'pagelist',
169                                    'style' => 'font-size:smaller'));
170             $th = HTML::thead();
171             $tb = HTML::tbody();
172             
173             
174             $th->pushContent(HTML::tr(HTML::td(_("Page Name")),
175                                       HTML::td(array('align'=> 'right'),
176                                                _("Version")),
177                                       $includeminor ? HTML::td(_("Minor")) : "",
178                                       HTML::td(_("Summary")),
179                                       HTML::td(_("Modified"))
180                                       ));
181             /////////////////////////////////////////////////////////////
182             
183             $allpages_iter = $dbi->getAllPages($includedeleted);
184             while ($p = $allpages_iter->next()) {
185                 /////////////////////////////////////////////////////////////
186                 
187                 $allrevisions_iter = $p->getAllRevisions();
188                 while ($rev = $allrevisions_iter->next()) {
189                     $isminor = $rev->get('is_minor_edit');
190                     $authordoesmatch = $author == $rev->get('author');
191                     if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
192                         $difflink = Button(array('action' => 'diff',
193                                                  'previous' => 'minor'),
194                                            $rev->getversion(), $rev);
195                         $tr = HTML::tr(
196                                        HTML::td($nbsp,
197                                                 ($isminor ? $rev->_pagename : WikiLink($rev->_pagename, 'auto'))
198                                                 ),
199                                        HTML::td(array('align'=> 'right'),
200                                                 $difflink, $nbsp),
201                                        $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
202                                        HTML::td($nbsp, $rev->get('summary')),
203                                        HTML::td(array('align'=> 'right'),
204                                                 $WikiTheme->formatdatetime($rev->get('mtime')), $nbsp)
205                                        );
206                         
207                         $class = $isminor ? 'evenrow' : 'oddrow';
208                         $tr->setAttr('class', $class);
209                         $tb->pushContent($tr);
210                         //$pagelist->addPage($rev->getPage());
211                     }
212                 }
213                 
214                 /////////////////////////////////////////////////////////////
215                 
216             }
217             
218             $captext = fmt($includeminor ? "History of all major and minor modifications for any page edited by %s."  : "History of major modifications for any page edited by %s." ,
219                            WikiLink($author, 'auto'));
220             $t->pushContent(HTML::caption($captext));
221             $t->pushContent($th, $tb);
222         }
223         
224         //        if (!$noheader) {
225         // total minor, major edits. if include minoredits was specified
226         //        }
227         return $t;
228         
229         //        if (!$noheader) {
230         //            $pagelink = WikiLink($page, 'auto');
231         //
232         //            if ($pagelist->isEmpty())
233         //                return HTML::p(fmt("No pages link to %s.", $pagelink));
234         //
235         //            if ($pagelist->getTotal() == 1)
236         //                $pagelist->setCaption(fmt("One page links to %s:",
237         //                                          $pagelink));
238         //            else
239         //                $pagelist->setCaption(fmt("%s pages link to %s:",
240         //                                          $pagelist->getTotal(), $pagelink));
241         //        }
242         //
243         //        return $pagelist;
244     }
245     
246 };
247
248 // $Log: not supported by cvs2svn $
249 // Revision 1.5  2004/02/28 21:14:08  rurban
250 // generally more PHPDOC docs
251 //   see http://xarch.tu-graz.ac.at/home/rurban/phpwiki/xref/
252 // fxied WikiUserNew pref handling: empty theme not stored, save only
253 //   changed prefs, sql prefs improved, fixed password update,
254 //   removed REPLACE sql (dangerous)
255 // moved gettext init after the locale was guessed
256 // + some minor changes
257 //
258 // Revision 1.4  2004/02/17 12:11:36  rurban
259 // added missing 4th basepage arg at plugin->run() to almost all plugins. This caused no harm so far, because it was silently dropped on normal usage. However on plugin internal ->run invocations it failed. (InterWikiSearch, IncludeSiteMap, ...)
260 //
261 // Revision 1.3  2004/01/26 09:18:00  rurban
262 // * changed stored pref representation as before.
263 //   the array of objects is 1) bigger and 2)
264 //   less portable. If we would import packed pref
265 //   objects and the object definition was changed, PHP would fail.
266 //   This doesn't happen with an simple array of non-default values.
267 // * use $prefs->retrieve and $prefs->store methods, where retrieve
268 //   understands the interim format of array of objects also.
269 // * simplified $prefs->get() and fixed $prefs->set()
270 // * added $user->_userid and class '_WikiUser' portability functions
271 // * fixed $user object ->_level upgrading, mostly using sessions.
272 //   this fixes yesterdays problems with loosing authorization level.
273 // * fixed WikiUserNew::checkPass to return the _level
274 // * fixed WikiUserNew::isSignedIn
275 // * added explodePageList to class PageList, support sortby arg
276 // * fixed UserPreferences for WikiUserNew
277 // * fixed WikiPlugin for empty defaults array
278 // * UnfoldSubpages: added pagename arg, renamed pages arg,
279 //   removed sort arg, support sortby arg
280 //
281 // Revision 1.2  2003/12/08 22:44:58  carstenklapp
282 // Code cleanup: fixed rcsid
283 //
284 // Revision 1.1  2003/12/08 22:43:30  carstenklapp
285 // New experimental plugin to provide a different kind of
286 // PageHistory. Functional as-is, but is in need of much cleanup and
287 // refactoring. Probably very, very slow on wikis with many pages!
288 //
289
290 // For emacs users
291 // Local Variables:
292 // mode: php
293 // tab-width: 8
294 // c-basic-offset: 4
295 // c-hanging-comment-ender-p: nil
296 // indent-tabs-mode: nil
297 // End:
298 ?>