]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/AuthorHistory.php
include [all] Include and file path should be devided with single space. File path...
[SourceForge/phpwiki.git] / lib / plugin / AuthorHistory.php
1 <?php // -*-php-*-
2 /**
3  * Copyright 1999, 2000, 2001, 2002 $ThePhpWikiProgrammingTeam
4  * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
5  *
6  * This file is part of PhpWiki.
7  *
8  * PhpWiki is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * PhpWiki is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 /*
24  *** EXPERIMENTAL PLUGIN ******************
25  Needs a lot of work! Use at your own risk.
26  ******************************************
27
28  try this in a page called AuthorHistory:
29
30 <?plugin AuthorHistory page=username includeminor=true ?>
31 ----
32 <?plugin AuthorHistory page=all ?>
33
34  try this in a subpage of your UserName: (UserName/AuthorHistory)
35
36 <?plugin AuthorHistory page=all includeminor=true ?>
37
38 * Displays a list of revision edits by one particular user, for the
39 * current page, a specified page, or all pages.
40
41 * This is a big hack to create a PageList like table. (PageList
42 * doesn't support page revisions yet, only pages.)
43
44 * Make a new subclass of PageHistory to filter changes of one (or all)
45 * page(s) by a single author?
46
47 */
48
49 /*
50  reference
51  _PageHistory_PageRevisionIter
52  WikiDB_PageIterator(&$wikidb, &$pages
53  WikiDB_PageRevisionIterator(&$wikidb, &$revisions)
54 */
55
56 require_once 'lib/PageList.php';
57
58 class WikiPlugin_AuthorHistory
59 extends WikiPlugin
60 {
61     function getName() {
62         return _("AuthorHistory");
63     }
64
65     function getDescription() {
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         global $request;
71         return array('exclude'      => '',
72                      'noheader'     => false,
73                      'includeminor' => false,
74                      'includedeleted' => false,
75                      'author'       => $request->_user->UserName(),
76                      'page'         => '[pagename]',
77                      'info'         => 'version,minor,author,summary,mtime'
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         $this->_args = $this->getArgs($argstr, $request);
86         extract($this->_args);
87         //trigger_error("1 p= $page a= $author");
88         if ($page && $page == 'username') //FIXME: use [username]!!!!!
89             $page = $author;
90         //trigger_error("2 p= $page a= $author");
91         if (!$page || !$author) //user not signed in or no author specified
92             return '';
93         //$pagelist = new PageList($info, $exclude);
94         ///////////////////////////
95
96         $nbsp = HTML::raw('&nbsp;');
97
98         global $WikiTheme; // date & time formatting
99
100         $table = HTML::table(array('class'=> 'pagelist'));
101         $thead = HTML::thead();
102         $tbody = HTML::tbody();
103
104         if (! ($page == 'all')) {
105             $p = $dbi->getPage($page);
106
107             $thead->pushContent(HTML::tr(HTML::th(array('align'=> 'right'),
108                                                _("Version")),
109                                       $includeminor ? HTML::th(_("Minor")) : "",
110                                       HTML::th(_("Author")),
111                                       HTML::th(_("Summary")),
112                                       HTML::th(_("Modified"))
113                                       ));
114
115             $allrevisions_iter = $p->getAllRevisions();
116             while ($rev = $allrevisions_iter->next()) {
117
118                 $isminor = $rev->get('is_minor_edit');
119                 $authordoesmatch = $author == $rev->get('author');
120
121                 if ($authordoesmatch && (!$isminor || ($includeminor && $isminor))) {
122                     $difflink = Button(array('action' => 'diff',
123                                              'previous' => 'minor'),
124                                        $rev->getversion(), $rev);
125                     $tr = HTML::tr(HTML::td(array('align'=> 'right'),
126                                             $difflink, $nbsp),
127                                    $includeminor ? (HTML::td($nbsp, ($isminor ? "minor" : "major"), $nbsp)) : "",
128                                    HTML::td($nbsp, WikiLink($rev->get('author'),
129                                                             'if_known'), $nbsp),
130                                    HTML::td($nbsp, $rev->get('summary')),
131                                    HTML::td(array('align'=> 'right'),
132                                             $WikiTheme->formatdatetime($rev->get('mtime')))
133                                    );
134
135                     $class = $isminor ? 'evenrow' : 'oddrow';
136                     $tr->setAttr('class', $class);
137                     $tbody->pushContent($tr);
138                     //$pagelist->addPage($rev->getPage());
139                 }
140             }
141             $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." ,
142                            WikiLink($author, 'auto'),
143                            WikiLink($page, 'auto'));
144         }
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: