class UploadFromBase {
var $mTempPath;
var $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType;
- var $mTitle = false;
+ var $mTitle = false, $mTitleError = 0;
var $mFilteredName, $mFinalExtension;
const SUCCESS = 0;
}
$nt = $this->getTitle();
- if( !( $nt instanceof Title ) ) {
- if( $nt == self::ILLEGAL_FILENAME )
+ if( is_null( $nt ) ) {
+ if( $this->mTitleError == self::ILLEGAL_FILENAME )
$resultDetails = array( 'filtered' => $this->mFilteredName );
- if ( $nt == self::FILETYPE_BADTYPE )
+ if ( $this->mTitleError == self::FILETYPE_BADTYPE )
$resultDetails = array( 'finalExt' => $this->mFinalExtension );
- // $nt is an error constant
- return $nt;
+ return $this->mTitleError;
}
$this->mLocalFile = wfLocalFile( $nt );
$this->mDestName = $this->mLocalFile->getName();
* to modify it by uploading a new revision.
*/
$nt = $this->getTitle();
+ if( is_null( $nt ) )
+ return true;
$permErrors = $nt->getUserPermissionsErrors( 'edit', $user );
$permErrorsUpload = $nt->getUserPermissionsErrors( 'upload', $user );
$permErrorsCreate = ( $nt->exists() ? array() : $nt->getUserPermissionsErrors( 'create', $user ) );
}
/**
- * Returns a title or a numeric error constant
+ * Returns a title or null
*/
function getTitle() {
if ( $this->mTitle !== false )
global $wgCheckFileExtensions, $wgStrictFileExtensions;
global $wgFileExtensions, $wgFileBlacklist;
if ( $this->mFinalExtension == '' ) {
- return self::FILETYPE_MISSING;
+ $this->mTitleError = self::FILETYPE_MISSING;
+ return $this->mTitle = null;
} elseif ( $this->checkFileExtensionList( $ext, $wgFileBlacklist ) ||
( $wgCheckFileExtensions && $wgStrictFileExtensions &&
!$this->checkFileExtension( $this->mFinalExtension, $wgFileExtensions ) ) ) {
- return self::FILETYPE_BADTYPE;
+ $this->mTitleError = self::FILETYPE_BADTYPE;
+ return $this->mTitle = null;
}
# If there was more than one "extension", reassemble the base
}
if( strlen( $partname ) < 1 ) {
- return self::MIN_LENGHT_PARTNAME;
+ $this->mTitleError = self::MIN_LENGHT_PARTNAME;
+ return $this->mTitle = null;
}
$nt = Title::makeTitleSafe( NS_IMAGE, $this->mFilteredName );
- if( is_null( $nt ) )
- return self::ILLEGAL_FILENAME;
+ if( is_null( $nt ) ) {
+ $this->mTitleError = self::ILLEGAL_FILENAME;
+ return $this->mTitle = null;
+ }
return $this->mTitle = $nt;
}
function getLocalFile() {
- if( is_null( $this->mLocalFile ) )
- $this->mLocalFile = wfLocalFile( $this->getTitle() );
+ if( is_null( $this->mLocalFile ) ) {
+ $nt = $this->getTitle();
+ $this->mLocalFile = is_null( $nt ) ? null : wfLocalFile( $nt );
+ }
return $this->mLocalFile;
}
return UploadFromBase::BEFORE_PROCESSING;
}
- $nt = $this->mUpload->getTitle();
- // Hold back returning errors for a bit so that verifyUpload can fill in the details
- if ( $nt instanceof Title ) {
- /**
- * If the image is protected, non-sysop users won't be able
- * to modify it by uploading a new revision.
- */
- $permErrors = $this->mUpload->verifyPermissions( $wgUser );
- if( $permErrors !== true ) {
- $resultDetails = array( 'permissionserrors' => $permErrors );
- return UploadFromBase::PROTECTED_PAGE;
- }
+ /**
+ * If the image is protected, non-sysop users won't be able
+ * to modify it by uploading a new revision.
+ */
+ $permErrors = $this->mUpload->verifyPermissions( $wgUser );
+ if( $permErrors !== true ) {
+ $resultDetails = array( 'permissionserrors' => $permErrors );
+ return UploadFromBase::PROTECTED_PAGE;
}
// Check whether this is a sane upload