Index: trunk/phase3/maintenance/importImages.php |
— | — | @@ -9,10 +9,10 @@ |
10 | 10 | * @author Rob Church <robchur@gmail.com> |
11 | 11 | */ |
12 | 12 | |
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' ); |
14 | 14 | require_once( dirname(__FILE__) . '/commandLine.inc' ); |
15 | 15 | require_once( 'importImages.inc' ); |
16 | | -$added = $skipped = $overwritten = 0; |
| 16 | +$processed = $added = $ignored = $skipped = $overwritten = $failed = 0; |
17 | 17 | |
18 | 18 | echo( "Import Images\n\n" ); |
19 | 19 | |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | if (isset($options['protect']) && isset($options['unprotect'])) |
27 | 27 | die("Cannot specify both protect and unprotect. Only 1 is allowed.\n"); |
28 | 28 | |
29 | | - if ($options['protect'] == 1) |
| 29 | +if (isset($options['protect']) && $options['protect'] == 1) |
30 | 30 | die("You must specify a protection option.\n"); |
31 | 31 | |
32 | 32 | # Prepare the list of allowed extensions |
— | — | @@ -45,6 +45,17 @@ |
46 | 46 | $user = User::newFromName( 'Maintenance script' ); |
47 | 47 | $wgUser = $user; |
48 | 48 | |
| 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 | + |
49 | 60 | # Get the upload comment |
50 | 61 | $comment = 'Importing image file'; |
51 | 62 | |
— | — | @@ -76,6 +87,15 @@ |
77 | 88 | continue; |
78 | 89 | } |
79 | 90 | |
| 91 | + if ( $from ) { |
| 92 | + if ( $from == $title->getDBkey() ) { |
| 93 | + $from = NULL; |
| 94 | + } else { |
| 95 | + $ignored++; |
| 96 | + continue; |
| 97 | + } |
| 98 | + } |
| 99 | + |
80 | 100 | # Check existence |
81 | 101 | $image = wfLocalFile( $title ); |
82 | 102 | if( $image->exists() ) { |
— | — | @@ -105,6 +125,10 @@ |
106 | 126 | echo( " Failed to load comment file {$f}, using default comment. " ); |
107 | 127 | } |
108 | 128 | } |
| 129 | + |
| 130 | + if ( $commentText && $comment ) { |
| 131 | + $commentText = trim( $commentText ) . "\n\n" . trim( $comment ); |
| 132 | + } |
109 | 133 | } |
110 | 134 | |
111 | 135 | if ( !$commentText ) { |
— | — | @@ -118,6 +142,7 @@ |
119 | 143 | $archive = $image->publish( $file ); |
120 | 144 | if( WikiError::isError( $archive ) || !$archive->isGood() ) { |
121 | 145 | echo( "failed.\n" ); |
| 146 | + $failed++; |
122 | 147 | continue; |
123 | 148 | } |
124 | 149 | } |
— | — | @@ -141,7 +166,6 @@ |
142 | 167 | } |
143 | 168 | |
144 | 169 | |
145 | | - $$svar++; |
146 | 170 | if ( isset( $options['dry'] ) ) { |
147 | 171 | echo( "done.\n" ); |
148 | 172 | } else if ( $image->recordUpload( $archive->value, $commentText, $license ) ) { |
— | — | @@ -164,14 +188,24 @@ |
165 | 189 | |
166 | 190 | } else { |
167 | 191 | echo( "failed.\n" ); |
| 192 | + $svar = 'failed'; |
168 | 193 | } |
169 | 194 | |
| 195 | + $$svar++; |
| 196 | + $processed++; |
| 197 | + |
| 198 | + if ( $limit && $processed >= $limit ) |
| 199 | + break; |
| 200 | + |
| 201 | + if ( $sleep ) |
| 202 | + sleep( $sleep ); |
170 | 203 | } |
171 | 204 | |
172 | 205 | # Print out some statistics |
173 | 206 | 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 ) { |
176 | 210 | if( $$var > 0 ) |
177 | 211 | echo( "{$desc}: {$$var}\n" ); |
178 | 212 | } |
— | — | @@ -199,12 +233,16 @@ |
200 | 234 | |
201 | 235 | Options: |
202 | 236 | --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. |
203 | 242 | --user=<username> Set username of uploader, default 'Maintenance script' |
| 243 | +--comment=<text> Set upload summary comment, default 'Importing image file'. |
204 | 244 | --comment-file=<file> Set upload summary comment the the content of <file>. |
205 | 245 | --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. |
207 | 247 | --license=<code> Use an optional license template |
208 | 248 | --dry Dry run, don't import anything |
209 | 249 | --protect=<protect> Specify the protect value (autoconfirmed,sysop) |