r56389 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56388‎ | r56389 | r56390 >
Date:19:29, 15 September 2009
Author:ialex
Status:deferred
Tags:
Comment:
* (bug 19621) Add namespace selector to Special:UserStats
* also fixed some E_STRICT and E_DEPRECATED (split() is deprecated since PHP 5.3.0)
* didn't move JavaScript to its own file for now since it requires some more work
* some whitespaces fixes
Based on a patch by Alfred Maghi - http://bug-attachment.wikimedia.org/attachment.cgi?id=6471
Modified paths:
  • /trunk/extensions/UsageStatistics/SpecialUserStats.i18n.php (modified) (history)
  • /trunk/extensions/UsageStatistics/SpecialUserStats_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/UsageStatistics/SpecialUserStats_body.php
@@ -1,31 +1,11 @@
22 <?php
3 -class SpecialUserStats extends SpecialPage
4 -{
5 - function SpecialUserStats() {
6 - SpecialPage::SpecialPage( "SpecialUserStats" );
73
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 {
145
15 - return true;
16 - }
 6+ function __construct() {
 7+ parent::__construct( 'SpecialUserStats' );
178
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' );
3010 }
3111
3212 function execute( $par ) {
@@ -35,33 +15,34 @@
3616 $wgOut->setPagetitle( wfMsg( 'usagestatistics' ) );
3717
3818 $user = $wgUser->getName();
39 - $wgOut->addWikiText( wfMsg( 'usagestatisticsfor', $user ) );
 19+ $wgOut->addWikiMsg( 'usagestatisticsfor', $user );
4020
4121 $interval = $wgRequest->getVal( 'interval', '' );
 22+ $namespace = $wgRequest->getVal('namespace', '' );
 23+ $noredirects = $wgRequest->getCheck( 'noredirects' );
4224 $type = $wgRequest->getVal( 'type', '' );
4325 $start = $wgRequest->getVal( 'start', '' );
4426 $end = $wgRequest->getVal( 'end', '' );
4527
4628 self::AddCalendarJavascript();
4729
48 - if ( $start == "" || $end == "" ) {
49 - if ( $start == "" ) {
 30+ if ( $start == '' || $end == '' ) {
 31+ if ( $start == '' ) {
5032 // FIXME: ideally this would use a class for markup.
5133 $wgOut->addWikiText( '* <font color=red>' . wfMsg( 'usagestatisticsnostart' ) . '</font>' );
5234 }
53 - if ( $end == "" ) {
 35+ if ( $end == '' ) {
5436 // FIXME: ideally this would use a class for markup.
5537 $wgOut->addWikiText( '* <font color=red>' . wfMsg( 'usagestatisticsnoend' ) . '</font>' );
5638 }
57 - self::DisplayForm( $start, $end );
 39+ $this->displayForm( $start, $end, $namespace, $noredirects );
5840 } else {
5941 $db = wfGetDB( DB_SLAVE );
60 - self::GetUserUsage( $db, $user, $start, $end, $interval, $type );
 42+ $this->getUserUsage( $db, $user, $start, $end, $interval, $namespace, $noredirects, $type );
6143 }
6244 }
6345
64 - function generate_google_chart( $dates, $edits, $pages )
65 - {
 46+ function generate_google_chart( $dates, $edits, $pages ) {
6647 $x_labels = 3;
6748 $max_url = 2080; // this is a typical minimum limitation of many browsers
6849
@@ -128,19 +109,28 @@
129110 return $new_ary;
130111 }
131112
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;
134115
135 - list( $start_m, $start_d, $start_y ) = split( '/', $start );
 116+ list( $start_m, $start_d, $start_y ) = explode( '/', $start );
136117 $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 );
138119 $end_t = mktime( 0, 0, 0, $end_m, $end_d, $end_y );
139120
140121 if ( $start_t >= $end_t ) {
141 - $wgOut->addHTML( wfMsg( 'usagestatisticsbadstartend' ) );
 122+ $wgOut->addWikiMsg( 'usagestatisticsbadstartend' );
142123 return;
143124 }
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+ }
145135 $dates = array();
146136 $csv = 'Username,';
147137 $cur_t = $start_t;
@@ -149,15 +139,22 @@
150140 $dates[$a_date] = array();
151141 $cur_t += $interval;
152142 }
153 -
154143 # Let's process the edits that are recorded in the database
155144 $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+ );
159158
160 - $res = $db->query( $sql, __METHOD__ );
161 -
162159 for ( $j = 0; $j < $db->numRows( $res ); $j++ ) {
163160 $row = $db->fetchRow( $res );
164161 if ( !isset( $u[$row[0]] ) )
@@ -224,14 +221,11 @@
225222 }
226223 $gnuplot .= "e\n$gnuplot_pdata\ne</gnuplot>";
227224
228 - if ( $wgUserStatsGoogleCharts )
229 - {
 225+ if ( $wgUserStatsGoogleCharts ) {
230226 $wgOut->addHTML( '<img src="' .
231227 self::generate_google_chart( $ary_dates, $ary_edits, $ary_pages ) .
232228 '"/>' );
233 - }
234 - else
235 - {
 229+ } else {
236230 // print "@@@@@@@\n$gnuplot\n@@@@@@@\n";
237231 $wgOut->addWikiText( "<center>$gnuplot</center>" );
238232 }
@@ -240,7 +234,7 @@
241235 return;
242236
243237 # plot overall usage statistics
244 - $wgOut->addWikiText( wfMsg( 'usagestatisticsforallusers' ) );
 238+ $wgOut->addWikiMsg( 'usagestatisticsforallusers' );
245239 $gnuplot = "<gnuplot>
246240 set xdata time
247241 set xtics rotate by 90
@@ -348,71 +342,88 @@
349343
350344 $wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' );
351345 $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 );
353347 $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 />" );
355349
356350 $wgOut->addHTML( '<div class="NavFrame" style="padding:0px;border-style:none;">' );
357351 $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 );
359353 $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>" );
361355
362356 return;
363357 }
364358
365 - function DisplayForm( $start, $end ) {
 359+ function displayForm( $start, $end, $namespace, $noredirects ) {
366360 global $wgOut;
367361
368362 $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'>
394405 <input type='text' size='20' name='start' value='$start'/>
395406 <script type='text/javascript'>
396407 var cal1 = new CalendarPopup('testdiv1');
397408 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'>
405416 <input type='text' size='20' name='end' value='$end'/>
406417 <script type='text/javascript'>
407418 var cal2 = new CalendarPopup('testdiv1');
408419 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>
417428 " );
418429 }
419430
Index: trunk/extensions/UsageStatistics/SpecialUserStats.i18n.php
@@ -13,10 +13,14 @@
1414 'usagestatistics-desc' => 'Show individual user and overall wiki usage statistics',
1515 'usagestatisticsfor' => '<h2>Usage statistics for [[User:$1|$1]]</h2>',
1616 '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:',
2125 'usagestatisticssubmit' => 'Generate statistics',
2226 'usagestatisticsnostart' => 'Please specify a start date',
2327 'usagestatisticsnoend' => 'Please specify an end date',
@@ -386,7 +390,7 @@
387391 'right-viewsystemstats' => "Veure [[Special:UserStats|estadístiques d'ús de la wiki]]",
388392 );
389393
390 -/** Sorani (Arabic script) (‫کوردی (عەرەبی)‬)
 394+/** Sorani (Arabic script) (کوردی (عەرەبی))
391395 * @author Marmzok
392396 */
393397 $messages['ckb-arab'] = array(
@@ -1385,7 +1389,7 @@
13861390 'right-viewsystemstats' => '[[Special:UserStats|Wikigebruiksstatistieken]] bekijken',
13871391 );
13881392
1389 -/** Norwegian Nynorsk (‪Norsk (nynorsk)‬)
 1393+/** Norwegian Nynorsk (Norsk (nynorsk))
13901394 * @author Eirik
13911395 * @author Frokor
13921396 * @author Jon Harald Søby
@@ -1416,7 +1420,7 @@
14171421 'usagestatistics-editpages' => 'Sidestatistikk for $1',
14181422 );
14191423
1420 -/** Norwegian (bokmål)‬ (‪Norsk (bokmål)‬)
 1424+/** Norwegian (bokmål) (Norsk (bokmål))
14211425 * @author Jon Harald Søby
14221426 * @author Nghtwlkr
14231427 */
@@ -2045,7 +2049,7 @@
20462050 'usagestatistics-editpages' => 'Padastatits tefü geban: $1',
20472051 );
20482052
2049 -/** Simplified Chinese (‪中文(简体)‬)
 2053+/** Simplified Chinese (中文(简体))
20502054 * @author Gaoxuewei
20512055 */
20522056 $messages['zh-hans'] = array(
@@ -2074,7 +2078,7 @@
20752079 'usagestatistics-editpages' => '用户$1统计分析',
20762080 );
20772081
2078 -/** Traditional Chinese (‪中文(繁體)‬)
 2082+/** Traditional Chinese (中文(繁體))
20792083 * @author Wrightbus
20802084 */
20812085 $messages['zh-hant'] = array(

Status & tagging log