+ /**
+ * @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).
+ *
+ * Upload stash exceptions are also caught and converted to an error status.
+ *
+ * @since 1.28
+ * @param User $user
+ * @param bool $isPartial Pass `true` if this is a part of a chunked upload (not a complete file).
+ * @return Status If successful, value is an UploadStashFile instance
+ */
+ public function tryStashFile( User $user, $isPartial = false ) {
+ if ( !$isPartial ) {
+ $error = $this->runUploadStashFileHook( $user );
+ if ( $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() );
+ }
+ }
+
+ /**
+ * @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;
+ }
+