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