Index: branches/maintenance-work/maintenance/initStats.inc |
— | — | @@ -1,57 +0,0 @@ |
2 | | -<?php |
3 | | -/** |
4 | | - * @file |
5 | | - * @ingroup Maintenance |
6 | | - */ |
7 | | - |
8 | | -function wfInitStats( $options=array() ) { |
9 | | - $dbr = wfGetDB( DB_SLAVE ); |
10 | | - |
11 | | - wfOut( "Counting total edits..." ); |
12 | | - $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ ); |
13 | | - $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ ); |
14 | | - wfOut( "{$edits}\nCounting number of articles..." ); |
15 | | - |
16 | | - global $wgContentNamespaces; |
17 | | - $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ ); |
18 | | - wfOut( "{$good}\nCounting total pages..." ); |
19 | | - |
20 | | - $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ ); |
21 | | - wfOut( "{$pages}\nCounting number of users..." ); |
22 | | - |
23 | | - $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ ); |
24 | | - wfOut( "{$users}\nCounting number of admins..." ); |
25 | | - |
26 | | - $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ ); |
27 | | - wfOut( "{$admin}\nCounting number of images..." ); |
28 | | - |
29 | | - $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ ); |
30 | | - wfOut( "{$image}\n" ); |
31 | | - |
32 | | - if( !isset( $options['noviews'] ) ) { |
33 | | - wfOut( "Counting total page views..." ); |
34 | | - $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ ); |
35 | | - wfOut( "{$views}\n" ); |
36 | | - } |
37 | | - |
38 | | - wfOut( "\nUpdating site statistics..." ); |
39 | | - |
40 | | - $dbw = wfGetDB( DB_MASTER ); |
41 | | - $values = array( 'ss_total_edits' => $edits, |
42 | | - 'ss_good_articles' => $good, |
43 | | - 'ss_total_pages' => $pages, |
44 | | - 'ss_users' => $users, |
45 | | - 'ss_admins' => $admin, |
46 | | - 'ss_images' => $image ); |
47 | | - $conds = array( 'ss_row_id' => 1 ); |
48 | | - $views = array( 'ss_total_views' => isset( $views ) ? $views : 0 ); |
49 | | - |
50 | | - if( isset( $options['update'] ) ) { |
51 | | - $dbw->update( 'site_stats', $values, $conds, __METHOD__ ); |
52 | | - } else { |
53 | | - $dbw->delete( 'site_stats', $conds, __METHOD__ ); |
54 | | - $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ ); |
55 | | - } |
56 | | - |
57 | | - wfOut( "done.\n" ); |
58 | | -} |
Index: branches/maintenance-work/maintenance/initStats.php |
— | — | @@ -9,23 +9,22 @@ |
10 | 10 | * @author Rob Church <robchur@gmail.com> |
11 | 11 | * @licence GNU General Public Licence 2.0 or later |
12 | 12 | */ |
13 | | - |
14 | | -$options = array( 'help', 'update', 'noviews' ); |
15 | | -require_once( 'commandLine.inc' ); |
16 | | -echo( "Refresh Site Statistics\n\n" ); |
17 | 13 | |
18 | | -if( isset( $options['help'] ) ) { |
19 | | - showHelp(); |
20 | | - exit(1); |
21 | | -} |
| 14 | +require_once( "Maintenance.php" ); |
22 | 15 | |
23 | | -require "$IP/maintenance/initStats.inc"; |
24 | | -wfInitStats( $options ); |
| 16 | +class InitStats extends Maintenance { |
| 17 | + public function __construct() { |
| 18 | + parent::__construct(); |
| 19 | + $this->mDescription = "Re-initialise the site statistics tables"; |
| 20 | + $this->addParam( 'update', 'Update the existing statistics (preserves the ss_total_views field)' ); |
| 21 | + $this->addParam( 'noviews', "Don't update the page view counter" ); |
| 22 | + } |
25 | 23 | |
26 | | -function showHelp() { |
27 | | - echo( "Re-initialise the site statistics tables.\n\n" ); |
28 | | - echo( "Usage: php initStats.php [--update|--noviews]\n\n" ); |
29 | | - echo( " --update : Update the existing statistics (preserves the ss_total_views field)\n" ); |
30 | | - echo( "--noviews : Don't update the page view counter\n\n" ); |
| 24 | + public function execute() { |
| 25 | + $this->output( "Refresh Site Statistics\n\n" ); |
| 26 | + SiteStats::init( $this->hasOption('update'), $this->hasOption('noviews') ); |
| 27 | + } |
31 | 28 | } |
32 | 29 | |
| 30 | +$maintClass = "InitStats"; |
| 31 | +require_once( DO_MAINTENANCE ); |
Index: branches/maintenance-work/maintenance/updaters.inc |
— | — | @@ -1038,10 +1038,7 @@ |
1039 | 1039 | wfOut( "ok.\n" ); |
1040 | 1040 | return; |
1041 | 1041 | } |
1042 | | - |
1043 | | - global $IP; |
1044 | | - require_once "$IP/maintenance/initStats.inc"; |
1045 | | - wfInitStats(); |
| 1042 | + SiteStats::init( false ); |
1046 | 1043 | } |
1047 | 1044 | |
1048 | 1045 | function do_active_users_init() { |
Index: branches/maintenance-work/includes/SiteStats.php |
— | — | @@ -49,11 +49,8 @@ |
50 | 50 | // clean schema with mwdumper. |
51 | 51 | wfDebug( __METHOD__ . ": initializing damaged or missing site_stats\n" ); |
52 | 52 | |
53 | | - global $IP; |
54 | | - require_once "$IP/maintenance/initStats.inc"; |
55 | | - |
56 | 53 | ob_start(); |
57 | | - wfInitStats(); |
| 54 | + self::init( false ); |
58 | 55 | ob_end_clean(); |
59 | 56 | |
60 | 57 | $row = self::doLoad( wfGetDB( DB_MASTER ) ); |
— | — | @@ -177,6 +174,63 @@ |
178 | 175 | } |
179 | 176 | return true; |
180 | 177 | } |
| 178 | + |
| 179 | + /** |
| 180 | + * Ported from initStats.inc. |
| 181 | + * @param $update bool Whether to update the current stats write fresh |
| 182 | + * @param $noViews bool When true, do not update the number of page views |
| 183 | + */ |
| 184 | + function init( $update, $noViews = false ) { |
| 185 | + $dbr = wfGetDB( DB_SLAVE ); |
| 186 | + |
| 187 | + wfOut( "Counting total edits..." ); |
| 188 | + $edits = $dbr->selectField( 'revision', 'COUNT(*)', '', __METHOD__ ); |
| 189 | + $edits += $dbr->selectField( 'archive', 'COUNT(*)', '', __METHOD__ ); |
| 190 | + wfOut( "{$edits}\nCounting number of articles..." ); |
| 191 | + |
| 192 | + global $wgContentNamespaces; |
| 193 | + $good = $dbr->selectField( 'page', 'COUNT(*)', array( 'page_namespace' => $wgContentNamespaces, 'page_is_redirect' => 0, 'page_len > 0' ), __METHOD__ ); |
| 194 | + wfOut( "{$good}\nCounting total pages..." ); |
| 195 | + |
| 196 | + $pages = $dbr->selectField( 'page', 'COUNT(*)', '', __METHOD__ ); |
| 197 | + wfOut( "{$pages}\nCounting number of users..." ); |
| 198 | + |
| 199 | + $users = $dbr->selectField( 'user', 'COUNT(*)', '', __METHOD__ ); |
| 200 | + wfOut( "{$users}\nCounting number of admins..." ); |
| 201 | + |
| 202 | + $admin = $dbr->selectField( 'user_groups', 'COUNT(*)', array( 'ug_group' => 'sysop' ), __METHOD__ ); |
| 203 | + wfOut( "{$admin}\nCounting number of images..." ); |
| 204 | + |
| 205 | + $image = $dbr->selectField( 'image', 'COUNT(*)', '', __METHOD__ ); |
| 206 | + wfOut( "{$image}\n" ); |
| 207 | + |
| 208 | + if( !$noViews ) { |
| 209 | + wfOut( "Counting total page views..." ); |
| 210 | + $views = $dbr->selectField( 'page', 'SUM(page_counter)', '', __METHOD__ ); |
| 211 | + wfOut( "{$views}\n" ); |
| 212 | + } |
| 213 | + |
| 214 | + wfOut( "\nUpdating site statistics..." ); |
| 215 | + |
| 216 | + $dbw = wfGetDB( DB_MASTER ); |
| 217 | + $values = array( 'ss_total_edits' => $edits, |
| 218 | + 'ss_good_articles' => $good, |
| 219 | + 'ss_total_pages' => $pages, |
| 220 | + 'ss_users' => $users, |
| 221 | + 'ss_admins' => $admin, |
| 222 | + 'ss_images' => $image ); |
| 223 | + $conds = array( 'ss_row_id' => 1 ); |
| 224 | + $views = array( 'ss_total_views' => isset( $views ) ? $views : 0 ); |
| 225 | + |
| 226 | + if( $update ) { |
| 227 | + $dbw->update( 'site_stats', $values, $conds, __METHOD__ ); |
| 228 | + } else { |
| 229 | + $dbw->delete( 'site_stats', $conds, __METHOD__ ); |
| 230 | + $dbw->insert( 'site_stats', array_merge( $values, $conds, $views ), __METHOD__ ); |
| 231 | + } |
| 232 | + |
| 233 | + wfOut( "done.\n" ); |
| 234 | + } |
181 | 235 | } |
182 | 236 | |
183 | 237 | |