r55619 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r55618‎ | r55619 | r55620 >
Date:14:21, 27 August 2009
Author:btongminh
Status:ok (Comments)
Tags:
Comment:
* Output warnings as filenames rather than an array representation of a File object.
* Renamed variable in UploadBase::checkWarnings to better indicate its meaning
Modified paths:
  • /trunk/phase3/includes/api/ApiUpload.php (modified) (history)
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -280,7 +280,7 @@
281281 * @return array Array of warnings
282282 */
283283 public function checkWarnings() {
284 - $warning = array();
 284+ $warnings = array();
285285
286286 $localFile = $this->getLocalFile();
287287 $filename = $localFile->getName();
@@ -297,33 +297,33 @@
298298 $comparableName = $wgContLang->ucfirst( $comparableName );
299299 }
300300 if( $this->mDesiredDestName != $filename && $comparableName != $filename )
301 - $warning['badfilename'] = $filename;
 301+ $warnings['badfilename'] = $filename;
302302
303303 // Check whether the file extension is on the unwanted list
304304 global $wgCheckFileExtensions, $wgFileExtensions;
305305 if ( $wgCheckFileExtensions ) {
306306 if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) )
307 - $warning['filetype-unwanted-type'] = $this->mFinalExtension;
 307+ $warnings['filetype-unwanted-type'] = $this->mFinalExtension;
308308 }
309309
310310 global $wgUploadSizeWarning;
311311 if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) )
312 - $warning['large-file'] = $wgUploadSizeWarning;
 312+ $warnings['large-file'] = $wgUploadSizeWarning;
313313
314314 if ( $this->mFileSize == 0 )
315 - $warning['emptyfile'] = true;
 315+ $warnings['emptyfile'] = true;
316316
317317
318318 $exists = self::getExistsWarning( $localFile );
319319 if( $exists !== false )
320 - $warning['exists'] = $exists;
 320+ $warnings['exists'] = $exists;
321321
322322 // Check whether this may be a thumbnail
323323 if( $exists !== false && $exists[0] != 'thumb'
324324 && self::isThumbName( $filename ) ){
325325 // Make the title
326326 $nt = $this->getTitle();
327 - $warning['file-thumbnail-no'] = substr( $filename, 0,
 327+ $warnings['file-thumbnail-no'] = substr( $filename, 0,
328328 strpos( $nt->getText() , '-' ) +1 );
329329 }
330330
@@ -337,17 +337,17 @@
338338 unset( $dupes[$key] );
339339 }
340340 if( $dupes )
341 - $warning['duplicate'] = $dupes;
 341+ $warnings['duplicate'] = $dupes;
342342
343343 // Check dupes against archives
344344 $archivedImage = new ArchivedFile( null, 0, "{$hash}.{$this->mFinalExtension}" );
345345 if ( $archivedImage->getID() > 0 )
346 - $warning['duplicate-archive'] = $archivedImage->getName();
 346+ $warnings['duplicate-archive'] = $archivedImage->getName();
347347
348348 $filenamePrefixBlacklist = self::getFilenamePrefixBlacklist();
349349 foreach( $filenamePrefixBlacklist as $prefix ) {
350350 if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
351 - $warning['filename-bad-prefix'] = $prefix;
 351+ $warnings['filename-bad-prefix'] = $prefix;
352352 break;
353353 }
354354 }
@@ -355,9 +355,9 @@
356356 # If the file existed before and was deleted, warn the user of this
357357 # Don't bother doing so if the file exists now, however
358358 if( $localFile->wasDeleted() && !$localFile->exists() )
359 - $warning['filewasdeleted'] = $localFile->getTitle();
 359+ $warnings['filewasdeleted'] = $localFile->getTitle();
360360
361 - return $warning;
 361+ return $warnings;
362362 }
363363
364364 /**
Index: trunk/phase3/includes/api/ApiUpload.php
@@ -242,14 +242,23 @@
243243 // Add indices
244244 $this->getResult()->setIndexedTagName( $warnings, 'warning' );
245245
246 - if( isset( $warnings['duplicate'] ) )
247 - $this->getResult()->setIndexedTagName( $warnings['duplicate'], 'duplicate');
 246+ if( isset( $warnings['duplicate'] ) ) {
 247+ $dupes = array();
 248+ foreach( $warnings['duplicate'] as $key => $dupe )
 249+ $dupes[] = $dupe->getName();
 250+ $this->getResult()->setIndexedTagName( $dupes, 'duplicate');
 251+ $warnings['duplicate'] = $dupes;
 252+ }
248253
249 - if( isset( $warnings['exists'] ) )
250 - $this->getResult()->setIndexedTagName( $warnings['exists'], 'exists' );
 254+
 255+ if( isset( $warnings['exists'] ) ) {
 256+ $warning = $warnings['exists'];
 257+ unset( $warnings['exists'] );
 258+ $warnings[$warning[0]] = $warning[1]->getName();
 259+ }
251260
252261 if( isset( $warnings['filewasdeleted'] ) )
253 - $warnings['filewasdeleted'] = $warnings['filewasdeleted']->getDBkey();
 262+ $warnings['filewasdeleted'] = $warnings['filewasdeleted']->getName();
254263
255264 $result['result'] = 'Warning';
256265 $result['warnings'] = $warnings;

Comments

#Comment by Brion VIBBER (talk | contribs)   17:06, 27 August 2009

Ok, I think this makes some kind of sense to me now. :D

Status & tagging log