r54511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r54510‎ | r54511 | r54512 >
Date:10:01, 6 August 2009
Author:jan
Status:reverted (Comments)
Tags:
Comment:
Add interface for adding own statistics with $wgStatsOther:
* Enable/Disable this with $wgAllowStatsOther
* Use $wgStatsOther['<name of statistic>'] = <value (number)> for adding the statistic
Modified paths:
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialStatistics.php (modified) (history)
  • /trunk/phase3/languages/messages/MessagesEn.php (modified) (history)
  • /trunk/phase3/maintenance/language/messages.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/language/messages.inc
@@ -1404,6 +1404,7 @@
14051405 'statistics-header-edits',
14061406 'statistics-header-views',
14071407 'statistics-header-users',
 1408+ 'statistics-header-hooks',
14081409 'statistics-articles',
14091410 'statistics-pages',
14101411 'statistics-pages-desc',
Index: trunk/phase3/includes/DefaultSettings.php
@@ -4156,3 +4156,15 @@
41574157 */
41584158 $wgMemoryLimit = "50M";
41594159
 4160+/**
 4161+ * Allow extensions to add Statistics at the end of Special:Statistics.
 4162+ */
 4163+$wgAllowStatsOther = true;
 4164+
 4165+/**
 4166+ * Statistics which add at the end of Special:Statistics.
 4167+ * Use: $wgStatsOther['<name of statistic>'] = <value>;
 4168+ * Example: $wgStatsOther['Time since 01.01.1970'] = time();
 4169+ */
 4170+$wgStatsOther = array();
 4171+
Index: trunk/phase3/includes/specials/SpecialStatistics.php
@@ -38,6 +38,7 @@
3939 $this->activeUsers = SiteStats::activeUsers();
4040 $this->admins = SiteStats::numberingroup('sysop');
4141 $this->numJobs = SiteStats::jobs();
 42+ $this->hook = '';
4243
4344 # Staticic - views
4445 $viewsStats = '';
@@ -75,6 +76,9 @@
7677 if( !$wgDisableCounters && !$wgMiserMode ) {
7778 $text .= $this->getMostViewedPages();
7879 }
 80+
 81+ # Statistic - other
 82+ $text .= $this->getOtherStats();
7983
8084 $text .= Xml::closeElement( 'table' );
8185
@@ -258,6 +262,27 @@
259263 return $text;
260264 }
261265
 266+ private function getOtherStats() {
 267+ global $wgLang, $wgAllowStatsOther, $wgStatsOther;
 268+
 269+ if( !$wgAllowStatsOther ) return;
 270+
 271+ if ( count( $wgStatsOther ) < 1 ) return;
 272+
 273+ $return = Xml::openElement( 'tr' ) .
 274+ Xml::tags( 'th', array( 'colspan' => '2' ), wfMsgExt( 'statistics-header-hooks', array( 'parseinline' ) ) ) .
 275+ Xml::closeElement( 'tr' );
 276+
 277+ foreach( $wgStatsOther as $name => $number ) {
 278+ $name = htmlspecialchars( $name );
 279+ $number = htmlspecialchars( $number );
 280+
 281+ $return .= $this->formatRow( $name, $wgLang->formatNum( $number ), array( 'class' => 'mw-statistics-hook' ) );
 282+ }
 283+
 284+ return $return;
 285+ }
 286+
262287 /**
263288 * Do the action=raw output for this page. Legacy, but we support
264289 * it for backwards compatibility
Index: trunk/phase3/languages/messages/MessagesEn.php
@@ -2278,6 +2278,7 @@
22792279 'statistics-header-edits' => 'Edit statistics',
22802280 'statistics-header-views' => 'View statistics',
22812281 'statistics-header-users' => 'User statistics',
 2282+'statistics-header-hooks' => 'Other statistics',
22822283 'statistics-articles' => 'Content pages',
22832284 'statistics-pages' => 'Pages',
22842285 'statistics-pages-desc' => 'All pages in the wiki, including talk pages, redirects, etc.',

Follow-up revisions

RevisionCommit summaryAuthorDate
r54516(r54511) Replace global array with hookjan13:40, 6 August 2009

Comments

#Comment by 😂 (talk | contribs)   12:47, 6 August 2009

Ew, not another config global. Use a hook.

#Comment by Jan Luca (talk | contribs)   13:01, 6 August 2009

Have you an idea how the function get the result of the hooks without a global array?

#Comment by 😂 (talk | contribs)   13:21, 6 August 2009

Try this in SpecialStatistics.php:

# Statistic - other
$extraStats = array();
if( wfRunHooks( 'SpecialStatsAdditional', array( &$extraStats ) ) ) {
	$text .= $this->getOtherStats( $extraStats );
}

And then use $extraStats in getOtherStats() instead of the globals. Basically we'll give people the chance to modify $extraStats in the same way they would've modified $wgStatsOther, but without adding 2 new globals :) Name the hook something better if you can think of it.

#Comment by Jan Luca (talk | contribs)   13:40, 6 August 2009

Fixed in r54516!

#Comment by 😂 (talk | contribs)   13:50, 6 August 2009

Much nicer, thanks :D

Status & tagging log