]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
Normalize header
[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 require_once('lib/PageList.php');
60
61 class WikiPlugin_AuthorHistory
62 extends WikiPlugin
63 {
64     function getName() {
65         return _("AuthorHistory");
66     }
67
68     function getDescription() {
69         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."));
70     }
71
72     function getVersion() {
73         return preg_replace("/[Revision: $]/", '',
74                             "\$Revision$");
75     }
76
77     function getDefaultArguments() {
78         global $request;
79         return array('exclude'      => '',
80                      'noheader'     => false,
81                      'includeminor' => false,
82                      'includedeleted' => false,
83                      'author'       => $request->_user->UserName(),
84                      'page'         => '[pagename]',
85                      'info'         => 'version,minor,author,summary,mtime'
86                      );
87     }
88     // info arg allows multiple columns
89     // info=mtime,hits,summary,version,author,locked,minor
90     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
91
92     function run($dbi, $argstr, &$request, $basepage) {
93         $this->_args = $this->getArgs($argstr, $request);
94         extract($this->_args);
95         //trigger_error("1 p= $page a= $author");
96         if ($page && $page == 'username') //FIXME: use [username]!!!!!
97             $page = $author;
98         //trigger_error("2 p= $page a= $author");
99         if (!$page || !$author) //user not signed in or no author specified
100             return '';
101         //$pagelist = new PageList($info, $exclude);
102         ///////////////////////////
103
104         $nbsp = HTML::raw('&nbsp;');
105
106         global $WikiTheme; // date & time formatting
107
108         $table = HTML::table(array('class'=> 'pagelist'));
109         $thead = HTML::thead();
110         $tbody = HTML::tbody();
111
112         if (! ($page == 'all')) {
113             $p = $dbi->getPage($page);
114
115             $thead->pushContent(HTML::tr(HTML::th(array('align'=> 'right'),
116                                                _("Version")),
117                                       $includeminor ? HTML::th(_("Minor")) : "",
118                                       HTML::th(_("Author")),
119                                       HTML::th(_("Summary")),
120                                       HTML::th(_("Modified"))
121                                       ));
122
123             $allrevisions_iter = $p->getAllRevisions();
124             while ($rev = $allrevisions_iter->next()) {
125
126                 $isminor = $rev->get('is_minor_edit');
127                 $authordoesmatch = $author == $rev->get('author');
128
129                 if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
130                     $difflink = Button(array('action' => 'diff',
131                                              'previous' => 'minor'),
132                                        $rev->getversion(), $rev);
133                     $tr = HTML::tr(HTML::td(array('align'=> 'right'),
134                                             $difflink, $nbsp),
135                                    $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
136                                    HTML::td($nbsp, WikiLink($rev->get('author'),
137                                                             'if_known'), $nbsp),
138                                    HTML::td($nbsp, $rev->get('summary')),
139                                    HTML::td(array('align'=> 'right'),
140                                             $WikiTheme->formatdatetime($rev->get('mtime')))
141                                    );
142
143                     $class = $isminor ? 'evenrow' : 'oddrow';
144                     $tr->setAttr('class', $class);
145                     $tbody->pushContent($tr);
146                     //$pagelist->addPage($rev->getPage());
147                 }
148             }
149             $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." ,
150                            WikiLink($author, 'auto'),
151                            WikiLink($page, 'auto'));
152         }
153         else {
154
155             //search all pages for all edits by this author
156
157             $thead->pushContent(HTML::tr(HTML::th(_("Page Name")),
158                                       HTML::th(array('align'=> 'right'),
159                                                _("Version")),
160                                       $includeminor ? HTML::th(_("Minor")) : "",
161                                       HTML::th(_("Summary")),
162                                       HTML::th(_("Modified"))
163                                       ));
164
165             $allpages_iter = $dbi->getAllPages($includedeleted);
166             while ($p = $allpages_iter->next()) {
167
168                 $allrevisions_iter = $p->getAllRevisions();
169                 while ($rev = $allrevisions_iter->next()) {
170                     $isminor = $rev->get('is_minor_edit');
171                     $authordoesmatch = $author == $rev->get('author');
172                     if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
173                         $difflink = Button(array('action' => 'diff',
174                                                  'previous' => 'minor'),
175                                            $rev->getversion(), $rev);
176                         $tr = HTML::tr(
177                                        HTML::td($nbsp,
178                                                 ($isminor ? $rev->_pagename : WikiLink($rev->_pagename, 'auto'))
179                                                 ),
180                                        HTML::td(array('align'=> 'right'),
181                                                 $difflink, $nbsp),
182                                        $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
183                                        HTML::td($nbsp, $rev->get('summary')),
184                                        HTML::td(array('align'=> 'right'),
185                                                 $WikiTheme->formatdatetime($rev->get('mtime')), $nbsp)
186                                        );
187
188                         $class = $isminor ? 'evenrow' : 'oddrow';
189                         $tr->setAttr('class', $class);
190                         $tbody->pushContent($tr);
191                         //$pagelist->addPage($rev->getPage());
192                     }
193                 }
194             }
195
196             $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." ,
197                            WikiLink($author, 'auto'));
198         }
199
200         $table->pushContent(HTML::caption($captext));
201         $table->pushContent($thead, $tbody);
202
203         //        if (!$noheader) {
204         // total minor, major edits. if include minoredits was specified
205         //        }
206         return $table;
207
208         //        if (!$noheader) {
209         //            $pagelink = WikiLink($page, 'auto');
210         //
211         //            if ($pagelist->isEmpty())
212         //                return HTML::p(fmt("No pages link to %s.", $pagelink));
213         //
214         //            if ($pagelist->getTotal() == 1)
215         //                $pagelist->setCaption(fmt("One page links to %s:",
216         //                                          $pagelink));
217         //            else
218         //                $pagelist->setCaption(fmt("%s pages link to %s:",
219         //                                          $pagelist->getTotal(), $pagelink));
220         //        }
221         //
222         //        return $pagelist;
223     }
224
225 };
226
227 // For emacs users
228 // Local Variables:
229 // mode: php
230 // tab-width: 8
231 // c-basic-offset: 4
232 // c-hanging-comment-ender-p: nil
233 // indent-tabs-mode: nil
234 // End:
235 ?>