* @ingroup Maintenance
*/
class TableCleanup extends Maintenance {
- protected $defaultParams = array(
+ protected $defaultParams = [
'table' => 'page',
- 'conds' => array(),
+ 'conds' => [],
'index' => 'page_id',
'callback' => 'processRow',
- );
+ ];
protected $dryrun = false;
public $batchSize = 100;
$wgUser = User::newFromName( 'Conversion script' );
$this->output( "Checking for bad titles...\n" );
} else {
- $wgUser = User::newSystemUser( 'Conversion script', array( 'steal' => true ) );
+ $wgUser = User::newSystemUser( 'Conversion script', [ 'steal' => true ] );
$this->output( "Checking and fixing bad titles...\n" );
}
$this->runTable( $this->defaultParams );
* @throws MWException
*/
public function runTable( $params ) {
- $dbr = wfGetDB( DB_SLAVE );
+ $dbr = $this->getDB( DB_SLAVE );
if ( array_diff( array_keys( $params ),
- array( 'table', 'conds', 'index', 'callback' ) )
+ [ 'table', 'conds', 'index', 'callback' ] )
) {
throw new MWException( __METHOD__ . ': Missing parameter ' . implode( ', ', $params ) );
}
$this->output( "Processing $table...\n" );
$index = (array)$params['index'];
- $indexConds = array();
- $options = array(
+ $indexConds = [];
+ $options = [
'ORDER BY' => implode( ',', $index ),
'LIMIT' => $this->batchSize
- );
- $callback = array( $this, $params['callback'] );
+ ];
+ $callback = [ $this, $params['callback'] ];
while ( true ) {
$conds = array_merge( $params['conds'], $indexConds );
$nextCond = "$field > $encValue OR ($field = $encValue AND ($nextCond))";
}
}
- $indexConds = array( $nextCond );
+ $indexConds = [ $nextCond ];
}
$this->output( "Finished $table... $this->updated of $this->processed rows updated\n" );
return sprintf( "\\x%02x", ord( $matches[1] ) );
}
}
-
-class TableCleanupTest extends TableCleanup {
- function processRow( $row ) {
- $this->progress( mt_rand( 0, 1 ) );
- }
-}
-