4 * Copyright (C) 2007 AVL
6 * This file is part of PhpWiki.
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.
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.
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.
24 * List all new pages per month per user.
31 class WikiPlugin_NewPagesPerUser
34 private function cmp_by_count($a, $b)
36 if ($a['count'] == $b['count']) return 0;
37 return $a['count'] < $b['count'] ? 1 : -1;
42 return _("NewPagesPerUser");
45 function getDescription()
47 return _("List all new pages per month per user.");
50 function getDefaultArguments()
52 return array('userid' => '',
62 function run($dbi, $argstr, &$request, $basepage)
65 $args = $this->getArgs($argstr, $request);
68 $since = strtotime($since);
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));
76 $iter = $dbi->getAllPages(false, '-mtime');
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";
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,
100 $pages[$monthnum]['author'][$author]['count']++;
101 $pages[$monthnum]['author'][$author]['pages'][] = $pagename;
104 $html = HTML::table(HTML::col(array('span' => 2, 'align' => 'left')));
105 $nbsp = HTML::raw(' ');
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);
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"))),
127 foreach ($authorarr['pages'] as $p)
128 $pagelist->pushContent(WikiLink($p), ', ');
130 $pagelist = join(', ', $authorarr['pages']);
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'),
149 // c-hanging-comment-ender-p: nil
150 // indent-tabs-mode: nil