wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
return;
}
+
$this->showUploadForm( $this->getUploadForm() );
}
protected function processUpload() {
global $wgUser, $wgOut;
- // Verify permissions
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true ) {
- $wgOut->showPermissionsErrorPage( $permErrors );
- return;
- }
-
// Fetch the file if required
$status = $this->mUpload->fetchFile();
if( !$status->isOK() ) {
$this->processVerificationError( $details );
return;
}
+
+ // Verify permissions for this title
+ $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ if( $permErrors !== true ) {
+ $code = array_shift( $permErrors[0] );
+ $this->showRecoverableUploadError( wfMsgExt( $code,
+ 'parseinline', $permErrors[0] ) );
+ return;
+ }
$this->mLocalFile = $this->mUpload->getLocalFile();
$this->showRecoverableUploadError( wfMsgExt( 'illegalfilename',
'parseinline', $details['filtered'] ) );
break;
- case UploadBase::OVERWRITE_EXISTING_FILE:
- $this->showRecoverableUploadError( wfMsgExt( $details['overwrite'],
- 'parseinline' ) );
- break;
case UploadBase::FILETYPE_MISSING:
$this->showRecoverableUploadError( wfMsgExt( 'filetype-missing',
'parseinline' ) );
const EMPTY_FILE = 3;
const MIN_LENGTH_PARTNAME = 4;
const ILLEGAL_FILENAME = 5;
- const OVERWRITE_EXISTING_FILE = 7;
+ const OVERWRITE_EXISTING_FILE = 7; # Not used anymore; handled by verifyPermissions()
const FILETYPE_MISSING = 8;
const FILETYPE_BADTYPE = 9;
const VERIFICATION_ERROR = 10;
* Verify whether the upload is sane.
* @return mixed self::OK or else an array with error information
*/
- public function verifyUpload( ) {
+ public function verifyUpload() {
/**
* If there was no filename or a zero size given, give up quick.
*/
/**
* Make sure this file can be created
*/
- $result = $this->validateNameAndOverwrite();
+ $result = $this->validateName();
if( $result !== true ) {
return $result;
}
* @return mixed true if valid, otherwise and array with 'status'
* and other keys
**/
- public function validateNameAndOverwrite() {
+ protected function validateName() {
$nt = $this->getTitle();
if( is_null( $nt ) ) {
$result = array( 'status' => $this->mTitleError );
}
$this->mDestName = $this->getLocalFile()->getName();
- /**
- * In some cases we may forbid overwriting of existing files.
- */
- $overwrite = $this->checkOverwrite();
- if( $overwrite !== true ) {
- return array(
- 'status' => self::OVERWRITE_EXISTING_FILE,
- 'overwrite' => $overwrite
- );
- }
return true;
}
* @return mixed true of the file is verified, array otherwise.
*/
protected function verifyFile() {
+ # get the title, even though we are doing nothing with it, because
+ # we need to populate mFinalExtension
+ $nt = $this->getTitle();
+
$this->mFileProps = File::getPropsFromPath( $this->mTempPath, $this->mFinalExtension );
$this->checkMacBinary();
}
/**
- * Check whether the user can edit, upload and create the image.
+ * Check whether the user can edit, upload and create the image. This
+ * checks only against the current title; if it returns errors, it may
+ * very well be that another title will not give errors. Therefore
+ * isAllowed() should be called as well for generic is-user-blocked or
+ * can-user-upload checking.
*
* @param $user the User object to verify the permissions against
* @return mixed An array as returned by getUserPermissionsErrors or true
$permErrors = array_merge( $permErrors, wfArrayDiff2( $permErrorsCreate, $permErrors ) );
return $permErrors;
}
+
+ $overwriteError = $this->checkOverwrite( $user );
+ if ( $overwriteError !== true ) {
+ return array( array( $overwriteError ) );
+ }
+
return true;
}
*
* @return mixed true on success, error string on failure
*/
- private function checkOverwrite() {
- global $wgUser;
+ private function checkOverwrite( $user ) {
// First check whether the local file can be overwritten
$file = $this->getLocalFile();
if( $file->exists() ) {
- if( !self::userCanReUpload( $wgUser, $file ) ) {
+ if( !self::userCanReUpload( $user, $file ) ) {
return 'fileexists-forbidden';
} else {
return true;
* wfFindFile finds a file, it exists in a shared repository.
*/
$file = wfFindFile( $this->getTitle() );
- if ( $file && !$wgUser->isAllowed( 'reupload-shared' ) ) {
+ if ( $file && !$user->isAllowed( 'reupload-shared' ) ) {
return 'fileexists-shared-forbidden';
}
}
public function convertVerifyErrorToStatus( $error ) {
- $args = func_get_args();
- array_shift($args);
- return Status::newFatal( $this->getVerificationErrorCode( $error ), $args );
+ $code = $error['status'];
+ unset( $code['status'] );
+ return Status::newFatal( $this->getVerificationErrorCode( $code ), $error );
}
}