Index: trunk/extensions/UsageStatistics/SpecialUserStats_body.php |
— | — | @@ -76,10 +76,12 @@ |
77 | 77 | $csv = 'Username,'; |
78 | 78 | $cur_t = $start_t; |
79 | 79 | 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(); |
81 | 82 | $cur_t += $interval; |
82 | 83 | } |
83 | 84 | |
| 85 | + # Let's process the edits that are recorded in the database |
84 | 86 | $u = array(); |
85 | 87 | $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " . |
86 | 88 | $db->tableName('page') . "," . $db->tableName('revision') . |
— | — | @@ -93,11 +95,18 @@ |
94 | 96 | $u[$row[0]] = $dates; |
95 | 97 | foreach ($u[$row[0]] as $d => $v) |
96 | 98 | if ($d > $row[1]) { |
| 99 | + if (!isset($u[$row[0]][$d][$row[2]])) |
| 100 | + $u[$row[0]][$d][$row[2]] = 0; |
97 | 101 | $u[$row[0]][$d][$row[2]]++; |
98 | 102 | break; |
99 | 103 | } |
100 | 104 | } |
101 | 105 | $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 | + } |
102 | 111 | |
103 | 112 | # plot the user statistics |
104 | 113 | $gnuplot ="<gnuplot> |
— | — | @@ -117,30 +126,30 @@ |
118 | 127 | $first = true; |
119 | 128 | $e = 0; |
120 | 129 | $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 | + } |
142 | 151 | $gnuplot .= "e\n$gnuplot_pdata\ne</gnuplot>"; |
143 | 152 | |
144 | | - //$wgOut->addHTML($gnuplot); |
| 153 | + //print "@@@@@@@\n$gnuplot\n@@@@@@@\n"; |
145 | 154 | $wgOut->addWikiText("<center>$gnuplot</center>"); |
146 | 155 | |
147 | 156 | |
— | — | @@ -180,8 +189,11 @@ |
181 | 190 | if (preg_match('/^(\d{4})(\d{2})(\d{2})/',$d,$matches)) |
182 | 191 | $date = "$matches[2]/$matches[3]/$matches[1]"; |
183 | 192 | 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 | + } |
186 | 198 | $pages = 0; |
187 | 199 | $edits = 0; |
188 | 200 | foreach ($totals as $pageid => $e) { |
— | — | @@ -217,8 +229,11 @@ |
218 | 230 | } |
219 | 231 | $totals = array(); |
220 | 232 | } |
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 | + } |
223 | 238 | $pages = 0; |
224 | 239 | $edits = 0; |
225 | 240 | foreach ($totals as $pageid => $e) { |
— | — | @@ -240,13 +255,13 @@ |
241 | 256 | $wgOut->addHtml('<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">'); |
242 | 257 | $wgOut->addWikiText(wfMsg ('usagestatistics-editindividual', $nature)); |
243 | 258 | $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 />"); |
245 | 260 | |
246 | 261 | $wgOut->addHtml('<div class="NavFrame" style="padding:0px;border-style:none;">'); |
247 | 262 | $wgOut->addHtml('<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">'); |
248 | 263 | $wgOut->addWikiText(wfMsg ('usagestatistics-editpages', $nature)); |
249 | 264 | $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>"); |
251 | 266 | |
252 | 267 | return; |
253 | 268 | } |
Index: trunk/extensions/UsageStatistics/SpecialUserStats.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | |
15 | 15 | $wgExtensionCredits['specialpage'][] = array( |
16 | 16 | 'name' => 'UserStats', |
17 | | - 'version' => 'v1.9', |
| 17 | + 'version' => 'v1.10', |
18 | 18 | 'author' => 'Paul Grinberg', |
19 | 19 | 'email' => 'gri6507 at yahoo dot com', |
20 | 20 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Usage_Statistics', |