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