]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
getName should not translate
[SourceForge/phpwiki.git] / lib / plugin / AuthorHistory.php
1 <?php
2
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 * Display 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 getDescription()
63     {
64         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."));
65     }
66
67     function getDefaultArguments()
68     {
69         global $request;
70         return array('exclude' => '',
71             'noheader' => false,
72             'includeminor' => false,
73             'includedeleted' => false,
74             'author' => $request->_user->UserName(),
75             'page' => '[pagename]',
76             'info' => 'version,minor,author,summary,mtime'
77         );
78     }
79
80     // info arg allows multiple columns
81     // info=mtime,hits,summary,version,author,locked,minor
82     // exclude arg allows multiple pagenames exclude=HomePage,RecentChanges
83
84     function run($dbi, $argstr, &$request, $basepage)
85     {
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         } else {
146
147             //search all pages for all edits by this author
148
149             $thead->pushContent(HTML::tr(HTML::th(_("Page Name")),
150                 HTML::th(array('align' => 'right'),
151                     _("Version")),
152                 $includeminor ? HTML::th(_("Minor")) : "",
153                 HTML::th(_("Summary")),
154                 HTML::th(_("Modified"))
155             ));
156
157             $allpages_iter = $dbi->getAllPages($includedeleted);
158             while ($p = $allpages_iter->next()) {
159
160                 $allrevisions_iter = $p->getAllRevisions();
161                 while ($rev = $allrevisions_iter->next()) {
162                     $isminor = $rev->get('is_minor_edit');
163                     $authordoesmatch = $author == $rev->get('author');
164                     if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
165                         $difflink = Button(array('action' => 'diff',
166                                 'previous' => 'minor'),
167                             $rev->getversion(), $rev);
168                         $tr = HTML::tr(
169                             HTML::td($nbsp,
170                                 ($isminor ? $rev->_pagename : WikiLink($rev->_pagename, 'auto'))
171                             ),
172                             HTML::td(array('align' => 'right'),
173                                 $difflink, $nbsp),
174                             $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
175                             HTML::td($nbsp, $rev->get('summary')),
176                             HTML::td(array('align' => 'right'),
177                                 $WikiTheme->formatdatetime($rev->get('mtime')), $nbsp)
178                         );
179
180                         $class = $isminor ? 'evenrow' : 'oddrow';
181                         $tr->setAttr('class', $class);
182                         $tbody->pushContent($tr);
183                         //$pagelist->addPage($rev->getPage());
184                     }
185                 }
186             }
187
188             $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.",
189                 WikiLink($author, 'auto'));
190         }
191
192         $table->pushContent(HTML::caption($captext));
193         $table->pushContent($thead, $tbody);
194
195         //        if (!$noheader) {
196         // total minor, major edits. if include minoredits was specified
197         //        }
198         return $table;
199
200         //        if (!$noheader) {
201         //            $pagelink = WikiLink($page, 'auto');
202         //
203         //            if ($pagelist->isEmpty())
204         //                return HTML::p(fmt("No pages link to %s.", $pagelink));
205         //
206         //            if ($pagelist->getTotal() == 1)
207         //                $pagelist->setCaption(fmt("One page links to %s:",
208         //                                          $pagelink));
209         //            else
210         //                $pagelist->setCaption(fmt("%s pages link to %s:",
211         //                                          $pagelist->getTotal(), $pagelink));
212         //        }
213         //
214         //        return $pagelist;
215     }
216
217 }
218
219 // Local Variables:
220 // mode: php
221 // tab-width: 8
222 // c-basic-offset: 4
223 // c-hanging-comment-ender-p: nil
224 // indent-tabs-mode: nil
225 // End: