]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
font-size:smaller moved to CSS
[SourceForge/phpwiki.git] / lib / plugin / AuthorHistory.php
1 <?php // -*-php-*-
2 rcs_id('$Id$');
3 /**
4  Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
5  Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
6
7  This file is part of PhpWiki.
8
9  PhpWiki is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13
14  PhpWiki is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with PhpWiki; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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             $th = HTML::thead();
118             $tb = HTML::tbody();
119
120             $th->pushContent(HTML::tr(HTML::td(array('align'=> 'right'),
121                                                _("Version")),
122                                       $includeminor ? HTML::td(_("Minor")) : "",
123                                       HTML::td(_("Author")),
124                                       HTML::td(_("Summary")),
125                                       HTML::td(_("Modified"))
126                                       ));
127
128             $allrevisions_iter = $p->getAllRevisions();
129             while ($rev = $allrevisions_iter->next()) {
130
131                 $isminor = $rev->get('is_minor_edit');
132                 $authordoesmatch = $author == $rev->get('author');
133
134                 if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
135                     $difflink = Button(array('action' => 'diff',
136                                              'previous' => 'minor'),
137                                        $rev->getversion(), $rev);
138                     $tr = HTML::tr(HTML::td(array('align'=> 'right'),
139                                             $difflink, $nbsp),
140                                    $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
141                                    HTML::td($nbsp, WikiLink($rev->get('author'),
142                                                             'if_known'), $nbsp),
143                                    HTML::td($nbsp, $rev->get('summary')),
144                                    HTML::td(array('align'=> 'right'),
145                                             $WikiTheme->formatdatetime($rev->get('mtime')))
146                                    );
147
148                     $class = $isminor ? 'evenrow' : 'oddrow';
149                     $tr->setAttr('class', $class);
150                     $tb->pushContent($tr);
151                     //$pagelist->addPage($rev->getPage());
152                 }
153             }
154             $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." ,
155                            WikiLink($author, 'auto'),
156                            WikiLink($page, 'auto'));
157             $t->pushContent(HTML::caption($captext));
158             $t->pushContent($th, $tb);
159         }
160         else {
161
162             //search all pages for all edits by this author
163
164             /////////////////////////////////////////////////////////////
165
166             $t = HTML::table(array('class'=> 'pagelist'));
167             $th = HTML::thead();
168             $tb = HTML::tbody();
169
170             $th->pushContent(HTML::tr(HTML::td(_("Page Name")),
171                                       HTML::td(array('align'=> 'right'),
172                                                _("Version")),
173                                       $includeminor ? HTML::td(_("Minor")) : "",
174                                       HTML::td(_("Summary")),
175                                       HTML::td(_("Modified"))
176                                       ));
177             /////////////////////////////////////////////////////////////
178
179             $allpages_iter = $dbi->getAllPages($includedeleted);
180             while ($p = $allpages_iter->next()) {
181                 /////////////////////////////////////////////////////////////
182
183                 $allrevisions_iter = $p->getAllRevisions();
184                 while ($rev = $allrevisions_iter->next()) {
185                     $isminor = $rev->get('is_minor_edit');
186                     $authordoesmatch = $author == $rev->get('author');
187                     if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
188                         $difflink = Button(array('action' => 'diff',
189                                                  'previous' => 'minor'),
190                                            $rev->getversion(), $rev);
191                         $tr = HTML::tr(
192                                        HTML::td($nbsp,
193                                                 ($isminor ? $rev->_pagename : WikiLink($rev->_pagename, 'auto'))
194                                                 ),
195                                        HTML::td(array('align'=> 'right'),
196                                                 $difflink, $nbsp),
197                                        $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
198                                        HTML::td($nbsp, $rev->get('summary')),
199                                        HTML::td(array('align'=> 'right'),
200                                                 $WikiTheme->formatdatetime($rev->get('mtime')), $nbsp)
201                                        );
202
203                         $class = $isminor ? 'evenrow' : 'oddrow';
204                         $tr->setAttr('class', $class);
205                         $tb->pushContent($tr);
206                         //$pagelist->addPage($rev->getPage());
207                     }
208                 }
209
210                 /////////////////////////////////////////////////////////////
211
212             }
213
214             $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." ,
215                            WikiLink($author, 'auto'));
216             $t->pushContent(HTML::caption($captext));
217             $t->pushContent($th, $tb);
218         }
219
220         //        if (!$noheader) {
221         // total minor, major edits. if include minoredits was specified
222         //        }
223         return $t;
224
225         //        if (!$noheader) {
226         //            $pagelink = WikiLink($page, 'auto');
227         //
228         //            if ($pagelist->isEmpty())
229         //                return HTML::p(fmt("No pages link to %s.", $pagelink));
230         //
231         //            if ($pagelist->getTotal() == 1)
232         //                $pagelist->setCaption(fmt("One page links to %s:",
233         //                                          $pagelink));
234         //            else
235         //                $pagelist->setCaption(fmt("%s pages link to %s:",
236         //                                          $pagelist->getTotal(), $pagelink));
237         //        }
238         //
239         //        return $pagelist;
240     }
241
242 };
243
244 // For emacs users
245 // Local Variables:
246 // mode: php
247 // tab-width: 8
248 // c-basic-offset: 4
249 // c-hanging-comment-ender-p: nil
250 // indent-tabs-mode: nil
251 // End:
252 ?>