Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -136,8 +136,10 @@ |
137 | 137 | * (bug 9383) Don't set a default value for BLOB column in rc-deleted |
138 | 138 | database patch |
139 | 139 | * (bug 10149) Don't show full template list on section-0 edit |
| 140 | +* Fix maintenance/importImages.php so it doesn't barf PHP errors when no suitable |
| 141 | + files are found, and make the list of extensions an option (defaults to |
| 142 | + $wgFileExtensions) |
140 | 143 | |
141 | | - |
142 | 144 | == MediaWiki API changes since 1.10 == |
143 | 145 | |
144 | 146 | (For ongoing development discussion, see http://www.mediawiki.org/wiki/API) |
Index: trunk/phase3/maintenance/importImages.php |
— | — | @@ -8,22 +8,24 @@ |
9 | 9 | * @author Rob Church <robchur@gmail.com> |
10 | 10 | */ |
11 | 11 | |
| 12 | +$optionsWithArguments = array( 'extensions' ); |
12 | 13 | require_once( 'commandLine.inc' ); |
13 | 14 | require_once( 'importImages.inc.php' ); |
14 | 15 | echo( "Import Images\n\n" ); |
15 | 16 | |
16 | | -# Need a directory and at least one extension |
17 | | -if( count( $args ) > 1 ) { |
| 17 | +# Need a path |
| 18 | +if( count( $args ) > 0 ) { |
18 | 19 | |
19 | | - $dir = array_shift( $args ); |
| 20 | + $dir = $args[0]; |
20 | 21 | |
21 | | - # Check the allowed extensions |
22 | | - while( $ext = array_shift( $args ) ) { |
23 | | - $exts[] = ltrim( $ext, '.' ); |
24 | | - } |
| 22 | + # Prepare the list of allowed extensions |
| 23 | + global $wgFileExtensions; |
| 24 | + $extensions = isset( $options['extensions'] ) |
| 25 | + ? explode( ',', strtolower( $options['extensions'] ) ) |
| 26 | + : $wgFileExtensions; |
25 | 27 | |
26 | | - # Search the directory given and pull out suitable candidates |
27 | | - $files = findFiles( $dir, $exts ); |
| 28 | + # Search the path provided for candidates for import |
| 29 | + $files = findFiles( $dir, $extensions ); |
28 | 30 | |
29 | 31 | # Initialise the user for this operation |
30 | 32 | $user = isset( $options['user'] ) |
— | — | @@ -44,6 +46,7 @@ |
45 | 47 | # Batch "upload" operation |
46 | 48 | global $wgUploadDirectory; |
47 | 49 | if( count( $files ) > 0 ) { |
| 50 | + |
48 | 51 | foreach( $files as $file ) { |
49 | 52 | $base = wfBaseName( $file ); |
50 | 53 | |
— | — | @@ -78,6 +81,9 @@ |
79 | 82 | echo( "failed.\n" ); |
80 | 83 | } |
81 | 84 | } |
| 85 | + |
| 86 | + } else { |
| 87 | + echo( "No suitable files could be found for import.\n" ); |
82 | 88 | } |
83 | 89 | |
84 | 90 | } else { |
— | — | @@ -92,15 +98,15 @@ |
93 | 99 | } |
94 | 100 | |
95 | 101 | echo <<<END |
96 | | -USAGE: php importImages.php [options] <dir> <ext1> ... |
| 102 | +USAGE: php importImages.php [options] <dir> |
97 | 103 | |
98 | 104 | <dir> : Path to the directory containing images to be imported |
99 | | -<ext1+> File extensions to import |
100 | 105 | |
101 | 106 | Options: |
| 107 | +--extensions=<exts> Comma-separated list of allowable extensions, defaults to $wgFileExtensions |
| 108 | +--user=<username> Set username of uploader, default 'Maintenance script' |
| 109 | +--comment=<text> Set upload summary comment, default 'Importing image file' |
| 110 | +--license=<code> Use an optional license template |
102 | 111 | |
103 | 112 | END; |
104 | 113 | exit(); |