From 59a3d6d58b1edfdd0b4576195116e70bdc3a6df6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Wed, 22 Jun 2005 01:59:35 +0000 Subject: [PATCH] * Special:Statistics now supports action=raw, useful for bots designed to harwest e.g. article counts from multiple wikis. --- RELEASE-NOTES | 2 ++ includes/SpecialStatistics.php | 57 ++++++++++++++++++++-------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 42c493a757..a038c98b6f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -315,6 +315,8 @@ Various bugfixes, small features, and a few experimental things: * Special:Watchlist/edit now has namespace subheadings * (bug 1714) the "Save page" button now has right margin to seperate it from "Show preview" and "Show changes" +* Special:Statistics now supports action=raw, useful for bots designed to + harwest e.g. article counts from multiple wikis. === Caveats === diff --git a/includes/SpecialStatistics.php b/includes/SpecialStatistics.php index 73e6eb29ee..8706e8b60d 100644 --- a/includes/SpecialStatistics.php +++ b/includes/SpecialStatistics.php @@ -9,9 +9,11 @@ * constructor */ function wfSpecialStatistics() { - global $wgUser, $wgOut, $wgLang; + global $wgUser, $wgOut, $wgLang, $wgRequest; $fname = 'wfSpecialStatistics'; + $action = $wgRequest->getVal( 'action' ); + $dbr =& wfGetDB( DB_SLAVE ); extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) ); @@ -38,38 +40,45 @@ function wfSpecialStatistics() { } if ( isset( $row->ss_users ) ) { - $totalUsers = $row->ss_users; + $users = $row->ss_users; } else { $sql = "SELECT MAX(user_id) AS total FROM $user"; $res = $dbr->query( $sql, $fname ); $userRow = $dbr->fetchObject( $res ); - $totalUsers = $userRow->total; + $users = $userRow->total; } - - $text = '==' . wfMsg( 'sitestats' ) . "==\n" ; - $text .= wfMsg( 'sitestatstext', - $wgLang->formatNum( $total ), - $wgLang->formatNum( $good ), - $wgLang->formatNum( $views ), - $wgLang->formatNum( $edits ), - $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ), - $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) ); - - $text .= "\n==" . wfMsg( 'userstats' ) . "==\n"; - $sql = "SELECT COUNT(*) AS total FROM $user_groups WHERE ug_group='sysop'"; $res = $dbr->query( $sql, $fname ); $row = $dbr->fetchObject( $res ); $admins = $row->total; - - $text .= wfMsg( 'userstatstext', - $wgLang->formatNum( $totalUsers ), - $wgLang->formatNum( $admins ), - '[[' . wfMsg( 'administrators' ) . ']]', - // should logically be after #admins, danm backwards compatability! - $wgLang->formatNum( round( $admins / $total * 100, 2 ) ) - ); - $wgOut->addWikiText( $text ); + + if ($action == 'raw') { + $wgOut->disable(); + header( 'Pragma: nocache' ); + echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins\n"; + return; + } else { + $text = '==' . wfMsg( 'sitestats' ) . "==\n" ; + $text .= wfMsg( 'sitestatstext', + $wgLang->formatNum( $total ), + $wgLang->formatNum( $good ), + $wgLang->formatNum( $views ), + $wgLang->formatNum( $edits ), + $wgLang->formatNum( sprintf( '%.2f', $total ? $edits / $total : 0 ) ), + $wgLang->formatNum( sprintf( '%.2f', $edits ? $views / $edits : 0 ) ) ); + + $text .= "\n==" . wfMsg( 'userstats' ) . "==\n"; + + $text .= wfMsg( 'userstatstext', + $wgLang->formatNum( $users ), + $wgLang->formatNum( $admins ), + '[[' . wfMsg( 'administrators' ) . ']]', + // should logically be after #admins, danm backwards compatability! + $wgLang->formatNum( round( $admins / $total * 100, 2 ) ) + ); + + $wgOut->addWikiText( $text ); + } } ?> -- 2.20.1