Merge "Tell users how they can force a maintenance script to run again."
[lhc/web/wiklou.git] / maintenance / rebuildImages.php
index 966864e..dfce202 100644 (file)
@@ -32,6 +32,7 @@
 
 require_once __DIR__ . '/Maintenance.php';
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IMaintainableDatabase;
 
 /**
@@ -63,7 +64,8 @@ class ImageBuilder extends Maintenance {
                $this->dbw = $this->getDB( DB_MASTER );
                $this->dryrun = $this->hasOption( 'dry-run' );
                if ( $this->dryrun ) {
-                       $GLOBALS['wgReadOnly'] = 'Dry run mode, image upgrades are suppressed';
+                       MediaWiki\MediaWikiServices::getInstance()->getReadOnlyMode()
+                               ->setReason( 'Dry run mode, image upgrades are suppressed' );
                }
 
                if ( $this->hasOption( 'missing' ) ) {
@@ -124,12 +126,14 @@ class ImageBuilder extends Maintenance {
                flush();
        }
 
-       function buildTable( $table, $key, $callback ) {
+       function buildTable( $table, $key, $queryInfo, $callback ) {
                $count = $this->dbw->selectField( $table, 'count(*)', '', __METHOD__ );
                $this->init( $count, $table );
                $this->output( "Processing $table...\n" );
 
-               $result = $this->getDB( DB_REPLICA )->select( $table, '*', [], __METHOD__ );
+               $result = $this->getDB( DB_REPLICA )->select(
+                       $queryInfo['tables'], $queryInfo['fields'], [], __METHOD__, [], $queryInfo['joins']
+               );
 
                foreach ( $result as $row ) {
                        $update = call_user_func( $callback, $row, null );
@@ -144,7 +148,7 @@ class ImageBuilder extends Maintenance {
 
        function buildImage() {
                $callback = [ $this, 'imageCallback' ];
-               $this->buildTable( 'image', 'img_name', $callback );
+               $this->buildTable( 'image', 'img_name', LocalFile::getQueryInfo(), $callback );
        }
 
        function imageCallback( $row, $copy ) {
@@ -156,7 +160,8 @@ class ImageBuilder extends Maintenance {
        }
 
        function buildOldImage() {
-               $this->buildTable( 'oldimage', 'oi_archive_name', [ $this, 'oldimageCallback' ] );
+               $this->buildTable( 'oldimage', 'oi_archive_name', OldLocalFile::getQueryInfo(),
+                       [ $this, 'oldimageCallback' ] );
        }
 
        function oldimageCallback( $row, $copy ) {
@@ -189,11 +194,10 @@ class ImageBuilder extends Maintenance {
        }
 
        function addMissingImage( $filename, $fullpath ) {
-               global $wgContLang;
-
                $timestamp = $this->dbw->timestamp( $this->getRepo()->getFileTimestamp( $fullpath ) );
+               $services = MediaWikiServices::getInstance();
 
-               $altname = $wgContLang->checkTitleEncoding( $filename );
+               $altname = $services->getContentLanguage()->checkTitleEncoding( $filename );
                if ( $altname != $filename ) {
                        if ( $this->dryrun ) {
                                $filename = $altname;
@@ -210,7 +214,7 @@ class ImageBuilder extends Maintenance {
                        return;
                }
                if ( !$this->dryrun ) {
-                       $file = wfLocalFile( $filename );
+                       $file = $services->getRepoGroup()->getLocalRepo()->newFile( $filename );
                        if ( !$file->recordUpload(
                                '',
                                '(recovered file, missing upload log entry)',
@@ -229,5 +233,5 @@ class ImageBuilder extends Maintenance {
        }
 }
 
-$maintClass = 'ImageBuilder';
+$maintClass = ImageBuilder::class;
 require_once RUN_MAINTENANCE_IF_MAIN;