protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType;
protected $mTitle = false, $mTitleError = 0;
protected $mFilteredName, $mFinalExtension;
- protected $mLocalFile, $mFileSize, $mFileProps;
+ protected $mLocalFile, $mStashFile, $mFileSize, $mFileProps;
protected $mBlackListedExtensions;
protected $mJavaDetected, $mSVGNSError;
$warnings['empty-file'] = true;
}
+ $hash = $this->getTempFileSha1Base36();
$exists = self::getExistsWarning( $localFile );
if ( $exists !== false ) {
$warnings['exists'] = $exists;
+
+ // check if file is an exact duplicate of current file version
+ if ( $hash === $localFile->getSha1() ) {
+ $warnings['no-change'] = $localFile;
+ }
+
+ // check if file is an exact duplicate of older versions of this file
+ $history = $localFile->getHistory();
+ foreach ( $history as $oldFile ) {
+ if ( $hash === $oldFile->getSha1() ) {
+ $warnings['duplicate-version'][] = $oldFile;
+ }
+ }
}
if ( $localFile->wasDeleted() && !$localFile->exists() ) {
}
// Check dupes against existing files
- $hash = $this->getTempFileSha1Base36();
$dupes = RepoGroup::singleton()->findBySha1( $hash );
$title = $this->getTitle();
// Remove all matches against self
/**
* Return the local file and initializes if necessary.
*
- * @return LocalFile|UploadStashFile|null
+ * @return LocalFile|null
*/
public function getLocalFile() {
if ( is_null( $this->mLocalFile ) ) {
return $this->mLocalFile;
}
+ /**
+ * @return UploadStashFile|null
+ */
+ public function getStashFile() {
+ return $this->mStashFile;
+ }
+
/**
* Like stashFile(), but respects extensions' wishes to prevent the stashing. verifyUpload() must
* be called before calling this method (unless $isPartial is true).
*/
public function tryStashFile( User $user, $isPartial = false ) {
if ( !$isPartial ) {
- $props = $this->mFileProps;
- $error = null;
- Hooks::run( 'UploadStashFile', [ $this, $user, $props, &$error ] );
+ $error = $this->runUploadStashFileHook( $user );
if ( $error ) {
- if ( !is_array( $error ) ) {
- $error = [ $error ];
- }
return call_user_func_array( 'Status::newFatal', $error );
}
}
}
}
+ /**
+ * @param User $user
+ * @return array|null Error message and parameters, null if there's no error
+ */
+ protected function runUploadStashFileHook( User $user ) {
+ $props = $this->mFileProps;
+ $error = null;
+ Hooks::run( 'UploadStashFile', [ $this, $user, $props, &$error ] );
+ if ( $error ) {
+ if ( !is_array( $error ) ) {
+ $error = [ $error ];
+ }
+ }
+ return $error;
+ }
+
/**
* If the user does not supply all necessary information in the first upload
* form submission (either by accident or by design) then we may want to
protected function doStashFile( User $user = null ) {
$stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $user );
$file = $stash->stashFile( $this->mTempPath, $this->getSourceType() );
- $this->mLocalFile = $file;
+ $this->mStashFile = $file;
return $file;
}
* @return array Containing the namespace URI and prefix
*/
private static function splitXmlNamespace( $element ) {
- // 'http://www.w3.org/2000/svg:script' -> array( 'http://www.w3.org/2000/svg', 'script' )
+ // 'http://www.w3.org/2000/svg:script' -> [ 'http://www.w3.org/2000/svg', 'script' ]
$parts = explode( ':', strtolower( $element ) );
$name = array_pop( $parts );
$ns = implode( ':', $parts );
* @return array Image info
*/
public function getImageInfo( $result ) {
- $file = $this->getLocalFile();
- /** @todo This cries out for refactoring.
- * We really want to say $file->getAllInfo(); here.
- * Perhaps "info" methods should be moved into files, and the API should
- * just wrap them in queries.
- */
- if ( $file instanceof UploadStashFile ) {
+ $localFile = $this->getLocalFile();
+ $stashFile = $this->getStashFile();
+ // Calling a different API module depending on whether the file was stashed is less than optimal.
+ // In fact, calling API modules here at all is less than optimal. Maybe it should be refactored.
+ if ( $stashFile ) {
$imParam = ApiQueryStashImageInfo::getPropertyNames();
- $info = ApiQueryStashImageInfo::getInfo( $file, array_flip( $imParam ), $result );
+ $info = ApiQueryStashImageInfo::getInfo( $stashFile, array_flip( $imParam ), $result );
} else {
$imParam = ApiQueryImageInfo::getPropertyNames();
- $info = ApiQueryImageInfo::getInfo( $file, array_flip( $imParam ), $result );
+ $info = ApiQueryImageInfo::getInfo( $localFile, array_flip( $imParam ), $result );
}
return $info;