Use addDescription() instead of accessing mDescription directly
[lhc/web/wiklou.git] / maintenance / initEditCount.php
index 3ca067c..5d0dcc6 100644 (file)
@@ -1,5 +1,8 @@
 <?php
 /**
+ * Init the user_editcount database field based on the number of rows in the
+ * revision table.
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
 class InitEditCount extends Maintenance {
        public function __construct() {
@@ -30,22 +34,21 @@ class InitEditCount extends Maintenance {
 
 Background mode will be automatically used if the server is MySQL 4.0
 (which does not support subqueries) or if multiple servers are listed
-in $wgDBservers, usually indicating a replication environment.' );
-               $this->mDescription = "Batch-recalculate user_editcount fields from the revision table";
+in the load balancer, usually indicating a replication environment.' );
+               $this->addDescription( 'Batch-recalculate user_editcount fields from the revision table' );
        }
 
        public function execute() {
-               global $wgDBservers;
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
                $user = $dbw->tableName( 'user' );
                $revision = $dbw->tableName( 'revision' );
 
                $dbver = $dbw->getServerVersion();
 
                // Autodetect mode...
-               $backgroundMode = count( $wgDBservers ) > 1 ||
-                       ( $dbw instanceof DatabaseMysql && version_compare( $dbver, '4.1' ) < 0 );
-       
+               $backgroundMode = wfGetLB()->getServerCount() > 1 ||
+                       ( $dbw instanceof DatabaseMysql );
+
                if ( $this->hasOption( 'background' ) ) {
                        $backgroundMode = true;
                } elseif ( $this->hasOption( 'quick' ) ) {
@@ -55,7 +58,7 @@ in $wgDBservers, usually indicating a replication environment.' );
                if ( $backgroundMode ) {
                        $this->output( "Using replication-friendly background mode...\n" );
 
-                       $dbr = wfGetDB( DB_SLAVE );
+                       $dbr = $this->getDB( DB_SLAVE );
                        $chunkSize = 100;
                        $lastUser = $dbr->selectField( 'user', 'MAX(user_id)', '', __METHOD__ );
 
@@ -90,7 +93,7 @@ in $wgDBservers, usually indicating a replication environment.' );
                                        $delta,
                                        $rate ) );
 
-                               wfWaitForSlaves( 10 );
+                               wfWaitForSlaves();
                        }
                } else {
                        // Subselect should work on modern MySQLs etc
@@ -104,4 +107,4 @@ in $wgDBservers, usually indicating a replication environment.' );
 }
 
 $maintClass = "InitEditCount";
-require_once( DO_MAINTENANCE );
+require_once RUN_MAINTENANCE_IF_MAIN;