Merge "Remove Revision::getRevisionText from migrateArchiveText"
[lhc/web/wiklou.git] / maintenance / importImages.php
index e4d1f09..0c4ff0a 100644 (file)
  * @author Mij <mij@bitchx.it>
  */
 
-use MediaWiki\MediaWikiServices;
-
 require_once __DIR__ . '/Maintenance.php';
 
+use MediaWiki\MediaWikiServices;
+
 class ImportImages extends Maintenance {
 
        public function __construct() {
@@ -127,6 +127,8 @@ class ImportImages extends Maintenance {
        public function execute() {
                global $wgFileExtensions, $wgUser, $wgRestrictionLevels;
 
+               $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+
                $processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
 
                $this->output( "Importing Files\n\n" );
@@ -198,7 +200,8 @@ class ImportImages extends Maintenance {
                                $title = Title::makeTitleSafe( NS_FILE, $base );
                                if ( !is_object( $title ) ) {
                                        $this->output(
-                                               "{$base} could not be imported; a valid title cannot be produced\n" );
+                                               "{$base} could not be imported; a valid title cannot be produced\n"
+                                       );
                                        continue;
                                }
 
@@ -213,10 +216,12 @@ class ImportImages extends Maintenance {
 
                                if ( $checkUserBlock && ( ( $processed % $checkUserBlock ) == 0 ) ) {
                                        $user->clearInstanceCache( 'name' ); // reload from DB!
-                                       // @TODO Use PermissionManager::isBlockedFrom() instead.
-                                       if ( $user->getBlock() ) {
-                                               $this->output( $user->getName() . " was blocked! Aborting.\n" );
-                                               break;
+                                       if ( $permissionManager->isBlockedFrom( $user, $title ) ) {
+                                               $this->output(
+                                                       "{$user->getName()} is blocked from {$title->getPrefixedText()}! skipping.\n"
+                                               );
+                                               $skipped++;
+                                               continue;
                                        }
                                }
 
@@ -242,7 +247,8 @@ class ImportImages extends Maintenance {
 
                                                if ( $dupes ) {
                                                        $this->output(
-                                                               "{$base} already exists as {$dupes[0]->getName()}, skipping\n" );
+                                                               "{$base} already exists as {$dupes[0]->getName()}, skipping\n"
+                                                       );
                                                        $skipped++;
                                                        continue;
                                                }
@@ -270,7 +276,8 @@ class ImportImages extends Maintenance {
                                                if ( $wgUser === false ) {
                                                        # user does not exist in target wiki
                                                        $this->output(
-                                                               "failed: user '$real_user' does not exist in target wiki." );
+                                                               "failed: user '$real_user' does not exist in target wiki."
+                                                       );
                                                        continue;
                                                }
                                        }
@@ -287,7 +294,8 @@ class ImportImages extends Maintenance {
                                                        $commentText = file_get_contents( $f );
                                                        if ( !$commentText ) {
                                                                $this->output(
-                                                                       " Failed to load comment file {$f}, using default comment. " );
+                                                                       " Failed to load comment file {$f}, using default comment. "
+                                                               );
                                                        }
                                                }
                                        }
@@ -318,7 +326,7 @@ class ImportImages extends Maintenance {
                                        $archive = $image->publish( $file, $flags, $publishOptions );
                                        if ( !$archive->isGood() ) {
                                                $this->output( "failed. (" .
-                                                        $archive->getWikiText( false, false, 'en' ) .
+                                                        $archive->getMessage( false, false, 'en' )->text() .
                                                         ")\n" );
                                                $failed++;
                                                continue;
@@ -332,7 +340,6 @@ class ImportImages extends Maintenance {
 
                                if ( $this->hasOption( 'dry' ) ) {
                                        $this->output( "done.\n" );
-                                       // @phan-suppress-next-line PhanUndeclaredMethod
                                } elseif ( $image->recordUpload2(
                                        $archive->value,
                                        $summary,
@@ -358,7 +365,7 @@ class ImportImages extends Maintenance {
                                                # Protect the file
                                                $this->output( "\nWaiting for replica DBs...\n" );
                                                // Wait for replica DBs.
-                                               sleep( 2.0 ); # Why this sleep?
+                                               sleep( 2 ); # Why this sleep?
                                                wfWaitForSlaves();
 
                                                $this->output( "\nSetting image restrictions ... " );