r24418 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24417‎ | r24418 | r24419 >
Date:22:21, 28 July 2007
Author:robchurch
Status:old
Tags:
Comment:
* Allow overwriting existing files with conflicting names using the --override option
* More useful output (no. of files added, overwritten, skipped)
* Trim some whitespace and kill a dud global \o/
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/maintenance/importImages.inc.php (modified) (history)
  • /trunk/phase3/maintenance/importImages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importImages.php
@@ -8,9 +8,11 @@
99 * @author Rob Church <robchur@gmail.com>
1010 */
1111
12 -$optionsWithArguments = array( 'extensions' );
 12+$optionsWithArguments = array( 'extensions', 'overwrite' );
1313 require_once( 'commandLine.inc' );
1414 require_once( 'importImages.inc.php' );
 15+$added = $skipped = $overwritten = 0;
 16+
1517 echo( "Import Images\n\n" );
1618
1719 # Need a path
@@ -44,8 +46,7 @@
4547 $license = isset( $options['license'] ) ? $options['license'] : '';
4648
4749 # Batch "upload" operation
48 - global $wgUploadDirectory;
49 - if( count( $files ) > 0 ) {
 50+ if( ( $count = count( $files ) ) > 0 ) {
5051
5152 foreach( $files as $file ) {
5253 $base = wfBaseName( $file );
@@ -60,28 +61,44 @@
6162 # Check existence
6263 $image = wfLocalFile( $title );
6364 if( $image->exists() ) {
64 - echo( "{$base} could not be imported; a file with this name exists in the wiki\n" );
65 - continue;
 65+ if( isset( $options['overwrite'] ) ) {
 66+ echo( "{$base} exists, overwriting..." );
 67+ $svar = 'overwritten';
 68+ } else {
 69+ echo( "{$base} exists, skipping\n" );
 70+ $skipped++;
 71+ continue;
 72+ }
 73+ } else {
 74+ echo( "Importing {$base}..." );
 75+ $svar = 'added';
6676 }
67 -
68 - # Stash the file
69 - echo( "Saving {$base}..." );
70 -
 77+
 78+ # Import the file
7179 $archive = $image->publish( $file );
72 - if ( WikiError::isError( $archive ) ) {
 80+ if( WikiError::isError( $archive ) || !$archive->isGood() ) {
7381 echo( "failed.\n" );
7482 continue;
7583 }
76 - echo( "importing..." );
77 -
78 - if ( $image->recordUpload( $archive, $comment, $license ) ) {
 84+
 85+ $$svar++;
 86+ if ( $image->recordUpload( $archive->value, $comment, $license ) ) {
7987 # We're done!
8088 echo( "done.\n" );
8189 } else {
8290 echo( "failed.\n" );
8391 }
 92+
8493 }
8594
 95+ # Print out some statistics
 96+ echo( "\n" );
 97+ foreach( array( 'count' => 'Found', 'added' => 'Added',
 98+ 'skipped' => 'Skipped', 'overwritten' => 'Overwritten' ) as $var => $desc ) {
 99+ if( $$var > 0 )
 100+ echo( "{$desc}: {$$var}\n" );
 101+ }
 102+
86103 } else {
87104 echo( "No suitable files could be found for import.\n" );
88105 }
@@ -98,18 +115,18 @@
99116 }
100117
101118 echo <<<END
 119+Imports images and other media files into the wiki
102120 USAGE: php importImages.php [options] <dir>
103121
104122 <dir> : Path to the directory containing images to be imported
105123
106124 Options:
 125+--extensions=<exts> Comma-separated list of allowable extensions, defaults to \$wgFileExtensions
 126+--overwrite Overwrite existing images if a conflicting-named image is found
107127 --user=<username> Set username of uploader, default 'Maintenance script'
108128 --comment=<text> Set upload summary comment, default 'Importing image file'
109129 --license=<code> Use an optional license template
110130
111131 END;
112132 exit();
113 -}
114 -
115 -
 133+}
\ No newline at end of file
Index: trunk/phase3/maintenance/importImages.inc.php
@@ -45,6 +45,4 @@
4646 unset( $parts[ count( $parts ) - 1 ] );
4747 $fname = implode( '.', $parts );
4848 return array( $fname, $ext );
49 -}
50 -
51 -
 49+}
\ No newline at end of file
Index: trunk/phase3/RELEASE-NOTES
@@ -386,6 +386,8 @@
387387 to $wgFileExtensions)
388388 * Add option to maintenance/createAndPromote.php to give the user bureaucrat
389389 permissions (--bureaucrat)
 390+* Allow overwriting existing files with a conflicting name using
 391+ maintenance/importImages.php
390392
391393 == Languages updated since 1.10 ==
392394

Follow-up revisions

RevisionCommit summaryAuthorDate
r24502Merged revisions 24415-24479 via svnmerge from...david22:31, 31 July 2007

Status & tagging log