Go to the documentation of this file.
100 if ( is_object( $this->
user ) ) {
101 $this->userId = $this->
user->getId();
102 $this->isLoggedIn = $this->
user->isLoggedIn();
119 public function getFile( $key, $noAuth =
false ) {
120 if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
124 if ( !$noAuth && !$this->isLoggedIn ) {
126 ' No user is logged in, files must belong to users' );
129 if ( !isset( $this->fileMetadata[$key] ) ) {
136 if ( !isset( $this->fileMetadata[$key] ) ) {
144 if ( strlen( $this->fileMetadata[$key][
'us_props'] ) ) {
145 $this->fileProps[$key] =
unserialize( $this->fileMetadata[$key][
'us_props'] );
147 wfDebug( __METHOD__ .
" fetched props for $key from file\n" );
148 $path = $this->fileMetadata[$key][
'us_path'];
149 $this->fileProps[$key] = $this->repo->getFileProps(
$path );
153 if ( !$this->
files[$key]->exists() ) {
154 wfDebug( __METHOD__ .
" tried to get file at $key, but it doesn't exist\n" );
160 if ( $this->fileMetadata[$key][
'us_user'] != $this->userId ) {
162 .
"belong to the current user." );
166 return $this->
files[$key];
178 return $this->fileMetadata[$key];
190 return $this->fileProps[$key];
206 if ( !is_file(
$path ) ) {
207 wfDebug( __METHOD__ .
" tried to stash file at '$path', but it doesn't exist\n" );
213 wfDebug( __METHOD__ .
" stashing file at '$path'\n" );
218 if ( !preg_match(
"/\\.\\Q$extension\\E$/",
$path ) ) {
219 $pathWithGoodExtension =
"$path.$extension";
221 $pathWithGoodExtension =
$path;
229 list( $usec, $sec ) = explode(
' ', microtime() );
230 $usec = substr( $usec, 2 );
231 $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) .
'.' .
232 Wikimedia\base_convert( mt_rand(), 10, 36 ) .
'.' .
233 $this->userId .
'.' .
238 if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
242 wfDebug( __METHOD__ .
" key for '$path': $key\n" );
245 $storeStatus = $this->repo->storeTemp( basename( $pathWithGoodExtension ),
$path );
247 if ( !$storeStatus->isOK() ) {
256 $error = $storeStatus->getErrorsArray();
257 $error = reset( $error );
258 if ( !
count( $error ) ) {
259 $error = $storeStatus->getWarningsArray();
260 $error = reset( $error );
261 if ( !
count( $error ) ) {
262 $error = [
'unknown',
'no error recorded' ];
267 $errorMsg = array_shift( $error );
271 $stashPath = $storeStatus->value;
274 if ( !$this->isLoggedIn ) {
276 .
' No user is logged in, files must belong to users' );
280 wfDebug( __METHOD__ .
" inserting $stashPath under $key\n" );
281 $dbw = $this->repo->getMasterDB();
284 if ( strlen( $serializedFileProps ) > self::MAX_US_PROPS_SIZE ) {
292 $this->fileMetadata[$key] = [
295 'us_orig_path' =>
$path,
296 'us_path' => $stashPath,
297 'us_props' => $dbw->encodeBlob( $serializedFileProps ),
305 'us_source_type' => $sourceType,
306 'us_timestamp' => $dbw->timestamp(),
307 'us_status' =>
'finished'
312 $this->fileMetadata[$key],
318 $this->fileMetadata[$key][
'us_id'] = $dbw->insertId();
320 # create the UploadStashFile object for this file.
334 if ( !$this->isLoggedIn ) {
336 .
' No user is logged in, files must belong to users' );
339 wfDebug( __METHOD__ .
' clearing all rows for user ' . $this->userId .
"\n" );
340 $dbw = $this->repo->getMasterDB();
343 [
'us_user' => $this->userId ],
349 $this->fileMetadata = [];
363 if ( !$this->isLoggedIn ) {
365 .
' No user is logged in, files must belong to users' );
368 $dbw = $this->repo->getMasterDB();
372 $row = $dbw->selectRow(
375 [
'us_key' => $key ],
383 if ( $row->us_user != $this->userId ) {
385 .
"the file ($key) doesn't belong to this user." );
398 wfDebug( __METHOD__ .
" clearing row $key\n" );
403 $dbw = $this->repo->getMasterDB();
407 [
'us_key' => $key ],
414 $this->
files[$key]->remove();
416 unset( $this->
files[$key] );
417 unset( $this->fileMetadata[$key] );
429 if ( !$this->isLoggedIn ) {
431 .
' No user is logged in, files must belong to users' );
434 $dbr = $this->repo->getReplicaDB();
438 [
'us_user' => $this->userId ],
442 if ( !is_object(
$res ) ||
$res->numRows() == 0 ) {
449 foreach (
$res as $row ) {
450 array_push(
$keys, $row->us_key );
469 $n = strrpos(
$path,
'.' );
471 if ( $n !==
false ) {
472 $extension = $n ? substr(
$path, $n + 1 ) :
'';
476 $mimeType = $magic->guessMimeType(
$path );
478 if (
count( $extensions ) ) {
479 $extension = $extensions[0];
483 if ( is_null( $extension ) ) {
511 $dbr = $this->repo->getMasterDB();
513 $dbr = $this->repo->getReplicaDB();
516 $row =
$dbr->selectRow(
519 [
'us_key' => $key ],
523 if ( !is_object( $row ) ) {
528 $this->fileMetadata[$key] = (
array)$row;
529 $this->fileMetadata[$key][
'us_props'] =
$dbr->decodeBlob( $row->us_props );
542 $file =
new UploadStashFile( $this->repo, $this->fileMetadata[$key][
'us_path'], $key );
543 if ( $file->getSize() === 0 ) {
546 $this->
files[$key] = $file;
570 $this->fileKey = $key;
580 ( strpos(
$path, $repoTempPath ) !== 0 )
582 wfDebug(
"UploadStash: tried to construct an UploadStashFile "
583 .
"from a file that should already exist at '$path', but path is not valid\n" );
589 wfDebug(
"UploadStash: tried to construct an UploadStashFile from "
590 .
"a file that should already exist at '$path', but path is not found\n" );
595 parent::__construct(
false,
$repo,
$path,
false );
597 $this->
name = basename( $this->path );
623 $path = dirname( $this->path );
624 if ( $thumbName !==
false ) {
625 $path .=
"/$thumbName";
665 wfDebug( __METHOD__ .
" getting for $thumbName \n" );
677 if ( !$this->urlName ) {
691 if ( !isset( $this->url ) ) {
723 public function remove() {
724 if ( !$this->repo->fileExists( $this->path ) ) {
729 return $this->repo->freeTemp( $this->path );
733 return $this->repo->fileExists( $this->path );
removeFileNoAuth( $key)
Remove a file (see removeFile), but doesn't check ownership first.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
getUrlName()
The basename for the URL, which we want to not be related to the filename.
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
validateFilename( $filename)
Determine if a relative path is valid, i.e.
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
listFiles()
List all files in the stash.
A file object referring to either a standalone local file, or a file in a local repository with no da...
UploadStash is intended to accomplish a few things:
static getExtensionForPath( $path)
Find or guess extension – ensuring that our extension matches our MIME type.
getFile( $key, $noAuth=false)
Get a file and its metadata from the stash.
getMetadata( $key)
Getter for file metadata.
unserialize( $serialized)
stashFile( $path, $sourceType=null)
Stash a file in a temp directory and record that we did this in the database, along with other metada...
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Base class for file repositories.
getFileProps( $key)
Getter for fileProps.
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
getThumbPath( $thumbName=false)
Get the path for the thumbnail (actually any transformation of this file) The actual argument is the ...
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms,...
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition files
__construct(FileRepo $repo, $user=null)
Represents a temporary filestore, with metadata in the database.
getFullUrl()
Parent classes use this method, for no obvious reason, to return the path (relative to wiki root,...
MimeMagic helper wrapper.
when a variable name is used in a it is silently declared as a new masking the global
static singleton()
Get an instance of this class.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
fileExists( $file)
Checks existence of a a file.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
removeFile( $key)
Remove a particular file from the stash.
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters.
thumbName( $params, $flags=0)
Return the file/url base name of a thumbnail with the specified parameters.
getDescriptionUrl()
A method needed by the file transforming and scaling routines in File.php We do not necessarily care ...
initFile( $key)
Helper function: Initialize the UploadStashFile for a given file.
getSpecialUrl( $subPage)
Helper function – given a 'subpage', return the local URL, e.g.
fetchFileMetadata( $key, $readFromDB=DB_REPLICA)
Helper function: do the actual database query to fetch file metadata.
getFileKey()
Getter for file key (the unique id by which this file's location & metadata is stored in the db)
__construct( $repo, $path, $key)
A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create ...
exists()
Returns true if file exists in the repository.
getUrl()
Return the URL of the file, if for some reason we wanted to download it We tend not to do this for th...
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 as
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
resolveVirtualUrl( $url)
Get the backend storage path corresponding to a virtual URL.
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
clear()
Remove all files from the stash.
LocalRepo $repo
repository that this uses to store temp files public because we sometimes need to get a LocalFile wit...
it s the revision text itself In either if gzip is the revision text is gzipped $flags
A repository that stores files in the local filesystem and registers them in the wiki's own database.
the array() calling protocol came about after MediaWiki 1.4rc1.
getThumbUrl( $thumbName=false)
Get a URL to access the thumbnail This is required because the model of how files work requires that ...