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