Index: trunk/phase3/includes/SiteStats.php |
— | — | @@ -32,19 +32,19 @@ |
33 | 33 | static function loadAndLazyInit() { |
34 | 34 | wfDebug( __METHOD__ . ": reading site_stats from slave\n" ); |
35 | 35 | $row = self::doLoad( wfGetDB( DB_SLAVE ) ); |
36 | | - |
37 | | - if( $row === false ) { |
38 | | - // Might have just been initialzed during this request? |
39 | | - wfDebug( __METHOD__ . ": site_stats missing on slave\n" ); |
| 36 | + |
| 37 | + if( !self::isSane( $row ) ) { |
| 38 | + // Might have just been initialized during this request? Underflow? |
| 39 | + wfDebug( __METHOD__ . ": site_stats damaged or missing on slave\n" ); |
40 | 40 | $row = self::doLoad( wfGetDB( DB_MASTER ) ); |
41 | 41 | } |
42 | 42 | |
43 | | - if( $row === false ) { |
| 43 | + if( !self::isSane( $row ) ) { |
44 | 44 | // Normally the site_stats table is initialized at install time. |
45 | | - // Some manual construction scenarios may leave the table empty, |
46 | | - // however, for instance when importing from a dump into a clean |
47 | | - // schema with mwdumper. |
48 | | - wfDebug( __METHOD__ . ": initializing empty site_stats\n" ); |
| 45 | + // Some manual construction scenarios may leave the table empty or |
| 46 | + // broken, however, for instance when importing from a dump into a |
| 47 | + // clean schema with mwdumper. |
| 48 | + wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" ); |
49 | 49 | |
50 | 50 | global $IP; |
51 | 51 | require_once "$IP/maintenance/initStats.inc"; |
— | — | @@ -56,8 +56,8 @@ |
57 | 57 | $row = self::doLoad( wfGetDB( DB_MASTER ) ); |
58 | 58 | } |
59 | 59 | |
60 | | - if( $row === false ) { |
61 | | - wfDebug( __METHOD__ . ": init of site_stats failed o_O\n" ); |
| 60 | + if( !self::isSane( $row ) ) { |
| 61 | + wfDebug( __METHOD__ . ": site_stats persistently nonsensical o_O\n" ); |
62 | 62 | } |
63 | 63 | return $row; |
64 | 64 | } |
— | — | @@ -114,6 +114,27 @@ |
115 | 115 | return $pageCount[$ns]; |
116 | 116 | } |
117 | 117 | |
| 118 | + /** Is the provided row of site stats sane, or should it be regenerated? */ |
| 119 | + private static function isSane( $row ) { |
| 120 | + if( |
| 121 | + $row === false |
| 122 | + or $row->ss_good_articles < $row->ss_total_pages |
| 123 | + or $row->ss_total_edits < $row->ss_total_pages |
| 124 | + or $row->ss_users < $row->ss_admins |
| 125 | + ) { |
| 126 | + return false; |
| 127 | + } |
| 128 | + // Now check for underflow/overflow |
| 129 | + foreach( array( 'total_views', 'total_edits', 'good_articles', |
| 130 | + 'total_pages', 'users', 'admins', 'images' ) as $member ) { |
| 131 | + if( |
| 132 | + $row->{"ss_$member"} > 2000000000 |
| 133 | + or $row->{"ss_$member"} < 0 |
| 134 | + ) { |
| 135 | + return false; |
| 136 | + } |
| 137 | + } |
| 138 | + } |
118 | 139 | } |
119 | 140 | |
120 | 141 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -308,6 +308,7 @@ |
309 | 309 | * Don't allow retrieving non-JavaScript/CSS pages with "text/css" or "text/javascript" |
310 | 310 | MIME types |
311 | 311 | * (bug 1629) Stop section edit links from being shoved down by other floats |
| 312 | +* (bug 4650) Keep impossibly large/small counts off Special:Statistics |
312 | 313 | |
313 | 314 | == API changes since 1.10 == |
314 | 315 | |