Index: trunk/phase3/includes/Title.php |
— | — | @@ -2986,29 +2986,8 @@ |
2987 | 2987 | } |
2988 | 2988 | |
2989 | 2989 | // 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 ) ); |
3008 | 2991 | |
3009 | | - if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) { |
3010 | | - $errors[] = array( 'nonfile-cannot-move-to-file' ); |
3011 | | - } |
3012 | | - |
3013 | 2992 | if ( $auth ) { |
3014 | 2993 | $errors = wfMergeErrorArrays( $errors, |
3015 | 2994 | $this->getUserPermissionsErrors( 'move', $wgUser ), |
— | — | @@ -3048,7 +3027,43 @@ |
3049 | 3028 | } |
3050 | 3029 | return $errors; |
3051 | 3030 | } |
| 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 | + } |
3052 | 3060 | |
| 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 | + |
3053 | 3068 | /** |
3054 | 3069 | * Move a title to a new location |
3055 | 3070 | * |