r41537 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r41536‎ | r41537 | r41538 >
Date:13:39, 2 October 2008
Author:gri6507
Status:old
Tags:
Comment:
v1.10 - corrected a number of warnings tha arize when executing by a user who does not have any edits themselves. Cleaned up the reported HTML errors
Modified paths:
  • /trunk/extensions/UsageStatistics/SpecialUserStats.php (modified) (history)
  • /trunk/extensions/UsageStatistics/SpecialUserStats_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsageStatistics/SpecialUserStats_body.php
@@ -76,10 +76,12 @@
7777 $csv = 'Username,';
7878 $cur_t = $start_t;
7979 while ($cur_t <= $end_t) {
80 - $dates[date("Ymd", $cur_t).'000000'] = array();
 80+ $a_date = date("Ymd", $cur_t) . '000000';
 81+ $dates[$a_date] = array();
8182 $cur_t += $interval;
8283 }
8384
 85+ # Let's process the edits that are recorded in the database
8486 $u = array();
8587 $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " .
8688 $db->tableName('page') . "," . $db->tableName('revision') .
@@ -93,11 +95,18 @@
9496 $u[$row[0]] = $dates;
9597 foreach ($u[$row[0]] as $d => $v)
9698 if ($d > $row[1]) {
 99+ if (!isset($u[$row[0]][$d][$row[2]]))
 100+ $u[$row[0]][$d][$row[2]] = 0;
97101 $u[$row[0]][$d][$row[2]]++;
98102 break;
99103 }
100104 }
101105 $db->freeResult($res);
 106+
 107+ # in case the current user is not already in the database
 108+ if (!isset($u[$user])) {
 109+ $u[$user] = $dates;
 110+ }
102111
103112 # plot the user statistics
104113 $gnuplot ="<gnuplot>
@@ -117,30 +126,30 @@
118127 $first = true;
119128 $e = 0;
120129 $p = 0;
121 - foreach ($u[$user] as $d => $v) {
122 - $date = '';
123 - if (preg_match('/^(\d{4})(\d{2})(\d{2})/',$d,$matches))
124 - $date = "$matches[2]/$matches[3]/$matches[1]";
125 - $csv .= "$date,";
126 - if ($type == 'incremental') {
127 - # the first data point includes all edits up to that date, so skip it
128 - if ($first) {
129 - $first = false;
130 - continue;
131 - }
132 - $e = 0;
133 - $p = 0;
134 - }
135 - foreach ($v as $pageid => $edits) {
136 - $p++;
137 - $e += $edits;
138 - }
139 - $gnuplot .= "$date $e\n";
140 - $gnuplot_pdata .= "$date $p\n";
141 - }
 130+ foreach ($u[$user] as $d => $v) {
 131+ $date = '';
 132+ if (preg_match('/^(\d{4})(\d{2})(\d{2})/',$d,$matches))
 133+ $date = "$matches[2]/$matches[3]/$matches[1]";
 134+ $csv .= "$date,";
 135+ if ($type == 'incremental') {
 136+ # the first data point includes all edits up to that date, so skip it
 137+ if ($first) {
 138+ $first = false;
 139+ continue;
 140+ }
 141+ $e = 0;
 142+ $p = 0;
 143+ }
 144+ foreach ($v as $pageid => $edits) {
 145+ $p++;
 146+ $e += $edits;
 147+ }
 148+ $gnuplot .= "$date $e\n";
 149+ $gnuplot_pdata .= "$date $p\n";
 150+ }
142151 $gnuplot .= "e\n$gnuplot_pdata\ne</gnuplot>";
143152
144 - //$wgOut->addHTML($gnuplot);
 153+ //print "@@@@@@@\n$gnuplot\n@@@@@@@\n";
145154 $wgOut->addWikiText("<center>$gnuplot</center>");
146155
147156
@@ -180,8 +189,11 @@
181190 if (preg_match('/^(\d{4})(\d{2})(\d{2})/',$d,$matches))
182191 $date = "$matches[2]/$matches[3]/$matches[1]";
183192 foreach ($u as $usr => $q)
184 - foreach ($u[$usr][$d] as $pageid => $numedits)
185 - $totals[$pageid] += $numedits;
 193+ foreach ($u[$usr][$d] as $pageid => $numedits) {
 194+ if (!isset($totals[$pageid]))
 195+ $totals[$pageid] = 0;
 196+ $totals[$pageid] += $numedits;
 197+ }
186198 $pages = 0;
187199 $edits = 0;
188200 foreach ($totals as $pageid => $e) {
@@ -217,8 +229,11 @@
218230 }
219231 $totals = array();
220232 }
221 - foreach ($u[$usr][$d] as $pageid => $numedits)
222 - $totals[$pageid] += $numedits;
 233+ foreach ($u[$usr][$d] as $pageid => $numedits) {
 234+ if (!isset($totals[$pageid]))
 235+ $totals[$pageid] = 0;
 236+ $totals[$pageid] += $numedits;
 237+ }
223238 $pages = 0;
224239 $edits = 0;
225240 foreach ($totals as $pageid => $e) {
@@ -240,13 +255,13 @@
241256 $wgOut->addHtml('<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">');
242257 $wgOut->addWikiText(wfMsg ('usagestatistics-editindividual', $nature));
243258 $wgOut->addHtml('</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">');
244 - $wgOut->AddWikiText("<pre>$csv$csv_edits</pre></div></div><br>");
 259+ $wgOut->AddHtml("<pre>$csv$csv_edits</pre></div></div><br />");
245260
246261 $wgOut->addHtml('<div class="NavFrame" style="padding:0px;border-style:none;">');
247262 $wgOut->addHtml('<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">');
248263 $wgOut->addWikiText(wfMsg ('usagestatistics-editpages', $nature));
249264 $wgOut->addHtml('</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">');
250 - $wgOut->AddWikiText("<pre>$csv$csv_pages</pre></div></div>");
 265+ $wgOut->AddHtml("<pre>$csv$csv_pages</pre></div></div>");
251266
252267 return;
253268 }
Index: trunk/extensions/UsageStatistics/SpecialUserStats.php
@@ -13,7 +13,7 @@
1414
1515 $wgExtensionCredits['specialpage'][] = array(
1616 'name' => 'UserStats',
17 - 'version' => 'v1.9',
 17+ 'version' => 'v1.10',
1818 'author' => 'Paul Grinberg',
1919 'email' => 'gri6507 at yahoo dot com',
2020 'url' => 'http://www.mediawiki.org/wiki/Extension:Usage_Statistics',

Status & tagging log