99 if ( is_object( $this->user ) ) {
100 $this->userId = $this->user->getId();
101 $this->isLoggedIn = $this->user->isLoggedIn();
118 public function getFile( $key, $noAuth =
false ) {
119 if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
121 wfMessage(
'uploadstash-bad-path-bad-format', $key )
125 if ( !$noAuth && !$this->isLoggedIn ) {
131 if ( !isset( $this->fileMetadata[$key] ) ) {
138 if ( !isset( $this->fileMetadata[$key] ) ) {
140 wfMessage(
'uploadstash-file-not-found', $key )
148 if ( strlen( $this->fileMetadata[$key][
'us_props'] ) ) {
149 $this->fileProps[$key] =
unserialize( $this->fileMetadata[$key][
'us_props'] );
151 wfDebug( __METHOD__ .
" fetched props for $key from file\n" );
152 $path = $this->fileMetadata[$key][
'us_path'];
153 $this->fileProps[$key] = $this->repo->getFileProps( $path );
157 if ( !$this->
files[$key]->exists() ) {
158 wfDebug( __METHOD__ .
" tried to get file at $key, but it doesn't exist\n" );
166 if ( $this->fileMetadata[$key][
'us_user'] != $this->userId ) {
168 wfMessage(
'uploadstash-wrong-owner', $key )
173 return $this->
files[$key];
185 return $this->fileMetadata[$key];
197 return $this->fileProps[$key];
212 public function stashFile( $path, $sourceType =
null ) {
213 if ( !is_file( $path ) ) {
214 wfDebug( __METHOD__ .
" tried to stash file at '$path', but it doesn't exist\n" );
221 $fileProps = $mwProps->getPropsFromPath( $path,
true );
222 wfDebug( __METHOD__ .
" stashing file at '$path'\n" );
227 if ( !preg_match(
"/\\.\\Q$extension\\E$/", $path ) ) {
228 $pathWithGoodExtension =
"$path.$extension";
230 $pathWithGoodExtension =
$path;
238 list( $usec, $sec ) = explode(
' ', microtime() );
239 $usec = substr( $usec, 2 );
240 $key = Wikimedia\base_convert( $sec . $usec, 10, 36 ) .
'.' .
241 Wikimedia\base_convert( mt_rand(), 10, 36 ) .
'.' .
242 $this->userId .
'.' .
247 if ( !preg_match( self::KEY_FORMAT_REGEX, $key ) ) {
249 wfMessage(
'uploadstash-bad-path-bad-format', $key )
253 wfDebug( __METHOD__ .
" key for '$path': $key\n" );
256 $storeStatus = $this->repo->storeTemp( basename( $pathWithGoodExtension ), $path );
258 if ( !$storeStatus->isOK() ) {
267 $error = $storeStatus->getErrorsArray();
268 $error = reset( $error );
269 if ( !count( $error ) ) {
270 $error = $storeStatus->getWarningsArray();
271 $error = reset( $error );
272 if ( !count( $error ) ) {
273 $error = [
'unknown',
'no error recorded' ];
278 $errorMsg = array_shift( $error );
281 $stashPath = $storeStatus->value;
284 if ( !$this->isLoggedIn ) {
291 wfDebug( __METHOD__ .
" inserting $stashPath under $key\n" );
292 $dbw = $this->repo->getMasterDB();
295 if ( strlen( $serializedFileProps ) > self::MAX_US_PROPS_SIZE ) {
303 $this->fileMetadata[$key] = [
306 'us_orig_path' =>
$path,
307 'us_path' => $stashPath,
308 'us_props' => $dbw->encodeBlob( $serializedFileProps ),
316 'us_source_type' => $sourceType,
317 'us_timestamp' => $dbw->timestamp(),
318 'us_status' =>
'finished'
323 $this->fileMetadata[$key],
329 $this->fileMetadata[$key][
'us_id'] = $dbw->insertId();
331 # create the UploadStashFile object for this file.
345 if ( !$this->isLoggedIn ) {
351 wfDebug( __METHOD__ .
' clearing all rows for user ' . $this->userId .
"\n" );
352 $dbw = $this->repo->getMasterDB();
355 [
'us_user' => $this->userId ],
361 $this->fileMetadata = [];
375 if ( !$this->isLoggedIn ) {
381 $dbw = $this->repo->getMasterDB();
385 $row = $dbw->selectRow(
388 [
'us_key' => $key ],
394 wfMessage(
'uploadstash-no-such-key', $key )
398 if ( $row->us_user != $this->userId ) {
400 wfMessage(
'uploadstash-wrong-owner', $key )
414 wfDebug( __METHOD__ .
" clearing row $key\n" );
419 $dbw = $this->repo->getMasterDB();
423 [
'us_key' => $key ],
430 $this->
files[$key]->remove();
432 unset( $this->
files[$key] );
433 unset( $this->fileMetadata[$key] );
445 if ( !$this->isLoggedIn ) {
451 $dbr = $this->repo->getReplicaDB();
455 [
'us_user' => $this->userId ],
459 if ( !is_object(
$res ) ||
$res->numRows() == 0 ) {
466 foreach (
$res as $row ) {
467 array_push(
$keys, $row->us_key );
486 $n = strrpos( $path,
'.' );
488 if ( $n !==
false ) {
489 $extension = $n ? substr( $path, $n + 1 ) :
'';
492 $magic = MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer();
493 $mimeType = $magic->guessMimeType( $path );
494 $extensions = explode(
' ', $magic->getExtensionsForType( $mimeType ) );
495 if ( count( $extensions ) ) {
496 $extension = $extensions[0];
500 if ( is_null( $extension ) ) {
530 $dbr = $this->repo->getMasterDB();
532 $dbr = $this->repo->getReplicaDB();
535 $row =
$dbr->selectRow(
538 'us_user',
'us_key',
'us_orig_path',
'us_path',
'us_props',
539 'us_size',
'us_sha1',
'us_mime',
'us_media_type',
540 'us_image_width',
'us_image_height',
'us_image_bits',
541 'us_source_type',
'us_timestamp',
'us_status',
543 [
'us_key' => $key ],
547 if ( !is_object( $row ) ) {
552 $this->fileMetadata[$key] = (
array)$row;
553 $this->fileMetadata[$key][
'us_props'] =
$dbr->decodeBlob( $row->us_props );
566 $file =
new UploadStashFile( $this->repo, $this->fileMetadata[$key][
'us_path'], $key );
567 if ( $file->getSize() === 0 ) {
572 $this->
files[$key] = $file;
599 $this->fileKey = $key;
609 ( strpos( $path, $repoTempPath ) !== 0 )
611 wfDebug(
"UploadStash: tried to construct an UploadStashFile "
612 .
"from a file that should already exist at '$path', but path is not valid\n" );
614 wfMessage(
'uploadstash-bad-path-invalid' )
620 wfDebug(
"UploadStash: tried to construct an UploadStashFile from "
621 .
"a file that should already exist at '$path', but path is not found\n" );
623 wfMessage(
'uploadstash-file-not-found-not-exists' )
628 parent::__construct(
false,
$repo, $path,
false );
630 $this->
name = basename( $this->path );
656 $path = dirname( $this->path );
657 if ( $thumbName !==
false ) {
658 $path .=
"/$thumbName";
684 return SpecialPage::getTitleFor(
'UploadStash', $subPage )->getLocalURL();
698 wfDebug( __METHOD__ .
" getting for $thumbName \n" );
710 if ( !$this->urlName ) {
724 if ( !isset( $this->url ) ) {
756 public function remove() {
757 if ( !$this->repo->fileExists( $this->path ) ) {
762 return $this->repo->freeTemp( $this->path );
766 return $this->repo->fileExists( $this->path );
786 $msg = preg_replace(
'!</?(var|kbd|samp|code)>!',
'"', $msg );
787 $msg = Sanitizer::stripAllTags( $msg );
788 parent::__construct( $msg,
$code, $previous );
792 return Message::newFromSpecifier( $this->messageSpec );
unserialize( $serialized)
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
$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.
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.
MimeMagic helper wrapper.
A file object referring to either a standalone local file, or a file in a local repository with no da...
string array MessageSpecifier $messageSpec
getMessageObject()
Return a Message object for this exception.
__construct( $messageSpec, $code=0, $previous=null)
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.
__construct(FileRepo $repo, $user=null)
Represents a temporary filestore, with metadata in the database.
fetchFileMetadata( $key, $readFromDB=DB_REPLICA)
Helper function: do the actual database query to fetch file metadata.
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
the array() calling protocol came about after MediaWiki 1.4rc1.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
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 "<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
> value, names are case insensitive). Two headers get special handling:If-Modified-Since(value must be a valid HTTP date) and Range(must be of the form "bytes=(\d*-\d*)") will be honored when streaming the file. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item. Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page. Return false to stop further processing of the tag $reader:XMLReader object & $pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision. Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag. Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload. Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports. & $fullInterwikiPrefix:Interwiki prefix, may contain colons. & $pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable. Can be used to lazy-load the import sources list. & $importSources:The value of $wgImportSources. Modify as necessary. See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page. $context:IContextSource object & $pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect. & $title:Title object for the current page & $request:WebRequest & $ignoreRedirect:boolean to skip redirect check & $target:Title/string of redirect target & $article:Article object 'InternalParseBeforeLinks':during Parser 's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InternalParseBeforeSanitize':during Parser 's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings. Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments. & $parser:Parser object & $text:string containing partially parsed text & $stripState:Parser 's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not. Return true without providing an interwiki to continue interwiki search. $prefix:interwiki prefix we are looking for. & $iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user 's email has been invalidated successfully. $user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification. Callee may modify $url and $query, URL will be constructed as $url . $query & $url:URL to index.php & $query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) & $article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() & $ip:IP being check & $result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from & $allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn 't match your organization. $addr:The e-mail address entered by the user & $result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user & $result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we 're looking for a messages file for & $file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED! Use $magicWords in a file listed in $wgExtensionMessagesFiles instead. Use this to define synonyms of magic words depending of the language & $magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces. Do not use this hook to add namespaces. Use CanonicalNamespaces for that. & $namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED! Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead. Use to define aliases of special pages names depending of the language & $specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names. & $names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page 's language links. This is called in various places to allow extensions to define the effective language links for a page. $title:The page 's Title. & $links:Array with elements of the form "language:title" in the order that they will be output. & $linkFlags:Associative array mapping prefixed links to arrays of flags. Currently unused, but planned to provide support for marking individual language links in the UI, e.g. for featured articles. 'LanguageSelector':Hook to change the language selector available on a page. $out:The output page. $cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED! Use HtmlPageLinkRendererBegin instead. Used when generating internal and interwiki links in Linker::link(), before processing starts. Return false to skip default processing and return $ret. See documentation for Linker::link() for details on the expected meanings of parameters. $skin:the Skin object $target:the Title that the link is pointing to & $html:the contents that the< a > tag should have(raw HTML) name
Interface for MediaWiki-localized exceptions.