return $this->mLocalFile;
}
+ /**
+ * Like stashFile(), but respects extensions' wishes to prevent the stashing.
+ *
+ * Upload stash exceptions are also caught and converted to an error status.
+ *
+ * @since 1.28
+ * @param User $user
+ * @return Status If successful, value is an UploadStashFile instance
+ */
+ public function tryStashFile( User $user ) {
+ $props = $this->mFileProps;
+ $error = null;
+ Hooks::run( 'UploadStashFile', [ $this, $user, $props, &$error ] );
+ if ( $error ) {
+ if ( !is_array( $error ) ) {
+ $error = [ $error ];
+ }
+ return call_user_func_array( 'Status::newFatal', $error );
+ }
+ try {
+ $file = $this->doStashFile( $user );
+ return Status::newGood( $file );
+ } catch ( UploadStashException $e ) {
+ return Status::newFatal( 'uploadstash-exception', get_class( $e ), $e->getMessage() );
+ }
+ }
+
/**
* 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
* which can be passed through a form or API request to find this stashed
* file again.
*
+ * @deprecated since 1.28 Use tryStashFile() instead
* @param User $user
* @return UploadStashFile Stashed file
* @throws UploadStashBadPathException
* @throws UploadStashNotLoggedInException
*/
public function stashFile( User $user = null ) {
+ return $this->doStashFile( $user );
+ }
+
+ /**
+ * Implementation for stashFile() and tryStashFile().
+ *
+ * @param User $user
+ * @return UploadStashFile Stashed file
+ */
+ protected function doStashFile( User $user = null ) {
$stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash( $user );
$file = $stash->stashFile( $this->mTempPath, $this->getSourceType() );
$this->mLocalFile = $file;
*/
public function stashFileGetKey() {
wfDeprecated( __METHOD__, '1.28' );
- return $this->stashFile()->getFileKey();
+ return $this->doStashFile()->getFileKey();
}
/**
*/
public function stashSession() {
wfDeprecated( __METHOD__, '1.28' );
- return $this->stashFile()->getFileKey();
+ return $this->doStashFile()->getFileKey();
}
/**