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