$user = User::newFromName( 'Maintenance script' );
$wgUser = $user;
+ # Get block check. If a value is given, this specified how often the check is performed
+ if ( isset( $options['check-userblock'] ) ) {
+ if ( !$options['check-userblock'] ) $checkUserBlock = 1;
+ else $checkUserBlock = (int)$options['check-userblock'];
+ } else {
+ $checkUserBlock = false;
+ }
+
# Get --from
$from = @$options['from'];
if ( $limit ) $limit = (int)$limit;
# Get the upload comment
- $comment = 'Importing image file';
+ $comment = NULL;
if ( isset( $options['comment-file'] ) ) {
$comment = file_get_contents( $options['comment-file'] );
}
}
+ if ( $checkUserBlock && ( ( $processed % $checkUserBlock ) == 0 ) ) {
+ $user->clearInstanceCache( 'name' ); //reload from DB!
+ if ( $user->isBlocked() ) {
+ echo( $user->getName() . " was blocked! Aborting.\n" );
+ break;
+ }
+ }
+
# Check existence
$image = wfLocalFile( $title );
if( $image->exists() ) {
continue;
}
} else {
+ if ( isset( $options['skip-dupes'] ) ) {
+ $repo = $image->getRepo();
+ $sha1 = File::sha1Base36( $file ); #XXX: we end up calculating this again when actually uploading. that sucks.
+
+ $dupes = $repo->findBySha1( $sha1 );
+
+ if ( $dupes ) {
+ echo( "{$base} already exists as " . $dupes[0]->getName() . ", skipping\n" );
+ $skipped++;
+ continue;
+ }
+ }
+
echo( "Importing {$base}..." );
$svar = 'added';
}
if ( $commentExt ) {
$f = findAuxFile( $file, $commentExt );
if ( !$f ) {
- echo( " No comment file with extension {$commentExt} found for {$file}, using default comment. " );
+ echo( " No comment file with extension {$commentExt} found for {$file}. " );
+ $commentText = $comment;
} else {
$commentText = file_get_contents( $f );
if ( !$f ) {
- echo( " Failed to load comment file {$f}, using default comment. " );
+ echo( " Failed to load comment file {$f}. " );
+ $commentText = $comment;
+ } else if ( $comment ) {
+ $commentText = trim( $commentText ) . "\n\n" . trim( $comment );
}
}
-
- if ( $commentText && $comment ) {
- $commentText = trim( $commentText ) . "\n\n" . trim( $comment );
- }
}
if ( !$commentText ) {
$commentText = $comment;
}
+ if ( !$commentText ) {
+ $commentText = 'Importing image file';
+ }
+
# Import the file
if ( isset( $options['dry'] ) ) {
echo( " publishing {$file}... " );
echo( $reason . "\n" );
}
- echo <<<END
+ echo <<<TEXT
Imports images and other media files into the wiki
USAGE: php importImages.php [options] <dir>
--limit=<num> Limit the number of images to process. Ignored or skipped images are not counted.
--from=<name> Ignore all files until the one with the given name. Useful for resuming
aborted imports. <name> should be the file's canonical database form.
+--skip-dupes Skip images that were already uploaded under a different name (check SHA1)
--sleep=<sec> Sleep between files. Useful mostly for debugging.
--user=<username> Set username of uploader, default 'Maintenance script'
+--check-userblock Check if the user got blocked during import.
--comment=<text> Set upload summary comment, default 'Importing image file'.
--comment-file=<file> Set upload summary comment the the content of <file>.
--comment-ext=<ext> Causes the comment for each file to be loaded from a file with the same name
--protect=<protect> Specify the protect value (autoconfirmed,sysop)
--unprotect Unprotects all uploaded images
-END;
+TEXT;
exit(1);
-}
\ No newline at end of file
+}