From 3e4467422987e4214e563133c7f4d7168e1dab60 Mon Sep 17 00:00:00 2001 From: Bryan Tong Minh Date: Sat, 5 Mar 2011 14:44:28 +0000 Subject: [PATCH] Move the file related parts of Title::isValidMoveOperation to its own function, Title::validateFileMoveOperation --- includes/Title.php | 59 +++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index f289bd4658..4c5f0183f6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -2986,28 +2986,7 @@ class Title { } // Image-specific checks - if ( $this->getNamespace() == NS_FILE ) { - if ( $nt->getNamespace() != NS_FILE ) { - $errors[] = array( 'imagenocrossnamespace' ); - } - $file = wfLocalFile( $this ); - if ( $file->exists() ) { - if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) { - $errors[] = array( 'imageinvalidfilename' ); - } - if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) { - $errors[] = array( 'imagetypemismatch' ); - } - } - $destfile = wfLocalFile( $nt ); - if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) { - $errors[] = array( 'file-exists-sharedrepo' ); - } - } - - if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) { - $errors[] = array( 'nonfile-cannot-move-to-file' ); - } + $errors = array_merge( $errors, $this->validateFileMoveOperation( $nt ) ); if ( $auth ) { $errors = wfMergeErrorArrays( $errors, @@ -3048,6 +3027,42 @@ class Title { } return $errors; } + + /** + * Check if the requested move target is a valid file move target + * @param Title $nt Target title + * @return array List of errors + */ + protected function validateFileMoveOperation( $nt ) { + global $wgUser; + + $errors = array(); + + if ( $nt->getNamespace() != NS_FILE ) { + $errors[] = array( 'imagenocrossnamespace' ); + } + + $file = wfLocalFile( $this ); + if ( $file->exists() ) { + if ( $nt->getText() != wfStripIllegalFilenameChars( $nt->getText() ) ) { + $errors[] = array( 'imageinvalidfilename' ); + } + if ( !File::checkExtensionCompatibility( $file, $nt->getDBkey() ) ) { + $errors[] = array( 'imagetypemismatch' ); + } + } + + $destFile = wfLocalFile( $nt ); + if ( !$wgUser->isAllowed( 'reupload-shared' ) && !$destfile->exists() && wfFindFile( $nt ) ) { + $errors[] = array( 'file-exists-sharedrepo' ); + } + + if ( $nt->getNamespace() == NS_FILE && $this->getNamespace() != NS_FILE ) { + $errors[] = array( 'nonfile-cannot-move-to-file' ); + } + + return $errors; + } /** * Move a title to a new location -- 2.20.1