Index: trunk/phase3/maintenance/importImages.php |
— | — | @@ -61,10 +61,10 @@ |
62 | 62 | $checkUserBlock = false; |
63 | 63 | } |
64 | 64 | |
65 | | - # Get --from |
| 65 | + # Get --from |
66 | 66 | $from = @$options['from']; |
67 | 67 | |
68 | | - # Get sleep time. |
| 68 | + # Get sleep time. |
69 | 69 | $sleep = @$options['sleep']; |
70 | 70 | if ( $sleep ) $sleep = (int)$sleep; |
71 | 71 | |
— | — | @@ -92,17 +92,17 @@ |
93 | 93 | |
94 | 94 | # Batch "upload" operation |
95 | 95 | if ( ( $count = count( $files ) ) > 0 ) { |
96 | | - |
| 96 | + |
97 | 97 | foreach ( $files as $file ) { |
98 | 98 | $base = wfBaseName( $file ); |
99 | | - |
| 99 | + |
100 | 100 | # Validate a title |
101 | 101 | $title = Title::makeTitleSafe( NS_FILE, $base ); |
102 | 102 | if ( !is_object( $title ) ) { |
103 | 103 | echo( "{$base} could not be imported; a valid title cannot be produced\n" ); |
104 | 104 | continue; |
105 | 105 | } |
106 | | - |
| 106 | + |
107 | 107 | if ( $from ) { |
108 | 108 | if ( $from == $title->getDBkey() ) { |
109 | 109 | $from = NULL; |
— | — | @@ -149,49 +149,49 @@ |
150 | 150 | $svar = 'added'; |
151 | 151 | } |
152 | 152 | |
153 | | - if ( isset( $options['source-wiki-url'] ) ) { |
154 | | - /* find comment text directly from source wiki, through MW's API */ |
155 | | - $real_comment = getFileCommentFromSourceWiki( $options['source-wiki-url'], $base ); |
156 | | - if ( $real_comment === false ) |
157 | | - $commentText = $comment; |
158 | | - else |
159 | | - $commentText = $real_comment; |
| 153 | + if ( isset( $options['source-wiki-url'] ) ) { |
| 154 | + /* find comment text directly from source wiki, through MW's API */ |
| 155 | + $real_comment = getFileCommentFromSourceWiki( $options['source-wiki-url'], $base ); |
| 156 | + if ( $real_comment === false ) |
| 157 | + $commentText = $comment; |
| 158 | + else |
| 159 | + $commentText = $real_comment; |
160 | 160 | |
161 | | - /* find user directly from source wiki, through MW's API */ |
162 | | - $real_user = getFileUserFromSourceWiki( $options['source-wiki-url'], $base ); |
163 | | - if ( $real_user === false ) { |
164 | | - $wgUser = $user; |
165 | | - } else { |
166 | | - $wgUser = User::newFromName( $real_user ); |
167 | | - if ( $wgUser === false ) { |
168 | | - # user does not exist in target wiki |
169 | | - echo ( "failed: user '$real_user' does not exist in target wiki." ); |
170 | | - continue; |
171 | | - } |
172 | | - } |
173 | | - } else { |
174 | | - # Find comment text |
175 | | - $commentText = false; |
| 161 | + /* find user directly from source wiki, through MW's API */ |
| 162 | + $real_user = getFileUserFromSourceWiki( $options['source-wiki-url'], $base ); |
| 163 | + if ( $real_user === false ) { |
| 164 | + $wgUser = $user; |
| 165 | + } else { |
| 166 | + $wgUser = User::newFromName( $real_user ); |
| 167 | + if ( $wgUser === false ) { |
| 168 | + # user does not exist in target wiki |
| 169 | + echo ( "failed: user '$real_user' does not exist in target wiki." ); |
| 170 | + continue; |
| 171 | + } |
| 172 | + } |
| 173 | + } else { |
| 174 | + # Find comment text |
| 175 | + $commentText = false; |
176 | 176 | |
177 | | - if ( $commentExt ) { |
178 | | - $f = findAuxFile( $file, $commentExt ); |
179 | | - if ( !$f ) { |
180 | | - echo( " No comment file with extension {$commentExt} found for {$file}, using default comment. " ); |
181 | | - } else { |
182 | | - $commentText = file_get_contents( $f ); |
183 | | - if ( !$f ) { |
184 | | - echo( " Failed to load comment file {$f}, using default comment. " ); |
185 | | - } |
186 | | - } |
187 | | - } |
| 177 | + if ( $commentExt ) { |
| 178 | + $f = findAuxFile( $file, $commentExt ); |
| 179 | + if ( !$f ) { |
| 180 | + echo( " No comment file with extension {$commentExt} found for {$file}, using default comment. " ); |
| 181 | + } else { |
| 182 | + $commentText = file_get_contents( $f ); |
| 183 | + if ( !$f ) { |
| 184 | + echo( " Failed to load comment file {$f}, using default comment. " ); |
| 185 | + } |
| 186 | + } |
| 187 | + } |
188 | 188 | |
189 | | - if ( !$commentText ) { |
190 | | - $commentText = $comment; |
191 | | - } |
192 | | - } |
| 189 | + if ( !$commentText ) { |
| 190 | + $commentText = $comment; |
| 191 | + } |
| 192 | + } |
193 | 193 | |
194 | 194 | |
195 | | - # Import the file |
| 195 | + # Import the file |
196 | 196 | if ( isset( $options['dry'] ) ) { |
197 | 197 | echo( " publishing {$file} by '" . $wgUser->getName() . "', comment '$commentText'... " ); |
198 | 198 | } else { |
— | — | @@ -202,14 +202,14 @@ |
203 | 203 | continue; |
204 | 204 | } |
205 | 205 | } |
206 | | - |
| 206 | + |
207 | 207 | $doProtect = false; |
208 | 208 | $restrictions = array(); |
209 | | - |
| 209 | + |
210 | 210 | global $wgRestrictionLevels; |
211 | | - |
| 211 | + |
212 | 212 | $protectLevel = isset( $options['protect'] ) ? $options['protect'] : null; |
213 | | - |
| 213 | + |
214 | 214 | if ( $protectLevel && in_array( $protectLevel, $wgRestrictionLevels ) ) { |
215 | 215 | $restrictions['move'] = $protectLevel; |
216 | 216 | $restrictions['edit'] = $protectLevel; |
— | — | @@ -234,19 +234,19 @@ |
235 | 235 | // Wait for slaves. |
236 | 236 | sleep( 2.0 ); |
237 | 237 | wfWaitForSlaves( 1.0 ); |
238 | | - |
| 238 | + |
239 | 239 | echo( "\nSetting image restrictions ... " ); |
240 | 240 | if ( $article->updateRestrictions( $restrictions ) ) |
241 | | - echo( "done.\n" ); |
| 241 | + echo( "done.\n" ); |
242 | 242 | else |
243 | | - echo( "failed.\n" ); |
| 243 | + echo( "failed.\n" ); |
244 | 244 | } |
245 | 245 | |
246 | 246 | } else { |
247 | 247 | echo( "failed.\n" ); |
248 | 248 | $svar = 'failed'; |
249 | 249 | } |
250 | | - |
| 250 | + |
251 | 251 | $$svar++; |
252 | 252 | $processed++; |
253 | 253 | |
— | — | @@ -256,7 +256,7 @@ |
257 | 257 | if ( $sleep ) |
258 | 258 | sleep( $sleep ); |
259 | 259 | } |
260 | | - |
| 260 | + |
261 | 261 | # Print out some statistics |
262 | 262 | echo( "\n" ); |
263 | 263 | foreach ( array( 'count' => 'Found', 'limit' => 'Limit', 'ignored' => 'Ignored', |
— | — | @@ -265,7 +265,7 @@ |
266 | 266 | if ( $$var > 0 ) |
267 | 267 | echo( "{$desc}: {$$var}\n" ); |
268 | 268 | } |
269 | | - |
| 269 | + |
270 | 270 | } else { |
271 | 271 | echo( "No suitable files could be found for import.\n" ); |
272 | 272 | } |