r57284 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57283‎ | r57284 | r57285 >
Date:09:54, 2 October 2009
Author:daniel
Status:ok
Tags:
Comment:
new options: --limit --sleep --from
Modified paths:
  • /trunk/phase3/maintenance/importImages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importImages.php
@@ -9,10 +9,10 @@
1010 * @author Rob Church <robchur@gmail.com>
1111 */
1212
13 -$optionsWithArgs = array( 'extensions', 'comment', 'comment-file', 'comment-ext', 'user', 'license' );
 13+$optionsWithArgs = array( 'extensions', 'comment', 'comment-file', 'comment-ext', 'user', 'license', 'sleep', 'limit', 'from' );
1414 require_once( dirname(__FILE__) . '/commandLine.inc' );
1515 require_once( 'importImages.inc' );
16 -$added = $skipped = $overwritten = 0;
 16+$processed = $added = $ignored = $skipped = $overwritten = $failed = 0;
1717
1818 echo( "Import Images\n\n" );
1919
@@ -25,7 +25,7 @@
2626 if (isset($options['protect']) && isset($options['unprotect']))
2727 die("Cannot specify both protect and unprotect. Only 1 is allowed.\n");
2828
29 - if ($options['protect'] == 1)
 29+if (isset($options['protect']) && $options['protect'] == 1)
3030 die("You must specify a protection option.\n");
3131
3232 # Prepare the list of allowed extensions
@@ -45,6 +45,17 @@
4646 $user = User::newFromName( 'Maintenance script' );
4747 $wgUser = $user;
4848
 49+ # Get --from
 50+ $from = @$options['from'];
 51+
 52+ # Get sleep time.
 53+ $sleep = @$options['sleep'];
 54+ if ( $sleep ) $sleep = (int)$sleep;
 55+
 56+ # Get limit number
 57+ $limit = @$options['limit'];
 58+ if ( $limit ) $limit = (int)$limit;
 59+
4960 # Get the upload comment
5061 $comment = 'Importing image file';
5162
@@ -76,6 +87,15 @@
7788 continue;
7889 }
7990
 91+ if ( $from ) {
 92+ if ( $from == $title->getDBkey() ) {
 93+ $from = NULL;
 94+ } else {
 95+ $ignored++;
 96+ continue;
 97+ }
 98+ }
 99+
80100 # Check existence
81101 $image = wfLocalFile( $title );
82102 if( $image->exists() ) {
@@ -105,6 +125,10 @@
106126 echo( " Failed to load comment file {$f}, using default comment. " );
107127 }
108128 }
 129+
 130+ if ( $commentText && $comment ) {
 131+ $commentText = trim( $commentText ) . "\n\n" . trim( $comment );
 132+ }
109133 }
110134
111135 if ( !$commentText ) {
@@ -118,6 +142,7 @@
119143 $archive = $image->publish( $file );
120144 if( WikiError::isError( $archive ) || !$archive->isGood() ) {
121145 echo( "failed.\n" );
 146+ $failed++;
122147 continue;
123148 }
124149 }
@@ -141,7 +166,6 @@
142167 }
143168
144169
145 - $$svar++;
146170 if ( isset( $options['dry'] ) ) {
147171 echo( "done.\n" );
148172 } else if ( $image->recordUpload( $archive->value, $commentText, $license ) ) {
@@ -164,14 +188,24 @@
165189
166190 } else {
167191 echo( "failed.\n" );
 192+ $svar = 'failed';
168193 }
169194
 195+ $$svar++;
 196+ $processed++;
 197+
 198+ if ( $limit && $processed >= $limit )
 199+ break;
 200+
 201+ if ( $sleep )
 202+ sleep( $sleep );
170203 }
171204
172205 # Print out some statistics
173206 echo( "\n" );
174 - foreach( array( 'count' => 'Found', 'added' => 'Added',
175 - 'skipped' => 'Skipped', 'overwritten' => 'Overwritten' ) as $var => $desc ) {
 207+ foreach( array( 'count' => 'Found', 'limit' => 'Limit', 'ignored' => 'Ignored',
 208+ 'added' => 'Added', 'skipped' => 'Skipped', 'overwritten' => 'Overwritten',
 209+ 'failed' => 'Failed' ) as $var => $desc ) {
176210 if( $$var > 0 )
177211 echo( "{$desc}: {$$var}\n" );
178212 }
@@ -199,12 +233,16 @@
200234
201235 Options:
202236 --extensions=<exts> Comma-separated list of allowable extensions, defaults to \$wgFileExtensions
 237+--overwrite Overwrite existing images with the same name (default is to skip them)
 238+--limit=<num> Limit the number of images to process. Ignored or skipped images are not counted.
 239+--from=<name> Ignore all files until the one with the given name. Useful for resuming
 240+ aborted imports. <name> should be the file's canonical database form.
 241+--sleep=<sec> Sleep between files. Useful mostly for debugging.
203242 --user=<username> Set username of uploader, default 'Maintenance script'
 243+--comment=<text> Set upload summary comment, default 'Importing image file'.
204244 --comment-file=<file> Set upload summary comment the the content of <file>.
205245 --comment-ext=<ext> Causes the comment for each file to be loaded from a file with the same name
206 - but the extension <ext>.
 246+ but the extension <ext>. If a global comment is also given, it is appended.
207247 --license=<code> Use an optional license template
208248 --dry Dry run, don't import anything
209249 --protect=<protect> Specify the protect value (autoconfirmed,sysop)

Status & tagging log