Go to the documentation of this file.
90 if ( is_object( $this->
user ) ) {
91 $this->userId = $this->
user->getId();
92 $this->isLoggedIn = $this->
user->isLoggedIn();
108 public function getFile( $key, $noAuth =
false ) {
109 if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
113 if ( !$noAuth && !$this->isLoggedIn ) {
115 ' No user is logged in, files must belong to users' );
118 if ( !isset( $this->fileMetadata[$key] ) ) {
124 if ( !isset( $this->fileMetadata[$key] ) ) {
132 if ( strlen( $this->fileMetadata[$key][
'us_props'] ) ) {
133 $this->fileProps[$key] = unserialize( $this->fileMetadata[$key][
'us_props'] );
135 wfDebug( __METHOD__ .
" fetched props for $key from file\n" );
136 $path = $this->fileMetadata[$key][
'us_path'];
137 $this->fileProps[$key] = $this->repo->getFileProps(
$path );
141 if ( ! $this->files[$key]->exists() ) {
142 wfDebug( __METHOD__ .
" tried to get file at $key, but it doesn't exist\n" );
147 if ( $this->fileMetadata[$key][
'us_user'] != $this->userId ) {
152 return $this->files[$key];
163 return $this->fileMetadata[$key];
174 return $this->fileProps[$key];
188 if ( !is_file(
$path ) ) {
189 wfDebug( __METHOD__ .
" tried to stash file at '$path', but it doesn't exist\n" );
193 wfDebug( __METHOD__ .
" stashing file at '$path'\n" );
198 if ( !preg_match(
"/\\.\\Q$extension\\E$/",
$path ) ) {
199 $pathWithGoodExtension =
"$path.$extension";
201 $pathWithGoodExtension =
$path;
209 list( $usec, $sec ) = explode(
' ', microtime() );
210 $usec = substr( $usec, 2 );
213 $this->userId .
'.' .
218 if ( ! preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
222 wfDebug( __METHOD__ .
" key for '$path': $key\n" );
225 $storeStatus = $this->repo->storeTemp( basename( $pathWithGoodExtension ),
$path );
227 if ( ! $storeStatus->isOK() ) {
233 $error = $storeStatus->getErrorsArray();
235 if ( ! count(
$error ) ) {
236 $error = $storeStatus->getWarningsArray();
238 if ( ! count(
$error ) ) {
243 $errorMsg = array_shift(
$error );
246 $stashPath = $storeStatus->value;
249 if ( !$this->isLoggedIn ) {
254 wfDebug( __METHOD__ .
" inserting $stashPath under $key\n" );
255 $dbw = $this->repo->getMasterDb();
257 $this->fileMetadata[$key] =
array(
258 'us_id' => $dbw->nextSequenceValue(
'uploadstash_us_id_seq' ),
261 'us_orig_path' =>
$path,
262 'us_path' => $stashPath,
263 'us_props' => $dbw->encodeBlob( serialize(
$fileProps ) ),
271 'us_source_type' => $sourceType,
272 'us_timestamp' => $dbw->timestamp(),
273 'us_status' =>
'finished'
278 $this->fileMetadata[$key],
283 $this->fileMetadata[$key][
'us_id'] = $dbw->insertId();
285 # create the UploadStashFile object for this file.
298 public function clear() {
299 if ( !$this->isLoggedIn ) {
303 wfDebug( __METHOD__ .
' clearing all rows for user ' . $this->userId .
"\n" );
304 $dbw = $this->repo->getMasterDb();
307 array(
'us_user' => $this->userId ),
312 $this->files =
array();
313 $this->fileMetadata =
array();
326 if ( !$this->isLoggedIn ) {
330 $dbw = $this->repo->getMasterDb();
334 $row = $dbw->selectRow(
337 array(
'us_key' => $key ),
345 if ( $row->us_user != $this->userId ) {
359 wfDebug( __METHOD__ .
" clearing row $key\n" );
364 $dbw = $this->repo->getMasterDb();
368 array(
'us_key' => $key ),
374 $this->files[$key]->remove();
376 unset( $this->files[$key] );
377 unset( $this->fileMetadata[$key] );
389 if ( !$this->isLoggedIn ) {
393 $dbr = $this->repo->getSlaveDb();
397 array(
'us_user' => $this->userId ),
401 if ( !is_object(
$res ) ||
$res->numRows() == 0 ) {
408 foreach (
$res as $row ) {
409 array_push(
$keys, $row->us_key );
430 if (
$n !==
false ) {
431 $extension =
$n ? substr(
$path,
$n + 1 ) :
'';
434 $magic = MimeMagic::singleton();
435 $mimeType = $magic->guessMimeType(
$path );
436 $extensions = explode(
' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) );
442 if ( is_null( $extension ) ) {
447 if ( in_array( $extension, $wgFileBlacklist ) ) {
469 $dbr = $this->repo->getMasterDb();
471 $dbr = $this->repo->getSlaveDb();
474 $row =
$dbr->selectRow(
477 array(
'us_key' => $key ),
481 if ( !is_object( $row ) ) {
486 $this->fileMetadata[$key] = (
array)$row;
487 $this->fileMetadata[$key][
'us_props'] =
$dbr->decodeBlob( $row->us_props );
499 protected function initFile( $key ) {
501 if (
$file->getSize() === 0 ) {
504 $this->files[$key] =
$file;
525 $this->fileKey = $key;
535 ( strpos(
$path, $repoTempPath ) !== 0 ) ) {
536 wfDebug(
"UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not valid\n" );
542 wfDebug(
"UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not found\n" );
547 parent::__construct(
false,
$repo,
$path,
false );
549 $this->
name = basename( $this->path );
573 $path = dirname( $this->path );
574 if ( $thumbName !==
false ) {
575 $path .=
"/$thumbName";
611 public function getThumbUrl( $thumbName =
false ) {
612 wfDebug( __METHOD__ .
" getting for $thumbName \n" );
623 if ( ! $this->urlName ) {
635 public function getUrl() {
636 if ( !isset( $this->url ) ) {
665 public function remove() {
666 if ( !$this->repo->fileExists( $this->path ) ) {
671 return $this->repo->freeTemp( $this->path );
674 public function exists() {
675 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.
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
validateFilename( $filename)
Determine if a relative path is valid, i.e.
static getPropsFromPath( $path, $ext=true)
Get an associative array containing information about a file in the local filesystem.
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.
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.
it s the revision text itself In either if gzip is the revision text is gzipped $flags
Base class for file repositories.
static normalizeExtension( $ext)
Normalize a file extension to the common form, and ensure it's clean.
getFileProps( $key)
Getter for fileProps.
getThumbPath( $thumbName=false)
Get the path for the thumbnail (actually any transformation of this file) The actual argument is the ...
__construct(FileRepo $repo, $user=null)
Represents a temporary filestore, with metadata in the database.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses after processing after in associative array form externallinks including delete and has completed for all link tables 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 "<
getFullUrl()
Parent classes use this method, for no obvious reason, to return the path (relative to wiki root,...
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
when a variable name is used in a it is silently declared as a new masking the global
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.
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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
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.
if(PHP_SAPI !='cli') $file
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.
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
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.
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
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
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...
A repository that stores files in the local filesystem and registers them in the wiki's own database.
getThumbUrl( $thumbName=false)
Get a URL to access the thumbnail This is required because the model of how files work requires that ...
fetchFileMetadata( $key, $readFromDB=DB_SLAVE)
Helper function: do the actual database query to fetch file metadata.