r22772 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r22771‎ | r22772 | r22773 >
Date:18:39, 5 June 2007
Author:robchurch
Status:old
Tags:
Comment:
Don't bug out if no files were found
Modified paths:
  • /trunk/phase3/maintenance/importImages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/importImages.php
@@ -43,39 +43,41 @@
4444
4545 # Batch "upload" operation
4646 global $wgUploadDirectory;
47 - foreach( $files as $file ) {
48 - $base = wfBaseName( $file );
49 -
50 - # Validate a title
51 - $title = Title::makeTitleSafe( NS_IMAGE, $base );
52 - if( !is_object( $title ) ) {
53 - echo( "{$base} could not be imported; a valid title cannot be produced\n" );
54 - continue;
 47+ if( count( $files ) > 0 ) {
 48+ foreach( $files as $file ) {
 49+ $base = wfBaseName( $file );
 50+
 51+ # Validate a title
 52+ $title = Title::makeTitleSafe( NS_IMAGE, $base );
 53+ if( !is_object( $title ) ) {
 54+ echo( "{$base} could not be imported; a valid title cannot be produced\n" );
 55+ continue;
 56+ }
 57+
 58+ # Check existence
 59+ $image = wfLocalFile( $title );
 60+ if( $image->exists() ) {
 61+ echo( "{$base} could not be imported; a file with this name exists in the wiki\n" );
 62+ continue;
 63+ }
 64+
 65+ # Stash the file
 66+ echo( "Saving {$base}..." );
 67+
 68+ $archive = $image->publish( $file );
 69+ if ( WikiError::isError( $archive ) ) {
 70+ echo( "failed.\n" );
 71+ continue;
 72+ }
 73+ echo( "importing..." );
 74+
 75+ if ( $image->recordUpload( $archive, $comment, $license ) ) {
 76+ # We're done!
 77+ echo( "done.\n" );
 78+ } else {
 79+ echo( "failed.\n" );
 80+ }
5581 }
56 -
57 - # Check existence
58 - $image = wfLocalFile( $title );
59 - if( $image->exists() ) {
60 - echo( "{$base} could not be imported; a file with this name exists in the wiki\n" );
61 - continue;
62 - }
63 -
64 - # Stash the file
65 - echo( "Saving {$base}..." );
66 -
67 - $archive = $image->publish( $file );
68 - if ( WikiError::isError( $archive ) ) {
69 - echo( "failed.\n" );
70 - continue;
71 - }
72 - echo( "importing..." );
73 -
74 - if ( $image->recordUpload( $archive, $comment, $license ) ) {
75 - # We're done!
76 - echo( "done.\n" );
77 - } else {
78 - echo( "failed.\n" );
79 - }
8082 }
8183
8284 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r22791Merged revisions 22747-22790 via svnmerge from...david09:21, 6 June 2007
r22815* Don't require a list of extensions; move it into an option, and default to ...robchurch15:07, 7 June 2007
r22857Merged revisions 22811-22855 via svnmerge from...david00:48, 9 June 2007

Status & tagging log