]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
extra_empty_lines
[SourceForge/phpwiki.git] / lib / plugin / AuthorHistory.php
1 <?php // -*-php-*-
2 // $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 along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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  try this in a subpage of your UserName: (UserName/AuthorHistory)
36
37 <?plugin AuthorHistory page=all includeminor=true ?>
38
39 * Displays a list of revision edits by one particular user, for the
40 * current page, a specified page, or all pages.
41
42 * This is a big hack to create a PageList like table. (PageList
43 * doesn't support page revisions yet, only pages.)
44
45 * Make a new subclass of PageHistory to filter changes of one (or all)
46 * page(s) by a single author?
47
48 */
49
50 /*
51  reference
52  _PageHistory_PageRevisionIter
53  WikiDB_PageIterator(&$wikidb, &$pages
54  WikiDB_PageRevisionIterator(&$wikidb, &$revisions)
55 */
56
57 require_once('lib/PageList.php');
58
59 class WikiPlugin_AuthorHistory
60 extends WikiPlugin
61 {
62     function getName() {
63         return _("AuthorHistory");
64     }
65
66     function getDescription() {
67         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."));
68     }
69
70     function getDefaultArguments() {
71         global $request;
72         return array('exclude'      => '',
73                      'noheader'     => false,
74                      'includeminor' => false,
75                      'includedeleted' => false,
76                      'author'       => $request->_user->UserName(),
77                      'page'         => '[pagename]',
78                      'info'         => 'version,minor,author,summary,mtime'
79                      );
80     }
81     // info arg allows multiple columns
82     // info=mtime,hits,summary,version,author,locked,minor
83     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
84
85     function run($dbi, $argstr, &$request, $basepage) {
86         $this->_args = $this->getArgs($argstr, $request);
87         extract($this->_args);
88         //trigger_error("1 p= $page a= $author");
89         if ($page && $page == 'username') //FIXME: use [username]!!!!!
90             $page = $author;
91         //trigger_error("2 p= $page a= $author");
92         if (!$page || !$author) //user not signed in or no author specified
93             return '';
94         //$pagelist = new PageList($info, $exclude);
95         ///////////////////////////
96
97         $nbsp = HTML::raw('&nbsp;');
98
99         global $WikiTheme; // date & time formatting
100
101         $table = HTML::table(array('class'=> 'pagelist'));
102         $thead = HTML::thead();
103         $tbody = HTML::tbody();
104
105         if (! ($page == 'all')) {
106             $p = $dbi->getPage($page);
107
108             $thead->pushContent(HTML::tr(HTML::th(array('align'=> 'right'),
109                                                _("Version")),
110                                       $includeminor ? HTML::th(_("Minor")) : "",
111                                       HTML::th(_("Author")),
112                                       HTML::th(_("Summary")),
113                                       HTML::th(_("Modified"))
114                                       ));
115
116             $allrevisions_iter = $p->getAllRevisions();
117             while ($rev = $allrevisions_iter->next()) {
118
119                 $isminor = $rev->get('is_minor_edit');
120                 $authordoesmatch = $author == $rev->get('author');
121
122                 if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
123                     $difflink = Button(array('action' => 'diff',
124                                              'previous' => 'minor'),
125                                        $rev->getversion(), $rev);
126                     $tr = HTML::tr(HTML::td(array('align'=> 'right'),
127                                             $difflink, $nbsp),
128                                    $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
129                                    HTML::td($nbsp, WikiLink($rev->get('author'),
130                                                             'if_known'), $nbsp),
131                                    HTML::td($nbsp, $rev->get('summary')),
132                                    HTML::td(array('align'=> 'right'),
133                                             $WikiTheme->formatdatetime($rev->get('mtime')))
134                                    );
135
136                     $class = $isminor ? 'evenrow' : 'oddrow';
137                     $tr->setAttr('class', $class);
138                     $tbody->pushContent($tr);
139                     //$pagelist->addPage($rev->getPage());
140                 }
141             }
142             $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." ,
143                            WikiLink($author, 'auto'),
144                            WikiLink($page, 'auto'));
145         }
146         else {
147
148             //search all pages for all edits by this author
149
150             $thead->pushContent(HTML::tr(HTML::th(_("Page Name")),
151                                       HTML::th(array('align'=> 'right'),
152                                                _("Version")),
153                                       $includeminor ? HTML::th(_("Minor")) : "",
154                                       HTML::th(_("Summary")),
155                                       HTML::th(_("Modified"))
156                                       ));
157
158             $allpages_iter = $dbi->getAllPages($includedeleted);
159             while ($p = $allpages_iter->next()) {
160
161                 $allrevisions_iter = $p->getAllRevisions();
162                 while ($rev = $allrevisions_iter->next()) {
163                     $isminor = $rev->get('is_minor_edit');
164                     $authordoesmatch = $author == $rev->get('author');
165                     if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
166                         $difflink = Button(array('action' => 'diff',
167                                                  'previous' => 'minor'),
168                                            $rev->getversion(), $rev);
169                         $tr = HTML::tr(
170                                        HTML::td($nbsp,
171                                                 ($isminor ? $rev->_pagename : WikiLink($rev->_pagename, 'auto'))
172                                                 ),
173                                        HTML::td(array('align'=> 'right'),
174                                                 $difflink, $nbsp),
175                                        $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
176                                        HTML::td($nbsp, $rev->get('summary')),
177                                        HTML::td(array('align'=> 'right'),
178                                                 $WikiTheme->formatdatetime($rev->get('mtime')), $nbsp)
179                                        );
180
181                         $class = $isminor ? 'evenrow' : 'oddrow';
182                         $tr->setAttr('class', $class);
183                         $tbody->pushContent($tr);
184                         //$pagelist->addPage($rev->getPage());
185                     }
186                 }
187             }
188
189             $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." ,
190                            WikiLink($author, 'auto'));
191         }
192
193         $table->pushContent(HTML::caption($captext));
194         $table->pushContent($thead, $tbody);
195
196         //        if (!$noheader) {
197         // total minor, major edits. if include minoredits was specified
198         //        }
199         return $table;
200
201         //        if (!$noheader) {
202         //            $pagelink = WikiLink($page, 'auto');
203         //
204         //            if ($pagelist->isEmpty())
205         //                return HTML::p(fmt("No pages link to %s.", $pagelink));
206         //
207         //            if ($pagelist->getTotal() == 1)
208         //                $pagelist->setCaption(fmt("One page links to %s:",
209         //                                          $pagelink));
210         //            else
211         //                $pagelist->setCaption(fmt("%s pages link to %s:",
212         //                                          $pagelist->getTotal(), $pagelink));
213         //        }
214         //
215         //        return $pagelist;
216     }
217
218 };
219
220 // Local Variables:
221 // mode: php
222 // tab-width: 8
223 // c-basic-offset: 4
224 // c-hanging-comment-ender-p: nil
225 // indent-tabs-mode: nil
226 // End:
227 ?>