r62598 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62597‎ | r62598 | r62599 >
Date:21:33, 16 February 2010
Author:ashley
Status:ok
Tags:
Comment:
more braces, documentation and spacing tweaks
Modified paths:
  • /trunk/phase3/includes/upload/UploadBase.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/upload/UploadBase.php
@@ -40,8 +40,9 @@
4141 */
4242 public static function isEnabled() {
4343 global $wgEnableUploads;
44 - if ( !$wgEnableUploads )
 44+ if ( !$wgEnableUploads ) {
4545 return false;
 46+ }
4647
4748 # Check php's file_uploads setting
4849 if( !wfIniGetBool( 'file_uploads' ) ) {
@@ -56,8 +57,9 @@
5758 * Can be overriden by subclasses.
5859 */
5960 public static function isAllowed( $user ) {
60 - if( !$user->isAllowed( 'upload' ) )
 61+ if( !$user->isAllowed( 'upload' ) ) {
6162 return 'upload';
 63+ }
6264 return true;
6365 }
6466
@@ -70,8 +72,9 @@
7173 public static function createFromRequest( &$request, $type = null ) {
7274 $type = $type ? $type : $request->getVal( 'wpSourceType', 'File' );
7375
74 - if( !$type )
 76+ if( !$type ) {
7577 return null;
 78+ }
7679
7780 // Get the upload class
7881 $type = ucfirst( $type );
@@ -82,17 +85,20 @@
8386 if ( is_null( $className ) ) {
8487 $className = 'UploadFrom' . $type;
8588 wfDebug( __METHOD__ . ": class name: $className\n" );
86 - if( !in_array( $type, self::$uploadHandlers ) )
 89+ if( !in_array( $type, self::$uploadHandlers ) ) {
8790 return null;
 91+ }
8892 }
8993
9094 // Check whether this upload class is enabled
91 - if( !call_user_func( array( $className, 'isEnabled' ) ) )
 95+ if( !call_user_func( array( $className, 'isEnabled' ) ) ) {
9296 return null;
 97+ }
9398
9499 // Check whether the request is valid
95 - if( !call_user_func( array( $className, 'isValidRequest' ), $request ) )
 100+ if( !call_user_func( array( $className, 'isValidRequest' ), $request ) ) {
96101 return null;
 102+ }
97103
98104 $handler = new $className;
99105
@@ -139,16 +145,15 @@
140146 /**
141147 * Return the file size
142148 */
143 - public function isEmptyFile(){
 149+ public function isEmptyFile() {
144150 return empty( $this->mFileSize );
145151 }
146152
147153 /**
148 - * getRealPath
149 - * @param string $srcPath the source path
150 - * @returns the real path if it was a virtual url
151 - */
152 - function getRealPath( $srcPath ){
 154+ * @param string $srcPath the source path
 155+ * @returns the real path if it was a virtual URL
 156+ */
 157+ function getRealPath( $srcPath ) {
153158 $repo = RepoGroup::singleton()->getLocalRepo();
154159 if ( $repo->isVirtualUrl( $srcPath ) ) {
155160 return $repo->resolveVirtualUrl( $srcPath );
@@ -164,8 +169,9 @@
165170 /**
166171 * If there was no filename or a zero size given, give up quick.
167172 */
168 - if( $this->isEmptyFile() )
 173+ if( $this->isEmptyFile() ) {
169174 return array( 'status' => self::EMPTY_FILE );
 175+ }
170176
171177 /**
172178 * Look at the contents of the file; if we can recognize the
@@ -174,20 +180,24 @@
175181 */
176182 $verification = $this->verifyFile();
177183 if( $verification !== true ) {
178 - if( !is_array( $verification ) )
 184+ if( !is_array( $verification ) ) {
179185 $verification = array( $verification );
180 - return array( 'status' => self::VERIFICATION_ERROR,
181 - 'details' => $verification );
182 -
 186+ }
 187+ return array(
 188+ 'status' => self::VERIFICATION_ERROR,
 189+ 'details' => $verification
 190+ );
183191 }
184192
185193 $nt = $this->getTitle();
186194 if( is_null( $nt ) ) {
187195 $result = array( 'status' => $this->mTitleError );
188 - if( $this->mTitleError == self::ILLEGAL_FILENAME )
 196+ if( $this->mTitleError == self::ILLEGAL_FILENAME ) {
189197 $result['filtered'] = $this->mFilteredName;
190 - if ( $this->mTitleError == self::FILETYPE_BADTYPE )
 198+ }
 199+ if ( $this->mTitleError == self::FILETYPE_BADTYPE ) {
191200 $result['finalExt'] = $this->mFinalExtension;
 201+ }
192202 return $result;
193203 }
194204 $this->mDestName = $this->getLocalFile()->getName();
@@ -196,8 +206,12 @@
197207 * In some cases we may forbid overwriting of existing files.
198208 */
199209 $overwrite = $this->checkOverwrite();
200 - if( $overwrite !== true )
201 - return array( 'status' => self::OVERWRITE_EXISTING_FILE, 'overwrite' => $overwrite );
 210+ if( $overwrite !== true ) {
 211+ return array(
 212+ 'status' => self::OVERWRITE_EXISTING_FILE,
 213+ 'overwrite' => $overwrite
 214+ );
 215+ }
202216
203217 $error = '';
204218 if( !wfRunHooks( 'UploadVerification',
@@ -218,16 +232,17 @@
219233 $this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension );
220234 $this->checkMacBinary();
221235
222 - #magically determine mime type
 236+ # magically determine mime type
223237 $magic = MimeMagic::singleton();
224238 $mime = $magic->guessMimeType( $this->mTempPath, false );
225239
226 - #check mime type, if desired
 240+ # check mime type, if desired
227241 global $wgVerifyMimeType;
228242 if ( $wgVerifyMimeType ) {
229243 global $wgMimeTypeBlacklist;
230 - if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) )
 244+ if ( $this->checkFileExtension( $mime, $wgMimeTypeBlacklist ) ) {
231245 return array( 'filetype-badmime', $mime );
 246+ }
232247
233248 # Check IE type
234249 $fp = fopen( $this->mTempPath, 'rb' );
@@ -242,7 +257,7 @@
243258 }
244259 }
245260
246 - #check for htmlish code and javascript
 261+ # check for htmlish code and javascript
247262 if( self::detectScript( $this->mTempPath, $mime, $this->mFinalExtension ) ) {
248263 return 'uploadscripted';
249264 }
@@ -276,8 +291,9 @@
277292 * to modify it by uploading a new revision.
278293 */
279294 $nt = $this->getTitle();
280 - if( is_null( $nt ) )
 295+ if( is_null( $nt ) ) {
281296 return true;
 297+ }
282298 $permErrors = $nt->getUserPermissionsErrors( 'edit', $user );
283299 $permErrorsUpload = $nt->getUserPermissionsErrors( 'upload', $user );
284300 $permErrorsCreate = ( $nt->exists() ? array() : $nt->getUserPermissionsErrors( 'create', $user ) );
@@ -302,34 +318,38 @@
303319 $n = strrpos( $filename, '.' );
304320 $partname = $n ? substr( $filename, 0, $n ) : $filename;
305321
306 - /*
 322+ /**
307323 * Check whether the resulting filename is different from the desired one,
308324 * but ignore things like ucfirst() and spaces/underscore things
309325 */
310326 $comparableName = str_replace( ' ', '_', $this->mDesiredDestName );
311327 $comparableName = Title::capitalize( $comparableName, NS_FILE );
312328
313 - if( $this->mDesiredDestName != $filename && $comparableName != $filename )
 329+ if( $this->mDesiredDestName != $filename && $comparableName != $filename ) {
314330 $warnings['badfilename'] = $filename;
 331+ }
315332
316333 // Check whether the file extension is on the unwanted list
317334 global $wgCheckFileExtensions, $wgFileExtensions;
318335 if ( $wgCheckFileExtensions ) {
319 - if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) )
 336+ if ( !$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) {
320337 $warnings['filetype-unwanted-type'] = $this->mFinalExtension;
 338+ }
321339 }
322340
323341 global $wgUploadSizeWarning;
324 - if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) )
 342+ if ( $wgUploadSizeWarning && ( $this->mFileSize > $wgUploadSizeWarning ) ) {
325343 $warnings['large-file'] = $wgUploadSizeWarning;
 344+ }
326345
327 - if ( $this->mFileSize == 0 )
 346+ if ( $this->mFileSize == 0 ) {
328347 $warnings['emptyfile'] = true;
 348+ }
329349
330 -
331350 $exists = self::getExistsWarning( $localFile );
332 - if( $exists !== false )
 351+ if( $exists !== false ) {
333352 $warnings['exists'] = $exists;
 353+ }
334354
335355 // Check dupes against existing files
336356 $hash = File::sha1Base36( $this->mTempPath );
@@ -337,16 +357,19 @@
338358 $title = $this->getTitle();
339359 // Remove all matches against self
340360 foreach ( $dupes as $key => $dupe ) {
341 - if( $title->equals( $dupe->getTitle() ) )
 361+ if( $title->equals( $dupe->getTitle() ) ) {
342362 unset( $dupes[$key] );
 363+ }
343364 }
344 - if( $dupes )
 365+ if( $dupes ) {
345366 $warnings['duplicate'] = $dupes;
 367+ }
346368
347369 // Check dupes against archives
348370 $archivedImage = new ArchivedFile( null, 0, "{$hash}.{$this->mFinalExtension}" );
349 - if ( $archivedImage->getID() > 0 )
 371+ if ( $archivedImage->getID() > 0 ) {
350372 $warnings['duplicate-archive'] = $archivedImage->getName();
 373+ }
351374
352375 return $warnings;
353376 }
@@ -362,11 +385,13 @@
363386 $status = $this->getLocalFile()->upload( $this->mTempPath, $comment, $pageText,
364387 File::DELETE_SOURCE, $this->mFileProps, false, $user );
365388
366 - if( $status->isGood() && $watch )
 389+ if( $status->isGood() && $watch ) {
367390 $user->addWatch( $this->getLocalFile()->getTitle() );
 391+ }
368392
369 - if( $status->isGood() )
 393+ if( $status->isGood() ) {
370394 wfRunHooks( 'UploadComplete', array( &$this ) );
 395+ }
371396
372397 return $status;
373398 }
@@ -378,8 +403,9 @@
379404 * @return Title The title of the file or null in case the name was illegal
380405 */
381406 public function getTitle() {
382 - if ( $this->mTitle !== false )
 407+ if ( $this->mTitle !== false ) {
383408 return $this->mTitle;
 409+ }
384410
385411 /**
386412 * Chop off any directories in the given filename. Then
@@ -425,8 +451,9 @@
426452 # If there was more than one "extension", reassemble the base
427453 # filename to prevent bogus complaints about length
428454 if( count( $ext ) > 1 ) {
429 - for( $i = 0; $i < count( $ext ) - 1; $i++ )
 455+ for( $i = 0; $i < count( $ext ) - 1; $i++ ) {
430456 $partname .= '.' . $ext[$i];
 457+ }
431458 }
432459
433460 if( strlen( $partname ) < 1 ) {
@@ -463,7 +490,6 @@
464491 * @param string $saveName - the destination filename
465492 * @param string $tempSrc - the source temporary file to save
466493 * @return string - full path the stashed file, or false on failure
467 - * @access private
468494 */
469495 protected function saveTempUploadedFile( $saveName, $tempSrc ) {
470496 $repo = RepoGroup::singleton()->getLocalRepo();
@@ -485,8 +511,9 @@
486512 # Couldn't save the file.
487513 return false;
488514 }
489 - if(!isset($_SESSION))
 515+ if( !isset( $_SESSION ) ) {
490516 session_start(); // start up the session (might have been previously closed to prevent php session locking)
 517+ }
491518 $key = $this->getSessionKey();
492519 $_SESSION['wsUploadData'][$key] = array(
493520 'mTempPath' => $status->value,
@@ -500,17 +527,15 @@
501528 /**
502529 * Generate a random session key from stash in cases where we want to start an upload without much information
503530 */
504 - protected function getSessionKey(){
 531+ protected function getSessionKey() {
505532 $key = mt_rand( 0, 0x7fffffff );
506533 $_SESSION['wsUploadData'][$key] = array();
507534 return $key;
508535 }
509536
510 -
511537 /**
512538 * If we've modified the upload file we need to manually remove it
513539 * on exit to clean up.
514 - * @access private
515540 */
516541 public function cleanupTempFile() {
517542 if ( $this->mRemoveTempFile && $this->mTempPath && file_exists( $this->mTempPath ) ) {
@@ -607,7 +632,8 @@
608633 /**
609634 * Heuristic for detecting files that *could* contain JavaScript instructions or
610635 * things that may look like HTML to a browser and are thus
611 - * potentially harmful. The present implementation will produce false positives in some situations.
 636+ * potentially harmful. The present implementation will produce false
 637+ * positives in some situations.
612638 *
613639 * @param string $file Pathname to the temporary upload file
614640 * @param string $mime The mime type of the file
@@ -617,12 +643,12 @@
618644 public static function detectScript( $file, $mime, $extension ) {
619645 global $wgAllowTitlesInSVG;
620646
621 - #ugly hack: for text files, always look at the entire file.
622 - #For binary field, just check the first K.
 647+ # ugly hack: for text files, always look at the entire file.
 648+ # For binary field, just check the first K.
623649
624 - if( strpos( $mime,'text/' ) === 0 )
 650+ if( strpos( $mime,'text/' ) === 0 ) {
625651 $chunk = file_get_contents( $file );
626 - else {
 652+ } else {
627653 $fp = fopen( $file, 'rb' );
628654 $chunk = fread( $fp, 1024 );
629655 fclose( $fp );
@@ -630,44 +656,48 @@
631657
632658 $chunk = strtolower( $chunk );
633659
634 - if( !$chunk )
 660+ if( !$chunk ) {
635661 return false;
 662+ }
636663
637 - #decode from UTF-16 if needed (could be used for obfuscation).
638 - if( substr( $chunk, 0, 2 ) == "\xfe\xff" )
639 - $enc = "UTF-16BE";
640 - elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" )
641 - $enc = "UTF-16LE";
642 - else
 664+ # decode from UTF-16 if needed (could be used for obfuscation).
 665+ if( substr( $chunk, 0, 2 ) == "\xfe\xff" ) {
 666+ $enc = 'UTF-16BE';
 667+ } elseif( substr( $chunk, 0, 2 ) == "\xff\xfe" ) {
 668+ $enc = 'UTF-16LE';
 669+ } else {
643670 $enc = null;
 671+ }
644672
645 - if( $enc )
 673+ if( $enc ) {
646674 $chunk = iconv( $enc, "ASCII//IGNORE", $chunk );
 675+ }
647676
648677 $chunk = trim( $chunk );
649678
650 - #FIXME: convert from UTF-16 if necessarry!
 679+ # FIXME: convert from UTF-16 if necessarry!
651680 wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" );
652681
653 - #check for HTML doctype
654 - if ( preg_match( "/<!DOCTYPE *X?HTML/i", $chunk ) )
 682+ # check for HTML doctype
 683+ if ( preg_match( "/<!DOCTYPE *X?HTML/i", $chunk ) ) {
655684 return true;
 685+ }
656686
657687 /**
658 - * Internet Explorer for Windows performs some really stupid file type
659 - * autodetection which can cause it to interpret valid image files as HTML
660 - * and potentially execute JavaScript, creating a cross-site scripting
661 - * attack vectors.
662 - *
663 - * Apple's Safari browser also performs some unsafe file type autodetection
664 - * which can cause legitimate files to be interpreted as HTML if the
665 - * web server is not correctly configured to send the right content-type
666 - * (or if you're really uploading plain text and octet streams!)
667 - *
668 - * Returns true if IE is likely to mistake the given file for HTML.
669 - * Also returns true if Safari would mistake the given file for HTML
670 - * when served with a generic content-type.
671 - */
 688+ * Internet Explorer for Windows performs some really stupid file type
 689+ * autodetection which can cause it to interpret valid image files as HTML
 690+ * and potentially execute JavaScript, creating a cross-site scripting
 691+ * attack vectors.
 692+ *
 693+ * Apple's Safari browser also performs some unsafe file type autodetection
 694+ * which can cause legitimate files to be interpreted as HTML if the
 695+ * web server is not correctly configured to send the right content-type
 696+ * (or if you're really uploading plain text and octet streams!)
 697+ *
 698+ * Returns true if IE is likely to mistake the given file for HTML.
 699+ * Also returns true if Safari would mistake the given file for HTML
 700+ * when served with a generic content-type.
 701+ */
672702 $tags = array(
673703 '<a href',
674704 '<body',
@@ -693,20 +723,23 @@
694724 * look for JavaScript
695725 */
696726
697 - #resolve entity-refs to look at attributes. may be harsh on big files... cache result?
 727+ # resolve entity-refs to look at attributes. may be harsh on big files... cache result?
698728 $chunk = Sanitizer::decodeCharReferences( $chunk );
699729
700 - #look for script-types
701 - if( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) )
 730+ # look for script-types
 731+ if( preg_match( '!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk ) ) {
702732 return true;
 733+ }
703734
704 - #look for html-style script-urls
705 - if( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) )
 735+ # look for html-style script-urls
 736+ if( preg_match( '!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) {
706737 return true;
 738+ }
707739
708 - #look for css-style script-urls
709 - if( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) )
 740+ # look for css-style script-urls
 741+ if( preg_match( '!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk ) ) {
710742 return true;
 743+ }
711744
712745 wfDebug( __METHOD__ . ": no scripts found\n" );
713746 return false;
@@ -772,12 +805,12 @@
773806 }
774807
775808 # look up scanner configuration
776 - $command = $wgAntivirusSetup[$wgAntivirus]["command"];
777 - $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]["codemap"];
778 - $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]["messagepattern"] ) ?
779 - $wgAntivirusSetup[$wgAntivirus]["messagepattern"] : null;
 809+ $command = $wgAntivirusSetup[$wgAntivirus]['command'];
 810+ $exitCodeMap = $wgAntivirusSetup[$wgAntivirus]['codemap'];
 811+ $msgPattern = isset( $wgAntivirusSetup[$wgAntivirus]['messagepattern'] ) ?
 812+ $wgAntivirusSetup[$wgAntivirus]['messagepattern'] : null;
780813
781 - if ( strpos( $command,"%f" ) === false ) {
 814+ if ( strpos( $command, "%f" ) === false ) {
782815 # simple pattern: append file to scan
783816 $command .= " " . wfEscapeShellArg( $file );
784817 } else {
@@ -790,7 +823,7 @@
791824 # execute virus scanner
792825 $exitCode = false;
793826
794 - #NOTE: there's a 50 line workaround to make stderr redirection work on windows, too.
 827+ # NOTE: there's a 50 line workaround to make stderr redirection work on windows, too.
795828 # that does not seem to be worth the pain.
796829 # Ask me (Duesentrieb) about it if it's ever needed.
797830 $output = wfShellExec( "$command 2>&1", $exitCode );
@@ -814,11 +847,11 @@
815848 } else {
816849 return null;
817850 }
818 - } else if ( $mappedCode === AV_SCAN_ABORTED ) {
 851+ } elseif ( $mappedCode === AV_SCAN_ABORTED ) {
819852 # scan failed because filetype is unknown (probably imune)
820853 wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" );
821854 return null;
822 - } else if ( $mappedCode === AV_NO_VIRUS ) {
 855+ } elseif ( $mappedCode === AV_NO_VIRUS ) {
823856 # no virus found
824857 wfDebug( __METHOD__ . ": file passed virus scan.\n" );
825858 return false;
@@ -846,8 +879,6 @@
847880 * from Internet Explorer on Mac OS Classic and Mac OS X will be.
848881 * If so, the data fork will be extracted to a second temporary file,
849882 * which will then be checked for validity and either kept or discarded.
850 - *
851 - * @access private
852883 */
853884 private function checkMacBinary() {
854885 $macbin = new MacBinary( $this->mTempPath );
@@ -872,25 +903,26 @@
873904 * forbid this user from performing the upload.
874905 *
875906 * @return mixed true on success, error string on failure
876 - * @access private
877907 */
878908 private function checkOverwrite() {
879909 global $wgUser;
880910 // First check whether the local file can be overwritten
881911 $file = $this->getLocalFile();
882912 if( $file->exists() ) {
883 - if( !self::userCanReUpload( $wgUser, $file ) )
 913+ if( !self::userCanReUpload( $wgUser, $file ) ) {
884914 return 'fileexists-forbidden';
885 - else
 915+ } else {
886916 return true;
 917+ }
887918 }
888919
889920 /* Check shared conflicts: if the local file does not exist, but
890921 * wfFindFile finds a file, it exists in a shared repository.
891922 */
892923 $file = wfFindFile( $this->getTitle() );
893 - if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) )
 924+ if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) {
894925 return 'fileexists-shared-forbidden';
 926+ }
895927
896928 return true;
897929 }
@@ -903,14 +935,18 @@
904936 * @return bool
905937 */
906938 public static function userCanReUpload( User $user, $img ) {
907 - if( $user->isAllowed( 'reupload' ) )
 939+ if( $user->isAllowed( 'reupload' ) ) {
908940 return true; // non-conditional
909 - if( !$user->isAllowed( 'reupload-own' ) )
 941+ }
 942+ if( !$user->isAllowed( 'reupload-own' ) ) {
910943 return false;
911 - if( is_string( $img ) )
 944+ }
 945+ if( is_string( $img ) ) {
912946 $img = wfLocalFile( $img );
913 - if ( !( $img instanceof LocalFile ) )
 947+ }
 948+ if ( !( $img instanceof LocalFile ) ) {
914949 return false;
 950+ }
915951
916952 return $user->getId() == $img->getUser( 'id' );
917953 }
@@ -927,14 +963,17 @@
928964 * @return mixed False if the file does not exists, else an array
929965 */
930966 public static function getExistsWarning( $file ) {
931 - if( $file->exists() )
 967+ if( $file->exists() ) {
932968 return array( 'warning' => 'exists', 'file' => $file );
 969+ }
933970
934 - if( $file->getTitle()->getArticleID() )
 971+ if( $file->getTitle()->getArticleID() ) {
935972 return array( 'warning' => 'page-exists', 'file' => $file );
 973+ }
936974
937 - if ( $file->wasDeleted() && !$file->exists() )
 975+ if ( $file->wasDeleted() && !$file->exists() ) {
938976 return array( 'warning' => 'was-deleted', 'file' => $file );
 977+ }
939978
940979 if( strpos( $file->getName(), '.' ) == false ) {
941980 $partname = $file->getName();
@@ -955,29 +994,46 @@
956995 $nt_lc = Title::makeTitle( NS_FILE, "{$partname}.{$normalizedExtension}" );
957996 $file_lc = wfLocalFile( $nt_lc );
958997
959 - if( $file_lc->exists() )
960 - return array( 'warning' => 'exists-normalized', 'file' => $file, 'normalizedFile' => $file_lc );
 998+ if( $file_lc->exists() ) {
 999+ return array(
 1000+ 'warning' => 'exists-normalized',
 1001+ 'file' => $file,
 1002+ 'normalizedFile' => $file_lc
 1003+ );
 1004+ }
9611005 }
9621006
9631007 if ( self::isThumbName( $file->getName() ) ) {
9641008 # Check for filenames like 50px- or 180px-, these are mostly thumbnails
9651009 $nt_thb = Title::newFromText( substr( $partname , strpos( $partname , '-' ) +1 ) . '.' . $extension, NS_FILE );
9661010 $file_thb = wfLocalFile( $nt_thb );
967 - if( $file_thb->exists() )
968 - return array( 'warning' => 'thumb', 'file' => $file, 'thumbFile' => $file_thb );
969 - else
 1011+ if( $file_thb->exists() ) {
 1012+ return array(
 1013+ 'warning' => 'thumb',
 1014+ 'file' => $file,
 1015+ 'thumbFile' => $file_thb
 1016+ );
 1017+ } else {
9701018 // File does not exist, but we just don't like the name
971 - return array( 'warning' => 'thumb-name', 'file' => $file, 'thumbFile' => $file_thb );
 1019+ return array(
 1020+ 'warning' => 'thumb-name',
 1021+ 'file' => $file,
 1022+ 'thumbFile' => $file_thb
 1023+ );
 1024+ }
9721025 }
9731026
9741027
9751028 foreach( self::getFilenamePrefixBlacklist() as $prefix ) {
976 - if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix )
977 - return array( 'warning' => 'bad-prefix', 'file' => $file, 'prefix' => $prefix );
 1029+ if ( substr( $partname, 0, strlen( $prefix ) ) == $prefix ) {
 1030+ return array(
 1031+ 'warning' => 'bad-prefix',
 1032+ 'file' => $file,
 1033+ 'prefix' => $prefix
 1034+ );
 1035+ }
9781036 }
9791037
980 -
981 -
9821038 return false;
9831039 }
9841040
@@ -995,7 +1051,7 @@
9961052 }
9971053
9981054 /**
999 - * Get a list of blacklisted filename prefixes from [[MediaWiki:filename-prefix-blacklist]]
 1055+ * Get a list of blacklisted filename prefixes from [[MediaWiki:Filename-prefix-blacklist]]
10001056 *
10011057 * @return array list of prefixes
10021058 */
@@ -1021,7 +1077,7 @@
10221078 return $blacklist;
10231079 }
10241080
1025 - public function getImageInfo($result) {
 1081+ public function getImageInfo( $result ) {
10261082 $file = $this->getLocalFile();
10271083 $imParam = ApiQueryImageInfo::getPropertyNames();
10281084 return ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result );

Status & tagging log