Merge "Make some whitespace fixes to importImages maintenance script"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Thu, 5 Sep 2019 19:51:23 +0000 (19:51 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Thu, 5 Sep 2019 19:51:23 +0000 (19:51 +0000)
1  2 
maintenance/importImages.php

   * @author Mij <mij@bitchx.it>
   */
  
 -use MediaWiki\MediaWikiServices;
 -
  require_once __DIR__ . '/Maintenance.php';
  
 +use MediaWiki\MediaWikiServices;
 +
  class ImportImages extends Maintenance {
  
        public function __construct() {
        public function execute() {
                global $wgFileExtensions, $wgUser, $wgRestrictionLevels;
  
 +              $permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
 +
                $processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
  
                $this->output( "Importing Files\n\n" );
                                $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;
                                }
  
  
                                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;
                                        }
                                }
  
  
                                                if ( $dupes ) {
                                                        $this->output(
-                                                               "{$base} already exists as {$dupes[0]->getName()}, skipping\n" );
+                                                               "{$base} already exists as {$dupes[0]->getName()}, skipping\n"
+                                                       );
                                                        $skipped++;
                                                        continue;
                                                }
                                                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;
                                                }
                                        }
                                                        $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. "
+                                                               );
                                                        }
                                                }
                                        }