r83282 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83281‎ | r83282 | r83283 >
Date:14:44, 5 March 2011
Author:btongminh
Status:resolved (Comments)
Tags:
Comment:
Move the file related parts of Title::isValidMoveOperation to its own function, Title::validateFileMoveOperation
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -2986,29 +2986,8 @@
29872987 }
29882988
29892989 // Image-specific checks
2990 - if ( $this->getNamespace() == NS_FILE ) {
2991 - if ( $nt->getNamespace() != NS_FILE ) {
2992 - $errors[] = array( 'imagenocrossnamespace' );
2993 - }
2994 - $file = wfLocalFile( $this );
2995 - if ( $file->exists() ) {
2996 - if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
2997 - $errors[] = array( 'imageinvalidfilename' );
2998 - }
2999 - if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
3000 - $errors[] = array( 'imagetypemismatch' );
3001 - }
3002 - }
3003 - $destfile = wfLocalFile( $nt );
3004 - if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
3005 - $errors[] = array( 'file-exists-sharedrepo' );
3006 - }
3007 - }
 2990+ $errors = array_merge( $errors, $this->validateFileMoveOperation( $nt ) );
30082991
3009 - if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) {
3010 - $errors[] = array( 'nonfile-cannot-move-to-file' );
3011 - }
3012 -
30132992 if ( $auth ) {
30142993 $errors = wfMergeErrorArrays( $errors,
30152994 $this->getUserPermissionsErrors( 'move', $wgUser ),
@@ -3048,7 +3027,43 @@
30493028 }
30503029 return $errors;
30513030 }
 3031+
 3032+ /**
 3033+ * Check if the requested move target is a valid file move target
 3034+ * @param Title $nt Target title
 3035+ * @return array List of errors
 3036+ */
 3037+ protected function validateFileMoveOperation( $nt ) {
 3038+ global $wgUser;
 3039+
 3040+ $errors = array();
 3041+
 3042+ if ( $nt->getNamespace() != NS_FILE ) {
 3043+ $errors[] = array( 'imagenocrossnamespace' );
 3044+ }
 3045+
 3046+ $file = wfLocalFile( $this );
 3047+ if ( $file->exists() ) {
 3048+ if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) {
 3049+ $errors[] = array( 'imageinvalidfilename' );
 3050+ }
 3051+ if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) {
 3052+ $errors[] = array( 'imagetypemismatch' );
 3053+ }
 3054+ }
 3055+
 3056+ $destFile = wfLocalFile( $nt );
 3057+ if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) {
 3058+ $errors[] = array( 'file-exists-sharedrepo' );
 3059+ }
30523060
 3061+ if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) {
 3062+ $errors[] = array( 'nonfile-cannot-move-to-file' );
 3063+ }
 3064+
 3065+ return $errors;
 3066+ }
 3067+
30533068 /**
30543069 * Move a title to a new location
30553070 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r83285Follow-up r83282: Re-add the lost $this->getNamespace() == NS_FILE, forgot to...btongminh14:47, 5 March 2011
r84489Fix variable typo introduced in r83282reedy21:26, 21 March 2011

Comments

#Comment by MaxSem (talk | contribs)   14:48, 5 March 2011

This conversion lost check if ( $this->getNamespace() == NS_FILE ), therefore it will trigger errors on moves of non-files.

#Comment by MaxSem (talk | contribs)   14:49, 5 March 2011

Whoops, already fixed:)

Status & tagging log