]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/NewPagesPerUser.php
Always return something
[SourceForge/phpwiki.git] / lib / plugin / NewPagesPerUser.php
1 <?php
2
3 /*
4  * Copyright (C) 2007 AVL
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  * List all new pages per month per user.
25  * March 2007
26  *   BERTUZZI 20
27  *   URBANR   15
28  *   ...
29  */
30
31 class WikiPlugin_NewPagesPerUser
32     extends WikiPlugin
33 {
34     function getName()
35     {
36         return _("NewPagesPerUser");
37     }
38
39     function getDescription()
40     {
41         return _("List all new pages per month per user");
42     }
43
44     function getDefaultArguments()
45     {
46         return array('userid' => '',
47             'month' => 0,
48             'since' => 0,
49             'until' => 0,
50             'comments' => 0,
51             'links' => 1,
52             'debug' => 0,
53         );
54     }
55
56     function run($dbi, $argstr, &$request, $basepage)
57     {
58         global $WikiTheme;
59         $args = $this->getArgs($argstr, $request);
60         extract($args);
61         if ($since)
62             $since = strtotime($since);
63         if ($month) {
64             $since = strtotime($month);
65             $since = mktime(0, 0, 0, date("m", $since), 1, date("Y", $since));
66             $until = mktime(23, 59, 59, date("m", $since) + 1, 0, date("Y", $since));
67         } else
68             $until = 0;
69
70         $iter = $dbi->getAllPages(false, '-mtime');
71         $pages = array();
72
73         while ($page = $iter->next()) {
74             $pagename = $page->getName();
75             if (!$page->exists()) continue;
76             $rev = $page->getRevision(1, false);
77             $date = $rev->get('mtime');
78             //$author = $rev->get('author_id');
79             $author = $page->getOwner();
80             if (defined('DEBUG') && DEBUG && $debug) {
81                 echo "<i>$pagename, ", strftime("%Y-%m-%d %h:%m:%s", $date), ", $author</i><br />\n";
82             }
83             if ($userid and (!preg_match("/" . $userid . "/", $author))) continue;
84             if ($since and $date < $since) continue;
85             if ($until and $date > $until) continue;
86             if (!$comments and preg_match("/\/Comment/", $pagename)) continue;
87             $monthnum = strftime("%Y%m", $date);
88             if (!isset($pages[$monthnum]))
89                 $pages[$monthnum] = array('author' => array(),
90                     'month' => strftime("%B, %Y", $date));
91             if (!isset($pages[$monthnum]['author'][$author]))
92                 $pages[$monthnum]['author'][$author] = array('count' => 0,
93                     'pages' => array());
94             $pages[$monthnum]['author'][$author]['count']++;
95             $pages[$monthnum]['author'][$author]['pages'][] = $pagename;
96         }
97         $iter->free();
98         $html = HTML::table(HTML::col(array('span' => 2, 'align' => 'left')));
99         $nbsp = HTML::raw('&nbsp;');
100         krsort($pages);
101         foreach ($pages as $monthname => $parr) {
102             $html->pushContent(HTML::tr(HTML::td(array('colspan' => 2),
103                 HTML::strong($parr['month']))));
104             uasort($parr['author'], 'cmp_by_count');
105             foreach ($parr['author'] as $user => $authorarr) {
106                 $count = $authorarr['count'];
107                 $id = preg_replace("/ /", "_", 'pages-' . $monthname . '-' . $user);
108                 $html->pushContent
109                 (HTML::tr(HTML::td($nbsp, $nbsp,
110                         HTML::img(array('id' => "$id-img",
111                             'src' => $WikiTheme->_findData("images/folderArrowClosed.png"),
112                             'onclick' => "showHideFolder('$id')",
113                             'alt' => _("Click to hide/show"),
114                             'title' => _("Click to hide/show"))),
115                         $nbsp,
116                         $user),
117                     HTML::td($count)
118                 ));
119                 if ($links) {
120                     $pagelist = HTML();
121                     foreach ($authorarr['pages'] as $p)
122                         $pagelist->pushContent(WikiLink($p), ', ');
123                 } else {
124                     $pagelist = join(', ', $authorarr['pages']);
125                 }
126                 $html->pushContent
127                 (HTML::tr(array('id' => $id . '-body',
128                         'style' => 'display:none; background-color: #eee;'),
129                     HTML::td(array('colspan' => 2,
130                             'style' => 'font-size:smaller'),
131                         $pagelist
132                     )));
133             }
134         }
135         return $html;
136     }
137 }
138
139 // Local Variables:
140 // mode: php
141 // tab-width: 8
142 // c-basic-offset: 4
143 // c-hanging-comment-ender-p: nil
144 // indent-tabs-mode: nil
145 // End: