Index: trunk/extensions/UsageStatistics/SpecialUserStats_body.php |
— | — | @@ -1,31 +1,11 @@ |
2 | 2 | <?php |
3 | | -class SpecialUserStats extends SpecialPage |
4 | | -{ |
5 | | - function SpecialUserStats() { |
6 | | - SpecialPage::SpecialPage( "SpecialUserStats" ); |
7 | 3 | |
8 | | - # the standard method for LoadingExtensionMessages was apparently broken in several versions of MW |
9 | | - # so, to make this work with multiple versions of MediaWiki, let's load the messages nicely |
10 | | - if ( function_exists( 'wfLoadExtensionMessages' ) ) |
11 | | - wfLoadExtensionMessages( 'UserStats' ); |
12 | | - else |
13 | | - self::loadMessages(); |
| 4 | +class SpecialUserStats extends SpecialPage { |
14 | 5 | |
15 | | - return true; |
16 | | - } |
| 6 | + function __construct() { |
| 7 | + parent::__construct( 'SpecialUserStats' ); |
17 | 8 | |
18 | | - function loadMessages() { |
19 | | - static $messagesLoaded = false; |
20 | | - global $wgMessageCache; |
21 | | - if ( !$messagesLoaded ) { |
22 | | - $messagesLoaded = true; |
23 | | - |
24 | | - require( dirname( __FILE__ ) . '/SpecialUserStats.i18n.php' ); |
25 | | - foreach ( $messages as $lang => $langMessages ) { |
26 | | - $wgMessageCache->addMessages( $langMessages, $lang ); |
27 | | - } |
28 | | - } |
29 | | - return true; |
| 9 | + wfLoadExtensionMessages( 'UserStats' ); |
30 | 10 | } |
31 | 11 | |
32 | 12 | function execute( $par ) { |
— | — | @@ -35,33 +15,34 @@ |
36 | 16 | $wgOut->setPagetitle( wfMsg( 'usagestatistics' ) ); |
37 | 17 | |
38 | 18 | $user = $wgUser->getName(); |
39 | | - $wgOut->addWikiText( wfMsg( 'usagestatisticsfor', $user ) ); |
| 19 | + $wgOut->addWikiMsg( 'usagestatisticsfor', $user ); |
40 | 20 | |
41 | 21 | $interval = $wgRequest->getVal( 'interval', '' ); |
| 22 | + $namespace = $wgRequest->getVal('namespace', '' ); |
| 23 | + $noredirects = $wgRequest->getCheck( 'noredirects' ); |
42 | 24 | $type = $wgRequest->getVal( 'type', '' ); |
43 | 25 | $start = $wgRequest->getVal( 'start', '' ); |
44 | 26 | $end = $wgRequest->getVal( 'end', '' ); |
45 | 27 | |
46 | 28 | self::AddCalendarJavascript(); |
47 | 29 | |
48 | | - if ( $start == "" || $end == "" ) { |
49 | | - if ( $start == "" ) { |
| 30 | + if ( $start == '' || $end == '' ) { |
| 31 | + if ( $start == '' ) { |
50 | 32 | // FIXME: ideally this would use a class for markup. |
51 | 33 | $wgOut->addWikiText( '* <font color=red>' . wfMsg( 'usagestatisticsnostart' ) . '</font>' ); |
52 | 34 | } |
53 | | - if ( $end == "" ) { |
| 35 | + if ( $end == '' ) { |
54 | 36 | // FIXME: ideally this would use a class for markup. |
55 | 37 | $wgOut->addWikiText( '* <font color=red>' . wfMsg( 'usagestatisticsnoend' ) . '</font>' ); |
56 | 38 | } |
57 | | - self::DisplayForm( $start, $end ); |
| 39 | + $this->displayForm( $start, $end, $namespace, $noredirects ); |
58 | 40 | } else { |
59 | 41 | $db = wfGetDB( DB_SLAVE ); |
60 | | - self::GetUserUsage( $db, $user, $start, $end, $interval, $type ); |
| 42 | + $this->getUserUsage( $db, $user, $start, $end, $interval, $namespace, $noredirects, $type ); |
61 | 43 | } |
62 | 44 | } |
63 | 45 | |
64 | | - function generate_google_chart( $dates, $edits, $pages ) |
65 | | - { |
| 46 | + function generate_google_chart( $dates, $edits, $pages ) { |
66 | 47 | $x_labels = 3; |
67 | 48 | $max_url = 2080; // this is a typical minimum limitation of many browsers |
68 | 49 | |
— | — | @@ -128,19 +109,28 @@ |
129 | 110 | return $new_ary; |
130 | 111 | } |
131 | 112 | |
132 | | - function GetUserUsage( $db, $user, $start, $end, $interval, $type ) { |
133 | | - global $wgOut, $wgUser, $wgUserStatsGlobalRight, $wgUserStatsGoogleCharts; |
| 113 | + function getUserUsage( $db, $user, $start, $end, $interval, $namespace, $noredirects, $type ) { |
| 114 | + global $wgOut, $wgUser, $wgUserStatsGlobalRight, $wgUserStatsGoogleCharts, $wgContLang; |
134 | 115 | |
135 | | - list( $start_m, $start_d, $start_y ) = split( '/', $start ); |
| 116 | + list( $start_m, $start_d, $start_y ) = explode( '/', $start ); |
136 | 117 | $start_t = mktime( 0, 0, 0, $start_m, $start_d, $start_y ); |
137 | | - list( $end_m, $end_d, $end_y ) = split( '/', $end ); |
| 118 | + list( $end_m, $end_d, $end_y ) = explode( '/', $end ); |
138 | 119 | $end_t = mktime( 0, 0, 0, $end_m, $end_d, $end_y ); |
139 | 120 | |
140 | 121 | if ( $start_t >= $end_t ) { |
141 | | - $wgOut->addHTML( wfMsg( 'usagestatisticsbadstartend' ) ); |
| 122 | + $wgOut->addWikiMsg( 'usagestatisticsbadstartend' ); |
142 | 123 | return; |
143 | 124 | } |
144 | | - |
| 125 | + if ( $namespace != 'all' ) { |
| 126 | + $nstext = $wgContLang->getNSText( $namespace ); |
| 127 | + $displayns = $nstext; |
| 128 | + if ( $displayns == '' ) |
| 129 | + $displayns = wfMsg( 'blanknamespace' ); |
| 130 | + $wgOut->addWikiMsg( 'usagestatistics-namespace', $nstext, $displayns ); |
| 131 | + } |
| 132 | + if ( $noredirects ) { |
| 133 | + $wgOut->addWikiMsg( 'usagestatistics-noredirects' ); |
| 134 | + } |
145 | 135 | $dates = array(); |
146 | 136 | $csv = 'Username,'; |
147 | 137 | $cur_t = $start_t; |
— | — | @@ -149,15 +139,22 @@ |
150 | 140 | $dates[$a_date] = array(); |
151 | 141 | $cur_t += $interval; |
152 | 142 | } |
153 | | - |
154 | 143 | # Let's process the edits that are recorded in the database |
155 | 144 | $u = array(); |
156 | | - $sql = "SELECT rev_user_text,rev_timestamp,page_id FROM " . |
157 | | - $db->tableName( 'page' ) . "," . $db->tableName( 'revision' ) . |
158 | | - " WHERE rev_page=page_id"; |
| 145 | + $conds = array( 'rev_page=page_id' ); |
| 146 | + if ( $namespace == 'all' ) { |
| 147 | + $conds['page_namespace'] = $namespace; |
| 148 | + } |
| 149 | + if ( $noredirects ) { |
| 150 | + $conds['page_is_redirect'] = 0; |
| 151 | + } |
| 152 | + $res = $db->select( |
| 153 | + array( 'page', 'revision' ), |
| 154 | + array( 'rev_user_text', 'rev_timestamp', 'page_id' ), |
| 155 | + $conds, |
| 156 | + __METHOD__ |
| 157 | + ); |
159 | 158 | |
160 | | - $res = $db->query( $sql, __METHOD__ ); |
161 | | - |
162 | 159 | for ( $j = 0; $j < $db->numRows( $res ); $j++ ) { |
163 | 160 | $row = $db->fetchRow( $res ); |
164 | 161 | if ( !isset( $u[$row[0]] ) ) |
— | — | @@ -224,14 +221,11 @@ |
225 | 222 | } |
226 | 223 | $gnuplot .= "e\n$gnuplot_pdata\ne</gnuplot>"; |
227 | 224 | |
228 | | - if ( $wgUserStatsGoogleCharts ) |
229 | | - { |
| 225 | + if ( $wgUserStatsGoogleCharts ) { |
230 | 226 | $wgOut->addHTML( '<img src="' . |
231 | 227 | self::generate_google_chart( $ary_dates, $ary_edits, $ary_pages ) . |
232 | 228 | '"/>' ); |
233 | | - } |
234 | | - else |
235 | | - { |
| 229 | + } else { |
236 | 230 | // print "@@@@@@@\n$gnuplot\n@@@@@@@\n"; |
237 | 231 | $wgOut->addWikiText( "<center>$gnuplot</center>" ); |
238 | 232 | } |
— | — | @@ -240,7 +234,7 @@ |
241 | 235 | return; |
242 | 236 | |
243 | 237 | # plot overall usage statistics |
244 | | - $wgOut->addWikiText( wfMsg( 'usagestatisticsforallusers' ) ); |
| 238 | + $wgOut->addWikiMsg( 'usagestatisticsforallusers' ); |
245 | 239 | $gnuplot = "<gnuplot> |
246 | 240 | set xdata time |
247 | 241 | set xtics rotate by 90 |
— | — | @@ -348,71 +342,88 @@ |
349 | 343 | |
350 | 344 | $wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' ); |
351 | 345 | $wgOut->addHTML( '<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">' ); |
352 | | - $wgOut->addWikiText( wfMsg ( 'usagestatistics-editindividual', $nature ) ); |
| 346 | + $wgOut->addWikiMsg ( 'usagestatistics-editindividual', $nature ); |
353 | 347 | $wgOut->addHTML( '</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">' ); |
354 | | - $wgOut->AddHtml( "<pre>$csv$csv_edits</pre></div></div><br />" ); |
| 348 | + $wgOut->addHTML( "<pre>$csv$csv_edits</pre></div></div><br />" ); |
355 | 349 | |
356 | 350 | $wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' ); |
357 | 351 | $wgOut->addHTML( '<div class="NavHead" style="background: #ffffff; text-align: left; font-size:100%;">' ); |
358 | | - $wgOut->addWikiText( wfMsg ( 'usagestatistics-editpages', $nature ) ); |
| 352 | + $wgOut->addWikiMsg ( 'usagestatistics-editpages', $nature ); |
359 | 353 | $wgOut->addHTML( '</div><div class="NavContent" style="display:none; font-size:normal; text-align:left">' ); |
360 | | - $wgOut->AddHtml( "<pre>$csv$csv_pages</pre></div></div>" ); |
| 354 | + $wgOut->addHTML( "<pre>$csv$csv_pages</pre></div></div>" ); |
361 | 355 | |
362 | 356 | return; |
363 | 357 | } |
364 | 358 | |
365 | | - function DisplayForm( $start, $end ) { |
| 359 | + function displayForm( $start, $end, $namespace, $noredirects ) { |
366 | 360 | global $wgOut; |
367 | 361 | |
368 | 362 | $wgOut->addHTML( " |
369 | | -<script type='text/javascript'>document.write(getCalendarStyles());</SCRIPT> |
370 | | -<form id=\"userstats\" method=\"post\"> |
371 | | -<table border='0'> |
372 | | -<tr> |
373 | | - <td align='right'>" . wfMsg( 'usagestatisticsinterval' ) . ":</td> |
374 | | - <td align='left'> |
375 | | - <select name='interval'> |
376 | | - <option value='86400'>" . wfMsg( 'usagestatisticsintervalday' ) . " |
377 | | - <option value='604800'>" . wfMsg( 'usagestatisticsintervalweek' ) . " |
378 | | - <option value='2629744' selected>" . wfMsg( 'usagestatisticsintervalmonth' ) . " |
379 | | - </select> |
380 | | - </td> |
381 | | -</tr> |
382 | | -<tr> |
383 | | - <td align='right'>" . wfMsg( 'usagestatisticstype' ) . ":</td> |
384 | | - <td align='left'> |
385 | | - <select name='type'> |
386 | | - <option value='incremental'>" . wfMsg( 'usagestatisticsincremental' ) . " |
387 | | - <option value='cumulative' selected>" . wfMsg( 'usagestatisticscumulative' ) . " |
388 | | - </select> |
389 | | - </td> |
390 | | -</tr> |
391 | | -<tr> |
392 | | - <td align='right'>" . wfMsg( 'usagestatisticsstart' ) . ":</td> |
393 | | - <td align='left'> |
| 363 | +<script type='text/javascript'>document.write(getCalendarStyles());</script> |
| 364 | +<form id=\"userstats\" method=\"post\">"); |
| 365 | + |
| 366 | + $wgOut->addHTML( |
| 367 | + Xml::openElement( 'table', array( 'border' => '0' ) ) . |
| 368 | + Xml::openElement( 'tr' ) . |
| 369 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . Xml::label( wfMsg( 'usagestatisticsnamespace' ), 'namespace' ) . |
| 370 | + Xml::closeElement( 'td' ) . |
| 371 | + Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . |
| 372 | + Xml::namespaceSelector( $namespace, 'all' ) . |
| 373 | + Xml::closeElement( 'td' ) . |
| 374 | + Xml::closeElement( 'tr' ) . |
| 375 | + Xml::openElement( 'tr' ) . |
| 376 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsinterval' ) . |
| 377 | + Xml::closeElement( 'td' ) . |
| 378 | + Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . |
| 379 | + Xml::openElement( 'select', array( 'name' => 'interval' ) ) . |
| 380 | + Xml::openElement( 'option', array( 'value' => '86400' ) ) . wfMsg( 'usagestatisticsintervalday' ) . |
| 381 | + Xml::openElement( 'option', array( 'value' => '604800' ) ) . wfMsg( 'usagestatisticsintervalweek' ) . |
| 382 | + Xml::openElement( 'option', array( 'value' => '2629744', 'selected' => 'selected' )) . wfMsg( 'usagestatisticsintervalmonth' ) . |
| 383 | + Xml::closeElement( 'select' ) . |
| 384 | + Xml::closeElement( 'td' ) . |
| 385 | + Xml::closeElement( 'tr' ) . |
| 386 | + Xml::openElement( 'tr' ) . |
| 387 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticstype' ) . Xml::closeElement( 'td' ) . |
| 388 | + Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . |
| 389 | + Xml::openElement( 'select', array( 'name' => 'type' ) ) . |
| 390 | + Xml::openElement( 'option', array( 'value' => 'incremental' ) ) . wfMsg( 'usagestatisticsincremental' ) . |
| 391 | + Xml::openElement( 'option', array( 'value' => 'cumulative', 'selected' => 'selected' ) ) . wfMsg( 'usagestatisticscumulative' ) . |
| 392 | + Xml::closeElement( 'select' ) . |
| 393 | + Xml::closeElement( 'td' ) . |
| 394 | + Xml::closeElement( 'tr' ) . |
| 395 | + Xml::openElement( 'tr' ) . |
| 396 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . Xml::label( wfMsg( 'usagestatisticsexcluderedirects' ), '' ) . Xml::closeElement( 'td' ) . |
| 397 | + Xml::openElement( 'td', array( 'class' => 'mw-input' ) ) . |
| 398 | + Xml::check( 'noredirects', $noredirects ) . |
| 399 | + Xml::closeElement( 'td' ) . |
| 400 | + Xml::closeElement( 'tr' ) . |
| 401 | + Xml::openElement( 'tr' ) . |
| 402 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsstart' ) . Xml::closeElement( 'td' ) . |
| 403 | +" |
| 404 | + <td class='mw-input'> |
394 | 405 | <input type='text' size='20' name='start' value='$start'/> |
395 | 406 | <script type='text/javascript'> |
396 | 407 | var cal1 = new CalendarPopup('testdiv1'); |
397 | 408 | cal1.showNavigationDropdowns(); |
398 | | - </SCRIPT> |
399 | | - <A HREF='#' onClick=\"cal1.select(document.forms[0].start,'anchor1','MM/dd/yyyy'); return false;\" NAME='anchor1' ID='anchor1'>" . wfMsg( 'usagestatisticscalselect' ) . "</A> |
400 | | - </td> |
401 | | -</tr> |
402 | | -<tr> |
403 | | - <td align='right'>" . wfMsg( 'usagestatisticsend' ) . ":</td> |
404 | | - <td align='left'> |
| 409 | + </script> |
| 410 | + <a href='#' onClick=\"cal1.select(document.forms[0].start,'anchor1','MM/dd/yyyy'); return false;\" name='anchor1' id='anchor1'>" . wfMsg( 'usagestatisticscalselect' ) . |
| 411 | + Xml::closeElement( 'a' ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . |
| 412 | + Xml::openElement( 'tr' ) . |
| 413 | + Xml::openElement( 'td', array( 'class' => 'mw-label' ) ) . wfMsg( 'usagestatisticsend' ) . Xml::closeElement( 'td' ) . |
| 414 | +" |
| 415 | + <td class='mw-input'> |
405 | 416 | <input type='text' size='20' name='end' value='$end'/> |
406 | 417 | <script type='text/javascript'> |
407 | 418 | var cal2 = new CalendarPopup('testdiv1'); |
408 | 419 | cal2.showNavigationDropdowns(); |
409 | | - </SCRIPT> |
410 | | - <A HREF='#' onClick=\"cal2.select(document.forms[0].end,'anchor2','MM/dd/yyyy'); return false;\" NAME='anchor2' ID='anchor2'>" . wfMsg( 'usagestatisticscalselect' ) . "</A> |
411 | | - </td> |
412 | | -</tr> |
413 | | -</table> |
414 | | -<input type='submit' name=\"wpSend\" value=\"" . wfMsg( 'usagestatisticssubmit' ) . "\" /> |
415 | | -</form> |
416 | | -<DIV ID=\"testdiv1\" STYLE=\"position:absolute;visibility:hidden;background-color:white;layer-background-color:white;\"></DIV> |
| 420 | + </script> |
| 421 | + <a href='#' onClick=\"cal2.select(document.forms[0].end,'anchor2','MM/dd/yyyy'); return false;\" name='anchor2' id='anchor2'>" . wfMsg( 'usagestatisticscalselect' ) . |
| 422 | + Xml::closeElement( 'a' ) . Xml::closeElement( 'td' ) . Xml::closeElement( 'tr' ) . |
| 423 | + Xml::closeElement( 'table' ) . " |
| 424 | +<input type='submit' name=\"wpSend\" value=\"" . wfMsg( 'usagestatisticssubmit' ) . "\" /> ". |
| 425 | + Xml::closeElement( 'form' ) ." |
| 426 | + |
| 427 | +<div id=\"testdiv1\" style=\"position:absolute;visibility:hidden;background-color:white;layer-background-color:white;\"></div> |
417 | 428 | " ); |
418 | 429 | } |
419 | 430 | |
Index: trunk/extensions/UsageStatistics/SpecialUserStats.i18n.php |
— | — | @@ -13,10 +13,14 @@ |
14 | 14 | 'usagestatistics-desc' => 'Show individual user and overall wiki usage statistics', |
15 | 15 | 'usagestatisticsfor' => '<h2>Usage statistics for [[User:$1|$1]]</h2>', |
16 | 16 | 'usagestatisticsforallusers' => '<h2>Usage statistics for all users</h2>', |
17 | | - 'usagestatisticsinterval' => 'Interval', |
18 | | - 'usagestatisticstype' => 'Type', |
19 | | - 'usagestatisticsstart' => 'Start date', |
20 | | - 'usagestatisticsend' => 'End date', |
| 17 | + 'usagestatisticsinterval' => 'Interval:', |
| 18 | + 'usagestatisticsnamespace' => 'Namespace:', |
| 19 | + 'usagestatisticsexcluderedirects' => 'Exclude redirects', |
| 20 | + 'usagestatistics-namespace' => 'These are statistics on the [[Special:Allpages/$1|$2]] namespace.', |
| 21 | + 'usagestatistics-noredirects' => '[[Special:ListRedirects|Redirects]] are not taken into account.', |
| 22 | + 'usagestatisticstype' => 'Type:', |
| 23 | + 'usagestatisticsstart' => 'Start date:', |
| 24 | + 'usagestatisticsend' => 'End date:', |
21 | 25 | 'usagestatisticssubmit' => 'Generate statistics', |
22 | 26 | 'usagestatisticsnostart' => 'Please specify a start date', |
23 | 27 | 'usagestatisticsnoend' => 'Please specify an end date', |
— | — | @@ -386,7 +390,7 @@ |
387 | 391 | 'right-viewsystemstats' => "Veure [[Special:UserStats|estadístiques d'ús de la wiki]]", |
388 | 392 | ); |
389 | 393 | |
390 | | -/** Sorani (Arabic script) (کوردی (عەرەبی)) |
| 394 | +/** Sorani (Arabic script) (کوردی (عەرەبی)) |
391 | 395 | * @author Marmzok |
392 | 396 | */ |
393 | 397 | $messages['ckb-arab'] = array( |
— | — | @@ -1385,7 +1389,7 @@ |
1386 | 1390 | 'right-viewsystemstats' => '[[Special:UserStats|Wikigebruiksstatistieken]] bekijken', |
1387 | 1391 | ); |
1388 | 1392 | |
1389 | | -/** Norwegian Nynorsk (Norsk (nynorsk)) |
| 1393 | +/** Norwegian Nynorsk (Norsk (nynorsk)) |
1390 | 1394 | * @author Eirik |
1391 | 1395 | * @author Frokor |
1392 | 1396 | * @author Jon Harald Søby |
— | — | @@ -1416,7 +1420,7 @@ |
1417 | 1421 | 'usagestatistics-editpages' => 'Sidestatistikk for $1', |
1418 | 1422 | ); |
1419 | 1423 | |
1420 | | -/** Norwegian (bokmål) (Norsk (bokmål)) |
| 1424 | +/** Norwegian (bokmål) (Norsk (bokmål)) |
1421 | 1425 | * @author Jon Harald Søby |
1422 | 1426 | * @author Nghtwlkr |
1423 | 1427 | */ |
— | — | @@ -2045,7 +2049,7 @@ |
2046 | 2050 | 'usagestatistics-editpages' => 'Padastatits tefü geban: $1', |
2047 | 2051 | ); |
2048 | 2052 | |
2049 | | -/** Simplified Chinese (中文(简体)) |
| 2053 | +/** Simplified Chinese (中文(简体)) |
2050 | 2054 | * @author Gaoxuewei |
2051 | 2055 | */ |
2052 | 2056 | $messages['zh-hans'] = array( |
— | — | @@ -2074,7 +2078,7 @@ |
2075 | 2079 | 'usagestatistics-editpages' => '用户$1统计分析', |
2076 | 2080 | ); |
2077 | 2081 | |
2078 | | -/** Traditional Chinese (中文(繁體)) |
| 2082 | +/** Traditional Chinese (中文(繁體)) |
2079 | 2083 | * @author Wrightbus |
2080 | 2084 | */ |
2081 | 2085 | $messages['zh-hant'] = array( |