Index: trunk/phase3/maintenance/importImages.php |
— | — | @@ -8,9 +8,11 @@ |
9 | 9 | * @author Rob Church <robchur@gmail.com> |
10 | 10 | */ |
11 | 11 | |
12 | | -$optionsWithArguments = array( 'extensions' ); |
| 12 | +$optionsWithArguments = array( 'extensions', 'overwrite' ); |
13 | 13 | require_once( 'commandLine.inc' ); |
14 | 14 | require_once( 'importImages.inc.php' ); |
| 15 | +$added = $skipped = $overwritten = 0; |
| 16 | + |
15 | 17 | echo( "Import Images\n\n" ); |
16 | 18 | |
17 | 19 | # Need a path |
— | — | @@ -44,8 +46,7 @@ |
45 | 47 | $license = isset( $options['license'] ) ? $options['license'] : ''; |
46 | 48 | |
47 | 49 | # Batch "upload" operation |
48 | | - global $wgUploadDirectory; |
49 | | - if( count( $files ) > 0 ) { |
| 50 | + if( ( $count = count( $files ) ) > 0 ) { |
50 | 51 | |
51 | 52 | foreach( $files as $file ) { |
52 | 53 | $base = wfBaseName( $file ); |
— | — | @@ -60,28 +61,44 @@ |
61 | 62 | # Check existence |
62 | 63 | $image = wfLocalFile( $title ); |
63 | 64 | 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'; |
66 | 76 | } |
67 | | - |
68 | | - # Stash the file |
69 | | - echo( "Saving {$base}..." ); |
70 | | - |
| 77 | + |
| 78 | + # Import the file |
71 | 79 | $archive = $image->publish( $file ); |
72 | | - if ( WikiError::isError( $archive ) ) { |
| 80 | + if( WikiError::isError( $archive ) || !$archive->isGood() ) { |
73 | 81 | echo( "failed.\n" ); |
74 | 82 | continue; |
75 | 83 | } |
76 | | - echo( "importing..." ); |
77 | | - |
78 | | - if ( $image->recordUpload( $archive, $comment, $license ) ) { |
| 84 | + |
| 85 | + $$svar++; |
| 86 | + if ( $image->recordUpload( $archive->value, $comment, $license ) ) { |
79 | 87 | # We're done! |
80 | 88 | echo( "done.\n" ); |
81 | 89 | } else { |
82 | 90 | echo( "failed.\n" ); |
83 | 91 | } |
| 92 | + |
84 | 93 | } |
85 | 94 | |
| 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 | + |
86 | 103 | } else { |
87 | 104 | echo( "No suitable files could be found for import.\n" ); |
88 | 105 | } |
— | — | @@ -98,18 +115,18 @@ |
99 | 116 | } |
100 | 117 | |
101 | 118 | echo <<<END |
| 119 | +Imports images and other media files into the wiki |
102 | 120 | USAGE: php importImages.php [options] <dir> |
103 | 121 | |
104 | 122 | <dir> : Path to the directory containing images to be imported |
105 | 123 | |
106 | 124 | 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 |
107 | 127 | --user=<username> Set username of uploader, default 'Maintenance script' |
108 | 128 | --comment=<text> Set upload summary comment, default 'Importing image file' |
109 | 129 | --license=<code> Use an optional license template |
110 | 130 | |
111 | 131 | END; |
112 | 132 | exit(); |
113 | | -} |
114 | | - |
115 | | - |
| 133 | +} |
\ No newline at end of file |
Index: trunk/phase3/maintenance/importImages.inc.php |
— | — | @@ -45,6 +45,4 @@ |
46 | 46 | unset( $parts[ count( $parts ) - 1 ] ); |
47 | 47 | $fname = implode( '.', $parts ); |
48 | 48 | return array( $fname, $ext ); |
49 | | -} |
50 | | - |
51 | | - |
| 49 | +} |
\ No newline at end of file |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -386,6 +386,8 @@ |
387 | 387 | to $wgFileExtensions) |
388 | 388 | * Add option to maintenance/createAndPromote.php to give the user bureaucrat |
389 | 389 | permissions (--bureaucrat) |
| 390 | +* Allow overwriting existing files with a conflicting name using |
| 391 | + maintenance/importImages.php |
390 | 392 | |
391 | 393 | == Languages updated since 1.10 == |
392 | 394 | |