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