X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2FimportImages.php;h=ae70441f1b509ec57a004ed1edd05a0edac5f48d;hb=fb7b3eebeb8de47eb42e8d6ccf204106a2d6d9e4;hp=ba77354934d92ca713f00e87af3bf8b67648bb52;hpb=98d0403f918991c4cf46abc41c89d9b181313684;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/importImages.php b/maintenance/importImages.php index ba77354934..f0c6569ace 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -32,10 +32,10 @@ * @author Mij */ -$optionsWithArgs = array( +$optionsWithArgs = [ 'extensions', 'comment', 'comment-file', 'comment-ext', 'summary', 'user', 'license', 'sleep', 'limit', 'from', 'source-wiki-url', 'timestamp', -); +]; require_once __DIR__ . '/commandLine.inc'; require_once __DIR__ . '/importImages.inc'; $processed = $added = $ignored = $skipped = $overwritten = $failed = 0; @@ -70,9 +70,9 @@ $files = findFiles( $dir, $extensions, isset( $options['search-recursively'] ) ) # Initialise the user for this operation $user = isset( $options['user'] ) ? User::newFromName( $options['user'] ) - : User::newFromName( 'Maintenance script' ); + : User::newSystemUser( 'Maintenance script', [ 'steal' => true ] ); if ( !$user instanceof User ) { - $user = User::newFromName( 'Maintenance script' ); + $user = User::newSystemUser( 'Maintenance script', [ 'steal' => true ] ); } $wgUser = $user; @@ -88,23 +88,23 @@ if ( isset( $options['check-userblock'] ) ) { } # Get --from -wfSuppressWarnings(); +MediaWiki\suppressWarnings(); $from = $options['from']; -wfRestoreWarnings(); +MediaWiki\restoreWarnings(); # Get sleep time. -wfSuppressWarnings(); +MediaWiki\suppressWarnings(); $sleep = $options['sleep']; -wfRestoreWarnings(); +MediaWiki\restoreWarnings(); if ( $sleep ) { $sleep = (int)$sleep; } # Get limit number -wfSuppressWarnings(); +MediaWiki\suppressWarnings(); $limit = $options['limit']; -wfRestoreWarnings(); +MediaWiki\restoreWarnings(); if ( $limit ) { $limit = (int)$limit; @@ -136,7 +136,7 @@ $count = count( $files ); if ( $count > 0 ) { foreach ( $files as $file ) { - $base = wfBaseName( $file ); + $base = UtfNormal\Validator::cleanUp( wfBaseName( $file ) ); # Validate a title $title = Title::makeTitleSafe( NS_FILE, $base ); @@ -177,7 +177,7 @@ if ( $count > 0 ) { if ( isset( $options['skip-dupes'] ) ) { $repo = $image->getRepo(); # XXX: we end up calculating this again when actually uploading. that sucks. - $sha1 = File::sha1Base36( $file ); + $sha1 = FSFile::getSha1Base36FromPath( $file ); $dupes = $repo->findBySha1( $sha1 ); @@ -241,12 +241,12 @@ if ( $count > 0 ) { } else { $props = FSFile::getPropsFromPath( $file ); $flags = 0; - $publishOptions = array(); + $publishOptions = []; $handler = MediaHandler::getHandler( $props['mime'] ); if ( $handler ) { $publishOptions['headers'] = $handler->getStreamHeaders( $props['metadata'] ); } else { - $publishOptions['headers'] = array(); + $publishOptions['headers'] = []; } $archive = $image->publish( $file, $flags, $publishOptions ); if ( !$archive->isGood() ) { @@ -290,25 +290,24 @@ if ( $count > 0 ) { } if ( $doProtect ) { - # Protect the file - echo "\nWaiting for slaves...\n"; - // Wait for slaves. - sleep( 2.0 ); # Why this sleep? - wfWaitForSlaves(); - - echo "\nSetting image restrictions ... "; - - $cascade = false; - $restrictions = array(); - foreach ( $title->getRestrictionTypes() as $type ) { - $restrictions[$type] = $protectLevel; - } + # Protect the file + echo "\nWaiting for slaves...\n"; + // Wait for slaves. + sleep( 2.0 ); # Why this sleep? + wfWaitForSlaves(); + + echo "\nSetting image restrictions ... "; + + $cascade = false; + $restrictions = []; + foreach ( $title->getRestrictionTypes() as $type ) { + $restrictions[$type] = $protectLevel; + } - $page = WikiPage::factory( $title ); - $status = $page->doUpdateRestrictions( $restrictions, array(), $cascade, '', $user ); - echo ( $status->isOK() ? 'done' : 'failed' ) . "\n"; + $page = WikiPage::factory( $title ); + $status = $page->doUpdateRestrictions( $restrictions, [], $cascade, '', $user ); + echo ( $status->isOK() ? 'done' : 'failed' ) . "\n"; } - } else { echo "failed. (at recordUpload stage)\n"; $svar = 'failed'; @@ -328,14 +327,21 @@ if ( $count > 0 ) { # Print out some statistics echo "\n"; - foreach ( array( 'count' => 'Found', 'limit' => 'Limit', 'ignored' => 'Ignored', - 'added' => 'Added', 'skipped' => 'Skipped', 'overwritten' => 'Overwritten', - 'failed' => 'Failed' ) as $var => $desc ) { + foreach ( + [ + 'count' => 'Found', + 'limit' => 'Limit', + 'ignored' => 'Ignored', + 'added' => 'Added', + 'skipped' => 'Skipped', + 'overwritten' => 'Overwritten', + 'failed' => 'Failed' + ] as $var => $desc + ) { if ( $$var > 0 ) { echo "{$desc}: {$$var}\n"; } } - } else { echo "No suitable files could be found for import.\n"; }