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( "Import Images\n\n" );
+ $this->output( "Importing Files\n\n" );
$dir = $this->getArg( 0 );
$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!
- if ( $user->isBlocked() ) {
- $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;
}
}
# Check existence
- $image = wfLocalFile( $title );
+ $image = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()
+ ->newFile( $title );
if ( $image->exists() ) {
if ( $this->hasOption( 'overwrite' ) ) {
$this->output( "{$base} exists, overwriting..." );
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. "
+ );
}
}
}
$publishOptions = [];
$handler = MediaHandler::getHandler( $props['mime'] );
if ( $handler ) {
- $metadata = Wikimedia\quietCall( 'unserialize', $props['metadata'] );
+ $metadata = \Wikimedia\AtEase\AtEase::quietCall( 'unserialize', $props['metadata'] );
$publishOptions['headers'] = $handler->getContentHeaders( $metadata );
} else {
# 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 ... " );