summaryrefslogtreecommitdiff
path: root/includes/SiteStats.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/SiteStats.php')
-rw-r--r--includes/SiteStats.php53
1 files changed, 44 insertions, 9 deletions
diff --git a/includes/SiteStats.php b/includes/SiteStats.php
index e2774a14..e320a196 100644
--- a/includes/SiteStats.php
+++ b/includes/SiteStats.php
@@ -2,7 +2,6 @@
/**
* Static accessor class for site_stats and related things
- * @package MediaWiki
*/
class SiteStats {
static $row, $loaded = false;
@@ -18,17 +17,54 @@ class SiteStats {
return;
}
- $dbr =& wfGetDB( DB_SLAVE );
- self::$row = $dbr->selectRow( 'site_stats', '*', false, __METHOD__ );
+ self::$row = self::loadAndLazyInit();
# This code is somewhat schema-agnostic, because I'm changing it in a minor release -- TS
if ( !isset( self::$row->ss_total_pages ) && self::$row->ss_total_pages == -1 ) {
# Update schema
$u = new SiteStatsUpdate( 0, 0, 0 );
$u->doUpdate();
+ $dbr = wfGetDB( DB_SLAVE );
self::$row = $dbr->selectRow( 'site_stats', '*', false, __METHOD__ );
}
}
+
+ static function loadAndLazyInit() {
+ wfDebug( __METHOD__ . ": reading site_stats from slave\n" );
+ $row = self::doLoad( wfGetDB( DB_SLAVE ) );
+
+ if( $row === false ) {
+ // Might have just been initialzed during this request?
+ wfDebug( __METHOD__ . ": site_stats missing on slave\n" );
+ $row = self::doLoad( wfGetDB( DB_MASTER ) );
+ }
+
+ if( $row === false ) {
+ // Normally the site_stats table is initialized at install time.
+ // Some manual construction scenarios may leave the table empty,
+ // however, for instance when importing from a dump into a clean
+ // schema with mwdumper.
+ wfDebug( __METHOD__ . ": initializing empty site_stats\n" );
+
+ global $IP;
+ require_once "$IP/maintenance/initStats.inc";
+
+ ob_start();
+ wfInitStats();
+ ob_end_clean();
+
+ $row = self::doLoad( wfGetDB( DB_MASTER ) );
+ }
+
+ if( $row === false ) {
+ wfDebug( __METHOD__ . ": init of site_stats failed o_O\n" );
+ }
+ return $row;
+ }
+
+ static function doLoad( $db ) {
+ return $db->selectRow( 'site_stats', '*', false, __METHOD__ );
+ }
static function views() {
self::load();
@@ -62,7 +98,7 @@ class SiteStats {
static function admins() {
if ( !isset( self::$admins ) ) {
- $dbr =& wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
self::$admins = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ );
}
return self::$admins;
@@ -71,7 +107,7 @@ class SiteStats {
static function pagesInNs( $ns ) {
wfProfileIn( __METHOD__ );
if( !isset( self::$pageCount[$ns] ) ) {
- $dbr =& wfGetDB( DB_SLAVE );
+ $dbr = wfGetDB( DB_SLAVE );
$pageCount[$ns] = (int)$dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $ns ), __METHOD__ );
}
wfProfileOut( __METHOD__ );
@@ -83,13 +119,12 @@ class SiteStats {
/**
*
- * @package MediaWiki
*/
class SiteStatsUpdate {
var $mViews, $mEdits, $mGood, $mPages, $mUsers;
- function SiteStatsUpdate( $views, $edits, $good, $pages = 0, $users = 0 ) {
+ function __construct( $views, $edits, $good, $pages = 0, $users = 0 ) {
$this->mViews = $views;
$this->mEdits = $edits;
$this->mGood = $good;
@@ -112,7 +147,7 @@ class SiteStatsUpdate {
function doUpdate() {
$fname = 'SiteStatsUpdate::doUpdate';
- $dbw =& wfGetDB( DB_MASTER );
+ $dbw = wfGetDB( DB_MASTER );
# First retrieve the row just to find out which schema we're in
$row = $dbw->selectRow( 'site_stats', '*', false, $fname );
@@ -126,7 +161,7 @@ class SiteStatsUpdate {
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') );
+ $dbr = wfGetDB( DB_SLAVE, array( 'SpecialStatistics', 'vslow') );
list( $page, $user ) = $dbr->tableNamesN( 'page', 'user' );
$sql = "SELECT COUNT(page_namespace) AS total FROM $page";