[bug 37746] string ids for content model and format.
[lhc/web/wiklou.git] / maintenance / cleanupTable.inc
index da0ff88..1c27976 100644 (file)
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
- * @defgroup Wikimedia
+ * @file
  * @ingroup Maintenance
  */
 
-require_once( dirname(__FILE__) . '/Maintenance.php' );
+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 
 class TableCleanup extends Maintenance {
        protected $defaultParams = array(
@@ -43,9 +43,9 @@ class TableCleanup extends Maintenance {
 
        public function execute() {
                global $wgUser;
-               $wgUser->setName( 'Conversion script' );
+               $wgUser = User::newFromName( 'Conversion script' );
                $this->dryrun = $this->hasOption( 'dry-run' );
-               if( $this->dryrun ) {
+               if ( $this->dryrun ) {
                        $this->output( "Checking for bad titles...\n" );
                } else {
                        $this->output( "Checking and fixing bad titles...\n" );
@@ -64,7 +64,7 @@ class TableCleanup extends Maintenance {
        protected function progress( $updated ) {
                $this->updated += $updated;
                $this->processed++;
-               if( $this->processed % $this->reportInterval != 0 ) {
+               if ( $this->processed % $this->reportInterval != 0 ) {
                        return;
                }
                $portion = $this->processed / $this->count;
@@ -75,7 +75,7 @@ class TableCleanup extends Maintenance {
                $estimatedTotalTime = $delta / $portion;
                $eta = $this->startTime + $estimatedTotalTime;
 
-               $this->output( 
+               $this->output(
                        sprintf( "%s %s: %6.2f%% done on %s; ETA %s [%d/%d] %.2f/sec <%.2f%% updated>\n",
                                wfWikiID(),
                                wfTimestamp( TS_DB, intval( $now ) ),
@@ -85,7 +85,7 @@ class TableCleanup extends Maintenance {
                                $this->processed,
                                $this->count,
                                $this->processed / $delta,
-                               $updateRate * 100.0 
+                               $updateRate * 100.0
                        )
                );
                flush();
@@ -95,13 +95,14 @@ class TableCleanup extends Maintenance {
                $dbr = wfGetDB( DB_SLAVE );
 
                if ( array_diff( array_keys( $params ),
-                       array( 'table', 'conds', 'index', 'callback' ) ) ) 
+                       array( 'table', 'conds', 'index', 'callback' ) ) )
                {
-                       throw new MWException( __METHOD__.': Missing parameter ' . implode( ', ', $params ) );
+                       throw new MWException( __METHOD__ . ': Missing parameter ' . implode( ', ', $params ) );
                }
 
                $table = $params['table'];
-               $count = $dbr->selectField( $table, 'count(*)', $params['conds'], __METHOD__ );
+               // count(*) would melt the DB for huge tables, we can estimate here
+               $count = $dbr->estimateRowCount( $table, '*', '', __METHOD__ );
                $this->init( $count, $table );
                $this->output( "Processing $table...\n" );