wiki.techinc.nl/includes/SpecialStatistics.php

87 lines
2.4 KiB
PHP
Raw Normal View History

<?php
/**
2005-06-19 00:21:49 +00:00
*
* @package MediaWiki
* @subpackage SpecialPage
*/
2003-04-14 23:10:40 +00:00
/**
2005-06-19 00:21:49 +00:00
* constructor
*/
function wfSpecialStatistics() {
2005-12-04 18:27:59 +00:00
global $wgOut, $wgLang, $wgRequest;
2005-01-30 21:17:22 +00:00
$fname = 'wfSpecialStatistics';
2003-04-14 23:10:40 +00:00
$action = $wgRequest->getVal( 'action' );
$dbr =& wfGetDB( DB_SLAVE );
extract( $dbr->tableNames( 'page', 'site_stats', 'user', 'user_groups' ) );
2003-04-14 23:10:40 +00:00
$row = $dbr->selectRow( 'site_stats', '*', false, $fname );
2003-04-14 23:10:40 +00:00
$views = $row->ss_total_views;
$edits = $row->ss_total_edits;
$good = $row->ss_good_articles;
$images = $row->ss_images;
2003-04-14 23:10:40 +00:00
2005-06-19 00:21:49 +00:00
# This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
if ( isset( $row->ss_total_pages ) && $row->ss_total_pages == -1 ) {
# Update schema
$u = new SiteStatsUpdate( 0, 0, 0 );
$u->doUpdate();
$row = $dbr->selectRow( 'site_stats', '*', false, $fname );
2005-06-19 00:21:49 +00:00
}
if ( isset( $row->ss_total_pages ) ) {
$total = $row->ss_total_pages;
} else {
$sql = "SELECT COUNT(page_namespace) AS total FROM $page";
$res = $dbr->query( $sql, $fname );
$pageRow = $dbr->fetchObject( $res );
$total = $pageRow->total;
}
if ( isset( $row->ss_users ) ) {
$users = $row->ss_users;
2005-06-19 00:21:49 +00:00
} else {
$sql = "SELECT MAX(user_id) AS total FROM $user";
$res = $dbr->query( $sql, $fname );
$userRow = $dbr->fetchObject( $res );
$users = $userRow->total;
2006-03-11 17:13:49 +00:00
}
2005-06-19 00:21:49 +00:00
$admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), $fname );
$numJobs = $dbr->selectField( 'job', 'COUNT(*)', '', $fname );
2006-01-07 13:31:29 +00:00
if ($action == 'raw') {
$wgOut->disable();
header( 'Pragma: nocache' );
echo "total=$total;good=$good;views=$views;edits=$edits;users=$users;admins=$admins;images=$images\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 ) ),
$wgLang->formatNum( $numJobs ),
$wgLang->formatNum( $images )
);
2006-01-07 13:31:29 +00:00
$text .= "\n==" . wfMsg( 'userstats' ) . "==\n";
2006-01-07 13:31:29 +00:00
$text .= wfMsg( 'userstatstext',
$wgLang->formatNum( $users ),
$wgLang->formatNum( $admins ),
'[[' . wfMsg( 'administrators' ) . ']]',
// should logically be after #admins, danm backwards compatability!
$wgLang->formatNum( sprintf( '%.2f', $admins / $users * 100 ) )
);
2006-01-07 13:31:29 +00:00
$wgOut->addWikiText( $text );
}
2003-04-14 23:10:40 +00:00
}
2005-04-05 10:43:56 +00:00
?>