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