2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2005-04-12 02:07:16 +00:00
|
|
|
* See deferred.txt
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
|
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
2004-09-03 23:00:01 +00:00
|
|
|
* @package MediaWiki
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2003-04-14 23:10:40 +00:00
|
|
|
class SiteStatsUpdate {
|
|
|
|
|
|
2005-06-19 00:21:49 +00:00
|
|
|
var $mViews, $mEdits, $mGood, $mPages, $mUsers;
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2005-06-19 00:21:49 +00:00
|
|
|
function SiteStatsUpdate( $views, $edits, $good, $pages = 0, $users = 0 ) {
|
2003-04-14 23:10:40 +00:00
|
|
|
$this->mViews = $views;
|
|
|
|
|
$this->mEdits = $edits;
|
|
|
|
|
$this->mGood = $good;
|
2005-06-19 00:21:49 +00:00
|
|
|
$this->mPages = $pages;
|
|
|
|
|
$this->mUsers = $users;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-06-19 00:21:49 +00:00
|
|
|
function appendUpdate( &$sql, $field, $delta ) {
|
|
|
|
|
if ( $delta ) {
|
|
|
|
|
if ( $sql ) {
|
|
|
|
|
$sql .= ',';
|
|
|
|
|
}
|
|
|
|
|
if ( $delta < 0 ) {
|
|
|
|
|
$sql .= "$field=$field-1";
|
|
|
|
|
} else {
|
|
|
|
|
$sql .= "$field=$field+1";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
function doUpdate() {
|
2005-06-19 00:21:49 +00:00
|
|
|
global $wgDBname;
|
|
|
|
|
$fname = 'SiteStatsUpdate::doUpdate';
|
|
|
|
|
$dbw =& wfGetDB( DB_MASTER );
|
|
|
|
|
|
|
|
|
|
# First retrieve the row just to find out which schema we're in
|
|
|
|
|
$row = $dbw->selectRow( 'site_stats', '*', false, $fname );
|
|
|
|
|
|
|
|
|
|
$updates = '';
|
|
|
|
|
|
|
|
|
|
$this->appendUpdate( $updates, 'ss_total_views', $this->mViews );
|
|
|
|
|
$this->appendUpdate( $updates, 'ss_total_edits', $this->mEdits );
|
|
|
|
|
$this->appendUpdate( $updates, 'ss_good_articles', $this->mGood );
|
|
|
|
|
|
|
|
|
|
if ( isset( $row->ss_total_pages ) ) {
|
|
|
|
|
# Update schema if required
|
|
|
|
|
if ( $row->ss_total_pages == -1 && !$this->mViews ) {
|
|
|
|
|
$dbr =& wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
|
|
|
|
|
extract( $dbr->tableNames( 'page', 'user' ) );
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT COUNT(page_namespace) AS total FROM $page";
|
|
|
|
|
$res = $dbr->query( $sql, $fname );
|
|
|
|
|
$pageRow = $dbr->fetchObject( $res );
|
|
|
|
|
$pages = $pageRow->total + $this->mPages;
|
|
|
|
|
|
|
|
|
|
$sql = "SELECT COUNT(user_id) AS total FROM $user";
|
|
|
|
|
$res = $dbr->query( $sql, $fname );
|
|
|
|
|
$userRow = $dbr->fetchObject( $res );
|
|
|
|
|
$users = $userRow->total + $this->mUsers;
|
|
|
|
|
|
|
|
|
|
if ( $updates ) {
|
|
|
|
|
$updates .= ',';
|
|
|
|
|
}
|
|
|
|
|
$updates .= "ss_total_pages=$pages, ss_users=$users";
|
|
|
|
|
} else {
|
|
|
|
|
$this->appendUpdate( $updates, 'ss_total_pages', $this->mPages );
|
|
|
|
|
$this->appendUpdate( $updates, 'ss_users', $this->mUsers );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( $updates ) {
|
|
|
|
|
$site_stats = $dbw->tableName( 'site_stats' );
|
|
|
|
|
$sql = "UPDATE $site_stats SET $updates LIMIT 1";
|
|
|
|
|
$dbw->query( $sql, $fname );
|
|
|
|
|
}
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2005-06-19 00:21:49 +00:00
|
|
|
?>
|