Index: trunk/phase3/maintenance/importImages.php |
— | — | @@ -43,39 +43,41 @@ |
44 | 44 | |
45 | 45 | # Batch "upload" operation |
46 | 46 | 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 | + } |
55 | 81 | } |
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 | | - } |
80 | 82 | } |
81 | 83 | |
82 | 84 | } else { |