From b76bfa8a0fcaefebee8ee5133bc4cd96cc47bb85 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Thu, 7 Jun 2007 15:07:12 +0000 Subject: [PATCH] * Don't require a list of extensions; move it into an option, and default to $wgFileExtensions * Let the user know if no suitable files are found * Missing release note from r22772 --- RELEASE-NOTES | 4 +++- maintenance/importImages.php | 34 ++++++++++++++++++++-------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 3acf0f8851..e6a21abf27 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -136,7 +136,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 9383) Don't set a default value for BLOB column in rc-deleted database patch * (bug 10149) Don't show full template list on section-0 edit - +* Fix maintenance/importImages.php so it doesn't barf PHP errors when no suitable + files are found, and make the list of extensions an option (defaults to + $wgFileExtensions) == MediaWiki API changes since 1.10 == diff --git a/maintenance/importImages.php b/maintenance/importImages.php index 5ec580a86a..0c560d7a9a 100644 --- a/maintenance/importImages.php +++ b/maintenance/importImages.php @@ -8,22 +8,24 @@ * @author Rob Church */ +$optionsWithArguments = array( 'extensions' ); require_once( 'commandLine.inc' ); require_once( 'importImages.inc.php' ); echo( "Import Images\n\n" ); -# Need a directory and at least one extension -if( count( $args ) > 1 ) { +# Need a path +if( count( $args ) > 0 ) { - $dir = array_shift( $args ); + $dir = $args[0]; - # Check the allowed extensions - while( $ext = array_shift( $args ) ) { - $exts[] = ltrim( $ext, '.' ); - } + # Prepare the list of allowed extensions + global $wgFileExtensions; + $extensions = isset( $options['extensions'] ) + ? explode( ',', strtolower( $options['extensions'] ) ) + : $wgFileExtensions; - # Search the directory given and pull out suitable candidates - $files = findFiles( $dir, $exts ); + # Search the path provided for candidates for import + $files = findFiles( $dir, $extensions ); # Initialise the user for this operation $user = isset( $options['user'] ) @@ -44,6 +46,7 @@ if( count( $args ) > 1 ) { # Batch "upload" operation global $wgUploadDirectory; if( count( $files ) > 0 ) { + foreach( $files as $file ) { $base = wfBaseName( $file ); @@ -78,6 +81,9 @@ if( count( $args ) > 1 ) { echo( "failed.\n" ); } } + + } else { + echo( "No suitable files could be found for import.\n" ); } } else { @@ -92,15 +98,15 @@ function showUsage( $reason = false ) { } echo << ... +USAGE: php importImages.php [options] : Path to the directory containing images to be imported - File extensions to import Options: ---user= Set username of uploader, default 'Image import script' ---comment= Set upload summary comment, default 'Importing image file' ---license= Use an optional license template +--extensions= Comma-separated list of allowable extensions, defaults to $wgFileExtensions +--user= Set username of uploader, default 'Maintenance script' +--comment= Set upload summary comment, default 'Importing image file' +--license= Use an optional license template END; exit(); -- 2.20.1