+
+ self::$loaded = true;
+ }
+
+ static function loadAndLazyInit() {
+ wfDebug( __METHOD__ . ": reading site_stats from slave\n" );
+ $row = self::doLoad( wfGetDB( DB_SLAVE ) );
+
+ if( !self::isSane( $row ) ) {
+ // Might have just been initialized during this request? Underflow?
+ wfDebug( __METHOD__ . ": site_stats damaged or missing on slave\n" );
+ $row = self::doLoad( wfGetDB( DB_MASTER ) );
+ }
+
+ if( !self::isSane( $row ) ) {
+ // Normally the site_stats table is initialized at install time.
+ // Some manual construction scenarios may leave the table empty or
+ // broken, however, for instance when importing from a dump into a
+ // clean schema with mwdumper.
+ wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" );
+
+ global $IP;
+ require_once "$IP/maintenance/initStats.inc";
+
+ ob_start();
+ wfInitStats();
+ ob_end_clean();
+
+ $row = self::doLoad( wfGetDB( DB_MASTER ) );
+ }
+
+ if( !self::isSane( $row ) ) {
+ wfDebug( __METHOD__ . ": site_stats persistently nonsensical o_O\n" );
+ }
+ return $row;
+ }
+
+ static function doLoad( $db ) {
+ return $db->selectRow( 'site_stats', '*', false, __METHOD__ );