MediaWiki  1.23.8
UploadFromStash.php
Go to the documentation of this file.
1 <?php
30 class UploadFromStash extends UploadBase {
31  protected $mFileKey;
32  protected $mVirtualTempPath;
33  protected $mFileProps;
34  protected $mSourceType;
35 
36  // an instance of UploadStash
37  private $stash;
38 
39  //LocalFile repo
40  private $repo;
41 
47  public function __construct( $user = false, $stash = false, $repo = false ) {
48  // user object. sometimes this won't exist, as when running from cron.
49  $this->user = $user;
50 
51  if ( $repo ) {
52  $this->repo = $repo;
53  } else {
54  $this->repo = RepoGroup::singleton()->getLocalRepo();
55  }
56 
57  if ( $stash ) {
58  $this->stash = $stash;
59  } else {
60  if ( $user ) {
61  wfDebug( __METHOD__ . " creating new UploadStash instance for " . $user->getId() . "\n" );
62  } else {
63  wfDebug( __METHOD__ . " creating new UploadStash instance with no user\n" );
64  }
65 
66  $this->stash = new UploadStash( $this->repo, $this->user );
67  }
68  }
69 
74  public static function isValidKey( $key ) {
75  // this is checked in more detail in UploadStash
76  return (bool)preg_match( UploadStash::KEY_FORMAT_REGEX, $key );
77  }
78 
83  public static function isValidRequest( $request ) {
84  // this passes wpSessionKey to getText() as a default when wpFileKey isn't set.
85  // wpSessionKey has no default which guarantees failure if both are missing
86  // (though that should have been caught earlier)
87  return self::isValidKey( $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) ) );
88  }
89 
95  public function initialize( $key, $name = 'upload_file', $initTempFile = true ) {
102  $metadata = $this->stash->getMetadata( $key );
103  $this->initializePathInfo( $name,
104  $initTempFile ? $this->getRealPath( $metadata['us_path'] ) : false,
105  $metadata['us_size'],
106  false
107  );
108 
109  $this->mFileKey = $key;
110  $this->mVirtualTempPath = $metadata['us_path'];
111  $this->mFileProps = $this->stash->getFileProps( $key );
112  $this->mSourceType = $metadata['us_source_type'];
113  }
114 
118  public function initializeFromRequest( &$request ) {
119  // sends wpSessionKey as a default when wpFileKey is missing
120  $fileKey = $request->getText( 'wpFileKey', $request->getText( 'wpSessionKey' ) );
121 
122  // chooses one of wpDestFile, wpUploadFile, filename in that order.
123  $desiredDestName = $request->getText(
124  'wpDestFile',
125  $request->getText( 'wpUploadFile', $request->getText( 'filename' ) )
126  );
127 
128  $this->initialize( $fileKey, $desiredDestName );
129  }
130 
134  public function getSourceType() {
135  return $this->mSourceType;
136  }
137 
142  public function getTempFileSha1Base36() {
143  return $this->mFileProps['sha1'];
144  }
145 
146  /*
147  * protected function verifyFile() inherited
148  */
149 
156  public function stashFile( User $user = null ) {
157  // replace mLocalFile with an instance of UploadStashFile, which adds some methods
158  // that are useful for stashed files.
159  $this->mLocalFile = parent::stashFile( $user );
160  return $this->mLocalFile;
161  }
162 
167  public function stashSession() {
168  return $this->stashFile()->getFileKey();
169  }
170 
175  public function unsaveUploadedFile() {
176  return $this->stash->removeFile( $this->mFileKey );
177  }
178 
187  public function performUpload( $comment, $pageText, $watch, $user ) {
188  $rv = parent::performUpload( $comment, $pageText, $watch, $user );
189  $this->unsaveUploadedFile();
190  return $rv;
191  }
192 }
UploadBase
Definition: UploadBase.php:38
UploadBase\getRealPath
getRealPath( $srcPath)
Definition: UploadBase.php:253
RepoGroup\singleton
static singleton()
Get a RepoGroup instance.
Definition: RepoGroup.php:53
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
UploadFromStash\$stash
$stash
Definition: UploadFromStash.php:37
UploadFromStash\$mSourceType
$mSourceType
Definition: UploadFromStash.php:34
UploadStash\KEY_FORMAT_REGEX
const KEY_FORMAT_REGEX
Definition: UploadStash.php:47
UploadFromStash\initializeFromRequest
initializeFromRequest(&$request)
Definition: UploadFromStash.php:118
UploadFromStash\getSourceType
getSourceType()
Definition: UploadFromStash.php:134
UploadFromStash\getTempFileSha1Base36
getTempFileSha1Base36()
Get the base 36 SHA1 of the file.
Definition: UploadFromStash.php:142
UploadStash
UploadStash is intended to accomplish a few things:
Definition: UploadStash.php:44
UploadFromStash
Implements uploading from previously stored file.
Definition: UploadFromStash.php:30
UploadFromStash\$repo
$repo
Definition: UploadFromStash.php:40
UploadFromStash\$mVirtualTempPath
$mVirtualTempPath
Definition: UploadFromStash.php:32
UploadBase\$mLocalFile
$mLocalFile
Definition: UploadBase.php:43
$comment
$comment
Definition: importImages.php:107
UploadFromStash\unsaveUploadedFile
unsaveUploadedFile()
Remove a temporarily kept file stashed by saveTempUploadedFile().
Definition: UploadFromStash.php:175
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
UploadFromStash\__construct
__construct( $user=false, $stash=false, $repo=false)
Definition: UploadFromStash.php:47
UploadFromStash\isValidKey
static isValidKey( $key)
Definition: UploadFromStash.php:74
user
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Definition: distributors.txt:9
$name
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:336
UploadFromStash\performUpload
performUpload( $comment, $pageText, $watch, $user)
Perform the upload, then remove the database record afterward.
Definition: UploadFromStash.php:187
UploadFromStash\stashSession
stashSession()
This should return the key instead of the UploadStashFile instance, for backward compatibility.
Definition: UploadFromStash.php:167
UploadFromStash\isValidRequest
static isValidRequest( $request)
Definition: UploadFromStash.php:83
UploadFromStash\stashFile
stashFile(User $user=null)
Stash the file.
Definition: UploadFromStash.php:156
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:237
UploadBase\initializePathInfo
initializePathInfo( $name, $tempPath, $fileSize, $removeTempFile=false)
Initialize the path information.
Definition: UploadBase.php:202
UploadFromStash\$mFileProps
$mFileProps
Definition: UploadFromStash.php:33
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:59
UploadFromStash\$mFileKey
$mFileKey
Definition: UploadFromStash.php:31
UploadFromStash\initialize
initialize( $key, $name='upload_file', $initTempFile=true)
Definition: UploadFromStash.php:95