58 $this->repo = MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo();
62 $this->stash = $stash;
65 wfDebug( __METHOD__ .
" creating new UploadStash instance for " . $user->getId() );
67 wfDebug( __METHOD__ .
" creating new UploadStash instance with no user" );
70 $this->stash =
new UploadStash( $this->repo, $user );
80 return (
bool)preg_match( UploadStash::KEY_FORMAT_REGEX, $key );
91 return self::isValidKey( $request->getText(
'wpFileKey', $request->getText(
'wpSessionKey' ) ) );
99 public function initialize( $key, $name =
'upload_file', $initTempFile =
true ) {
106 $metadata = $this->stash->getMetadata( $key );
107 $tempPath = $initTempFile ? $this->
getRealPath( $metadata[
'us_path'] ) :
null;
108 if ( $tempPath ===
false ) {
113 $metadata[
'us_size'],
117 $this->mFileKey = $key;
118 $this->mVirtualTempPath = $metadata[
'us_path'];
119 $this->mFileProps = $this->stash->getFileProps( $key );
120 $this->mSourceType = $metadata[
'us_source_type'];
128 $fileKey = $request->getText(
'wpFileKey', $request->getText(
'wpSessionKey' ) );
131 $desiredDestName = $request->getText(
133 $request->getText(
'wpUploadFile', $request->getText(
'filename' ) )
136 $this->
initialize( $fileKey, $desiredDestName );
143 return $this->mSourceType;
154 if ( !is_array( $this->mFileProps ) ) {
155 throw new LogicException(
"mFileProps should never be null" );
157 return $this->mFileProps[
'sha1'];
166 return $this->stash->removeFile( $this->mFileKey );
173 parent::postProcessUpload();
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
UploadBase and subclasses are the backend of MediaWiki's file uploads.
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Implements uploading from previously stored file.
__construct(?UserIdentity $user=null, $stash=false, $repo=false)
getTempFileSha1Base36()
Get the base 36 SHA1 of the file.
static isValidRequest( $request)
initializeFromRequest(&$request)
unsaveUploadedFile()
Remove a temporarily kept file stashed by saveTempUploadedFile().
postProcessUpload()
Remove the database record after a successful upload.
initialize( $key, $name='upload_file', $initTempFile=true)
UploadStash is intended to accomplish a few things: