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];
205 public function stashFile( $path, $sourceType =
null ) {
206 if ( !is_file(
$path ) ) {
207 wfDebug( __METHOD__ .
" tried to stash file at '$path', but it doesn't exist\n" );
211 wfDebug( __METHOD__ .
" stashing file at '$path'\n" );
216 if ( !preg_match(
"/\\.\\Q$extension\\E$/",
$path ) ) {
217 $pathWithGoodExtension =
"$path.$extension";
219 $pathWithGoodExtension =
$path;
227 list( $usec, $sec ) = explode(
' ', microtime() );
228 $usec = substr( $usec, 2 );
229 $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) .
'.' .
230 Wikimedia\base_convert( mt_rand(), 10, 36 ) .
'.' .
231 $this->userId .
'.' .
236 if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
240 wfDebug( __METHOD__ .
" key for '$path': $key\n" );
243 $storeStatus = $this->repo->storeTemp( basename( $pathWithGoodExtension ),
$path );
245 if ( !$storeStatus->isOK() ) {
254 $error = $storeStatus->getErrorsArray();
255 $error = reset( $error );
256 if ( !count( $error ) ) {
257 $error = $storeStatus->getWarningsArray();
258 $error = reset( $error );
259 if ( !count( $error ) ) {
260 $error = [
'unknown',
'no error recorded' ];
265 $errorMsg = array_shift( $error );
269 $stashPath = $storeStatus->value;
272 if ( !$this->isLoggedIn ) {
274 .
' No user is logged in, files must belong to users' );
278 wfDebug( __METHOD__ .
" inserting $stashPath under $key\n" );
279 $dbw = $this->repo->getMasterDB();
282 if ( strlen( $serializedFileProps ) > self::MAX_US_PROPS_SIZE ) {
290 $this->fileMetadata[$key] = [
291 'us_id' => $dbw->nextSequenceValue(
'uploadstash_us_id_seq' ),
294 'us_orig_path' =>
$path,
295 'us_path' => $stashPath,
296 'us_props' => $dbw->encodeBlob( $serializedFileProps ),
304 'us_source_type' => $sourceType,
305 'us_timestamp' => $dbw->timestamp(),
306 'us_status' =>
'finished'
311 $this->fileMetadata[$key],
317 $this->fileMetadata[$key][
'us_id'] = $dbw->insertId();
319 # create the UploadStashFile object for this file.
333 if ( !$this->isLoggedIn ) {
335 .
' No user is logged in, files must belong to users' );
338 wfDebug( __METHOD__ .
' clearing all rows for user ' . $this->userId .
"\n" );
339 $dbw = $this->repo->getMasterDB();
342 [
'us_user' => $this->userId ],
348 $this->fileMetadata = [];
362 if ( !$this->isLoggedIn ) {
364 .
' No user is logged in, files must belong to users' );
367 $dbw = $this->repo->getMasterDB();
371 $row = $dbw->selectRow(
374 [
'us_key' => $key ],
382 if ( $row->us_user != $this->userId ) {
384 .
"the file ($key) doesn't belong to this user." );
397 wfDebug( __METHOD__ .
" clearing row $key\n" );
402 $dbw = $this->repo->getMasterDB();
406 [
'us_key' => $key ],
413 $this->
files[$key]->remove();
415 unset( $this->
files[$key] );
416 unset( $this->fileMetadata[$key] );
428 if ( !$this->isLoggedIn ) {
430 .
' No user is logged in, files must belong to users' );
433 $dbr = $this->repo->getSlaveDB();
437 [
'us_user' => $this->userId ],
441 if ( !is_object(
$res ) ||
$res->numRows() == 0 ) {
448 foreach (
$res as $row ) {
449 array_push(
$keys, $row->us_key );
468 $n = strrpos(
$path,
'.' );
470 if ( $n !==
false ) {
471 $extension = $n ? substr(
$path, $n + 1 ) :
'';
474 $magic = MimeMagic::singleton();
475 $mimeType = $magic->guessMimeType(
$path );
476 $extensions = explode(
' ', MimeMagic::singleton()->getExtensionsForType( $mimeType ) );
482 if ( is_null( $extension ) ) {
510 $dbr = $this->repo->getMasterDB();
512 $dbr = $this->repo->getSlaveDB();
515 $row =
$dbr->selectRow(
518 [
'us_key' => $key ],
522 if ( !is_object( $row ) ) {
527 $this->fileMetadata[$key] = (
array)$row;
528 $this->fileMetadata[$key][
'us_props'] =
$dbr->decodeBlob( $row->us_props );
541 $file =
new UploadStashFile( $this->repo, $this->fileMetadata[$key][
'us_path'], $key );
542 if ( $file->getSize() === 0 ) {
545 $this->
files[$key] = $file;
569 $this->fileKey = $key;
579 ( strpos(
$path, $repoTempPath ) !== 0 )
581 wfDebug(
"UploadStash: tried to construct an UploadStashFile "
582 .
"from a file that should already exist at '$path', but path is not valid\n" );
588 wfDebug(
"UploadStash: tried to construct an UploadStashFile from "
589 .
"a file that should already exist at '$path', but path is not found\n" );
594 parent::__construct(
false,
$repo,
$path,
false );
596 $this->
name = basename( $this->path );
622 $path = dirname( $this->path );
623 if ( $thumbName !==
false ) {
624 $path .=
"/$thumbName";
664 wfDebug( __METHOD__ .
" getting for $thumbName \n" );
676 if ( !$this->urlName ) {
690 if ( !isset( $this->url ) ) {
722 public function remove() {
723 if ( !$this->repo->fileExists( $this->path ) ) {
728 return $this->repo->freeTemp( $this->path );
732 return $this->repo->fileExists( $this->path );
unserialize( $serialized)
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
static getPropsFromPath( $path, $ext=true)
Get an associative array containing information about a file in the local filesystem.
Base class for file repositories.
resolveVirtualUrl( $url)
Get the backend storage path corresponding to a virtual URL.
fileExists( $file)
Checks existence of a a file.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
validateFilename( $filename)
Determine if a relative path is valid, i.e.
FileRepo LocalRepo ForeignAPIRepo bool $repo
Some member variables can be lazy-initialised using __get().
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms,...
generateThumbName( $name, $params)
Generate a thumbnail file name from a name and specified parameters.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
A file object referring to either a standalone local file, or a file in a local repository with no da...
exists()
Returns true if file exists in the repository.
__construct( $repo, $path, $key)
A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create ...
getThumbPath( $thumbName=false)
Get the path for the thumbnail (actually any transformation of this file) The actual argument is the ...
getDescriptionUrl()
A method needed by the file transforming and scaling routines in File.php We do not necessarily care ...
getSpecialUrl( $subPage)
Helper function – given a 'subpage', return the local URL, e.g.
getUrl()
Return the URL of the file, if for some reason we wanted to download it We tend not to do this for th...
getThumbUrl( $thumbName=false)
Get a URL to access the thumbnail This is required because the model of how files work requires that ...
getFullUrl()
Parent classes use this method, for no obvious reason, to return the path (relative to wiki root,...
getUrlName()
The basename for the URL, which we want to not be related to the filename.
getFileKey()
Getter for file key (the unique id by which this file's location & metadata is stored in the db)
thumbName( $params, $flags=0)
Return the file/url base name of a thumbnail with the specified parameters.
UploadStash is intended to accomplish a few things:
static getExtensionForPath( $path)
Find or guess extension – ensuring that our extension matches our MIME type.
removeFile( $key)
Remove a particular file from the stash.
fetchFileMetadata( $key, $readFromDB=DB_SLAVE)
Helper function: do the actual database query to fetch file metadata.
__construct(FileRepo $repo, $user=null)
Represents a temporary filestore, with metadata in the database.
getFileProps( $key)
Getter for fileProps.
stashFile( $path, $sourceType=null)
Stash a file in a temp directory and record that we did this in the database, along with other metada...
clear()
Remove all files from the stash.
listFiles()
List all files in the stash.
getMetadata( $key)
Getter for file metadata.
removeFileNoAuth( $key)
Remove a file (see removeFile), but doesn't check ownership first.
initFile( $key)
Helper function: Initialize the UploadStashFile for a given file.
getFile( $key, $noAuth=false)
Get a file and its metadata from the stash.
LocalRepo $repo
repository that this uses to store temp files public because we sometimes need to get a LocalFile wit...
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
when a variable name is used in a it is silently declared as a new local masking the global
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
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
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
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
Wikitext formatted, in the key only.
the array() calling protocol came about after MediaWiki 1.4rc1.
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 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 "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
it s the revision text itself In either if gzip is the revision text is gzipped $flags
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