r9557 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r9556‎ | r9557 | r9558 >
Date:01:59, 22 June 2005
Author:avar
Status:old
Tags:
Comment:
* Special:Statistics now supports action=raw, useful for bots designed to
harwest e.g. article counts from multiple wikis.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/SpecialStatistics.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/SpecialStatistics.php
@@ -9,9 +9,11 @@
1010 * constructor
1111 */
1212 function wfSpecialStatistics() {
13 - global $wgUser, $wgOut, $wgLang;
 13+ global $wgUser, $wgOut, $wgLang, $wgRequest;
1414 $fname = 'wfSpecialStatistics';
1515
 16+ $action = $wgRequest->getVal( 'action' );
 17+
1618 $dbr =& wfGetDB( DB_SLAVE );
1719 extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) );
1820
@@ -38,38 +40,45 @@
3941 }
4042
4143 if ( isset( $row->ss_users ) ) {
42 - $totalUsers = $row->ss_users;
 44+ $users = $row->ss_users;
4345 } else {
4446 $sql = "SELECT MAX(user_id) AS total FROM $user";
4547 $res = $dbr->query( $sql, $fname );
4648 $userRow = $dbr->fetchObject( $res );
47 - $totalUsers = $userRow->total;
 49+ $users = $userRow->total;
4850 }
4951
50 -
51 - $text = '==' . wfMsg( 'sitestats' ) . "==\n" ;
52 - $text .= wfMsg( 'sitestatstext',
53 - $wgLang->formatNum( $total ),
54 - $wgLang->formatNum( $good ),
55 - $wgLang->formatNum( $views ),
56 - $wgLang->formatNum( $edits ),
57 - $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
58 - $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) );
59 -
60 - $text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
61 -
6252 $sql = "SELECT COUNT(*) AS total FROM $user_groups WHERE ug_group='sysop'";
6353 $res = $dbr->query( $sql, $fname );
6454 $row = $dbr->fetchObject( $res );
6555 $admins = $row->total;
66 -
67 - $text .= wfMsg( 'userstatstext',
68 - $wgLang->formatNum( $totalUsers ),
69 - $wgLang->formatNum( $admins ),
70 - '[[' . wfMsg( 'administrators' ) . ']]',
71 - // should logically be after #admins, danm backwards compatability!
72 - $wgLang->formatNum( round( $admins / $total * 100, 2 ) )
73 - );
74 - $wgOut->addWikiText( $text );
 56+
 57+ if ($action == 'raw') {
 58+ $wgOut->disable();
 59+ header( 'Pragma: nocache' );
 60+ echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins\n";
 61+ return;
 62+ } else {
 63+ $text = '==' . wfMsg( 'sitestats' ) . "==\n" ;
 64+ $text .= wfMsg( 'sitestatstext',
 65+ $wgLang->formatNum( $total ),
 66+ $wgLang->formatNum( $good ),
 67+ $wgLang->formatNum( $views ),
 68+ $wgLang->formatNum( $edits ),
 69+ $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ),
 70+ $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) );
 71+
 72+ $text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
 73+
 74+ $text .= wfMsg( 'userstatstext',
 75+ $wgLang->formatNum( $users ),
 76+ $wgLang->formatNum( $admins ),
 77+ '[[' . wfMsg( 'administrators' ) . ']]',
 78+ // should logically be after #admins, danm backwards compatability!
 79+ $wgLang->formatNum( round( $admins / $total * 100, 2 ) )
 80+ );
 81+
 82+ $wgOut->addWikiText( $text );
 83+ }
7584 }
7685 ?>
Index: trunk/phase3/RELEASE-NOTES
@@ -315,6 +315,8 @@
316316 * Special:Watchlist/edit now has namespace subheadings
317317 * (bug 1714) the "Save page" button now has right margin to seperate it from
318318 "Show preview" and "Show changes"
 319+* Special:Statistics now supports action=raw, useful for bots designed to
 320+ harwest e.g. article counts from multiple wikis.
319321
320322 === Caveats ===
321323

Status & tagging log