82 foreach ( $required
as $name ) {
83 if ( isset( $params[$name] ) ) {
89 foreach ( $optional
as $name ) {
90 if ( isset( $params[$name] ) ) {
94 foreach ( $paths
as $name ) {
95 if ( isset( $this->params[$name] ) ) {
97 $this->params[
$name] = self::normalizeIfValidStoragePath( $this->params[$name] );
134 return isset( $this->params[
$name] ) ? $this->params[
$name] : null;
152 return [
'exists' => [],
'sha1' => [] ];
161 return [
'read' => [],
'write' => [] ];
185 if ( isset( $deps[
'read'][$path] ) || isset( $deps[
'write'][$path] ) ) {
190 if ( isset( $deps[
'write'][$path] ) ) {
206 if ( !$this->doOperation ) {
213 foreach ( array_unique( $pathsUsed )
as $path ) {
217 'newSha1' => $this->
fileSha1( $path, $oPredicates )
221 if ( $nPredicates[
'sha1'][$path] ===
false ) {
229 'op' => $this->
fileExists( $path, $oPredicates ) ?
'update' :
'create',
231 'newSha1' => $nPredicates[
'sha1'][
$path]
236 return array_merge( $nullEntries, $updateEntries, $deleteEntries );
248 if ( $this->state !== self::STATE_NEW ) {
249 return Status::newFatal(
'fileop-fail-state', self::STATE_NEW, $this->state );
251 $this->state = self::STATE_CHECKED;
274 if ( $this->state !== self::STATE_CHECKED ) {
275 return Status::newFatal(
'fileop-fail-state', self::STATE_CHECKED, $this->state );
276 } elseif ( $this->
failed ) {
279 $this->state = self::STATE_ATTEMPTED;
280 if ( $this->doOperation ) {
308 $this->async =
false;
319 return [ [], [], [] ];
362 if ( $this->sourceSha1 === null ) {
363 $this->sourceSha1 = $this->
fileSha1( $this->params[
'src'], $predicates );
365 $this->overwriteSameCase =
false;
366 $this->destExists = $this->
fileExists( $this->params[
'dst'], $predicates );
367 if ( $this->destExists ) {
368 if ( $this->
getParam(
'overwrite' ) ) {
370 } elseif ( $this->
getParam(
'overwriteSame' ) ) {
371 $dhash = $this->
fileSha1( $this->params[
'dst'], $predicates );
373 if ( !strlen( $this->sourceSha1 ) || !strlen( $dhash ) ) {
374 $status->fatal(
'backend-fail-hashes' );
375 } elseif ( $this->sourceSha1 !== $dhash ) {
377 $status->fatal(
'backend-fail-notsame', $this->params[
'dst'] );
379 $this->overwriteSameCase =
true;
384 $status->fatal(
'backend-fail-alreadyexists', $this->params[
'dst'] );
411 if ( isset( $predicates[
'exists'][
$source] ) ) {
412 return $predicates[
'exists'][
$source];
416 return $this->backend->fileExists(
$params );
428 if ( isset( $predicates[
'sha1'][
$source] ) ) {
429 return $predicates[
'sha1'][
$source];
430 } elseif ( isset( $predicates[
'exists'][$source] ) && !$predicates[
'exists'][$source] ) {
435 return $this->backend->getFileSha1Base36(
$params );
455 $params[
'failedAction'] = $action;
457 wfDebugLog(
'FileOperation', get_class( $this ) .
472 [
'content',
'dst' ],
473 [
'overwrite',
'overwriteSame',
'headers' ],
481 if ( strlen( $this->
getParam(
'content' ) ) > $this->backend->maxFileSizeInternal() ) {
482 $status->fatal(
'backend-fail-maxsize',
483 $this->params[
'dst'], $this->backend->maxFileSizeInternal() );
484 $status->fatal(
'backend-fail-create', $this->params[
'dst'] );
488 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'dst'] ) ) {
489 $status->fatal(
'backend-fail-usable', $this->params[
'dst'] );
490 $status->fatal(
'backend-fail-create', $this->params[
'dst'] );
499 $predicates[
'exists'][$this->params[
'dst']] =
true;
507 if ( !$this->overwriteSameCase ) {
509 return $this->backend->createInternal( $this->
setFlags( $this->params ) );
516 return Wikimedia\base_convert( sha1( $this->params[
'content'] ), 16, 36, 31 );
520 return [ $this->params[
'dst'] ];
532 [
'overwrite',
'overwriteSame',
'headers' ],
540 if ( !is_file( $this->params[
'src'] ) ) {
541 $status->fatal(
'backend-fail-notexists', $this->params[
'src'] );
545 } elseif ( filesize( $this->params[
'src'] ) > $this->backend->maxFileSizeInternal() ) {
546 $status->fatal(
'backend-fail-maxsize',
547 $this->params[
'dst'], $this->backend->maxFileSizeInternal() );
548 $status->fatal(
'backend-fail-store', $this->params[
'src'], $this->params[
'dst'] );
552 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'dst'] ) ) {
553 $status->fatal(
'backend-fail-usable', $this->params[
'dst'] );
554 $status->fatal(
'backend-fail-store', $this->params[
'src'], $this->params[
'dst'] );
563 $predicates[
'exists'][$this->params[
'dst']] =
true;
571 if ( !$this->overwriteSameCase ) {
573 return $this->backend->storeInternal( $this->
setFlags( $this->params ) );
580 MediaWiki\suppressWarnings();
581 $hash = sha1_file( $this->params[
'src'] );
582 MediaWiki\restoreWarnings();
583 if ( $hash !==
false ) {
584 $hash = Wikimedia\base_convert( $hash, 16, 36, 31 );
591 return [ $this->params[
'dst'] ];
603 [
'overwrite',
'overwriteSame',
'ignoreMissingSource',
'headers' ],
611 if ( !$this->
fileExists( $this->params[
'src'], $predicates ) ) {
612 if ( $this->
getParam(
'ignoreMissingSource' ) ) {
613 $this->doOperation =
false;
615 $predicates[
'exists'][$this->params[
'src']] =
false;
616 $predicates[
'sha1'][$this->params[
'src']] =
false;
620 $status->fatal(
'backend-fail-notexists', $this->params[
'src'] );
625 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'dst'] ) ) {
626 $status->fatal(
'backend-fail-usable', $this->params[
'dst'] );
627 $status->fatal(
'backend-fail-copy', $this->params[
'src'], $this->params[
'dst'] );
636 $predicates[
'exists'][$this->params[
'dst']] =
true;
644 if ( $this->overwriteSameCase ) {
646 } elseif ( $this->params[
'src'] === $this->params[
'dst'] ) {
648 $headers = $this->
getParam(
'headers' ) ?: [];
650 'src' => $this->params[
'dst'],
'headers' => $headers
654 $status = $this->backend->copyInternal( $this->
setFlags( $this->params ) );
661 return [ $this->params[
'src'] ];
665 return [ $this->params[
'dst'] ];
677 [
'overwrite',
'overwriteSame',
'ignoreMissingSource',
'headers' ],
685 if ( !$this->
fileExists( $this->params[
'src'], $predicates ) ) {
686 if ( $this->
getParam(
'ignoreMissingSource' ) ) {
687 $this->doOperation =
false;
689 $predicates[
'exists'][$this->params[
'src']] =
false;
690 $predicates[
'sha1'][$this->params[
'src']] =
false;
694 $status->fatal(
'backend-fail-notexists', $this->params[
'src'] );
699 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'dst'] ) ) {
700 $status->fatal(
'backend-fail-usable', $this->params[
'dst'] );
701 $status->fatal(
'backend-fail-move', $this->params[
'src'], $this->params[
'dst'] );
710 $predicates[
'exists'][$this->params[
'src']] =
false;
711 $predicates[
'sha1'][$this->params[
'src']] =
false;
712 $predicates[
'exists'][$this->params[
'dst']] =
true;
720 if ( $this->overwriteSameCase ) {
721 if ( $this->params[
'src'] === $this->params[
'dst'] ) {
727 [
'src' => $this->params[
'src'] ]
730 } elseif ( $this->params[
'src'] === $this->params[
'dst'] ) {
732 $headers = $this->
getParam(
'headers' ) ?: [];
734 [
'src' => $this->params[
'dst'],
'headers' => $headers ]
738 $status = $this->backend->moveInternal( $this->
setFlags( $this->params ) );
745 return [ $this->params[
'src'] ];
749 return [ $this->params[
'src'], $this->params[
'dst'] ];
759 return [ [
'src' ], [
'ignoreMissingSource' ], [
'src' ] ];
765 if ( !$this->
fileExists( $this->params[
'src'], $predicates ) ) {
766 if ( $this->
getParam(
'ignoreMissingSource' ) ) {
767 $this->doOperation =
false;
769 $predicates[
'exists'][$this->params[
'src']] =
false;
770 $predicates[
'sha1'][$this->params[
'src']] =
false;
774 $status->fatal(
'backend-fail-notexists', $this->params[
'src'] );
779 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'src'] ) ) {
780 $status->fatal(
'backend-fail-usable', $this->params[
'src'] );
781 $status->fatal(
'backend-fail-delete', $this->params[
'src'] );
786 $predicates[
'exists'][$this->params[
'src']] =
false;
787 $predicates[
'sha1'][$this->params[
'src']] =
false;
794 return $this->backend->deleteInternal( $this->
setFlags( $this->params ) );
798 return [ $this->params[
'src'] ];
808 return [ [
'src' ], [
'headers' ], [
'src' ] ];
814 if ( !$this->
fileExists( $this->params[
'src'], $predicates ) ) {
815 $status->fatal(
'backend-fail-notexists', $this->params[
'src'] );
819 } elseif ( !$this->backend->isPathUsableInternal( $this->params[
'src'] ) ) {
820 $status->fatal(
'backend-fail-usable', $this->params[
'src'] );
821 $status->fatal(
'backend-fail-describe', $this->params[
'src'] );
826 $predicates[
'exists'][$this->params[
'src']] =
827 $this->
fileExists( $this->params[
'src'], $predicates );
828 $predicates[
'sha1'][$this->params[
'src']] =
829 $this->
fileSha1( $this->params[
'src'], $predicates );
836 return $this->backend->describeInternal( $this->
setFlags( $this->params ) );
840 return [ $this->params[
'src'] ];
setBatchId($batchId)
Set the batch UUID this operation belongs to.
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.
logFailure($action)
Log a file operation failure and preserve any temp files.
getJournalEntries(array $oPredicates, array $nPredicates)
Get the file journal entries for this file operation.
Delete a file at the given storage path from the backend.
Store a file into the backend from a file on the file system.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
FileBackend helper class for representing operations.
applyDependencies(array $deps)
Update a dependency tracking array to account for this operation.
fileSha1($source, array $predicates)
Get the SHA-1 of a file in storage when this operation is attempted.
getParam($name)
Get the value of the parameter with the given name.
Copy a file from one storage path to another in the backend.
doPrecheck(array &$predicates)
Move a file from one storage path to another in the backend.
setFlags(array $params)
Adjust params to FileBackendStore internal file calls.
bool $doOperation
Operation is not a no-op.
static newFatal($message)
Factory function for fatal errors.
doPrecheck(array &$predicates)
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. '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 '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:Associative array mapping language codes to prefixed links of the form"language:title".&$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':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) $result
attempt()
Attempt the operation.
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 true
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
File backend exception for checked exceptions (e.g.
storagePathsRead()
Get a list of storage paths read from for this operation.
dependsOn(array $deps)
Check if this operation changes files listed in $paths.
static newPredicates()
Get a new empty predicates array for precheck()
precheckDestExistence(array $predicates)
Check for errors with regards to the destination file already existing.
static isStoragePath($path)
Check if a given path is a "mwstore://" path.
attemptAsync()
Attempt the operation in the background.
getSourceSha1Base36()
precheckDestExistence() helper function to get the source file SHA-1.
doPrecheck(array &$predicates)
Change metadata for a file at the given storage path in the backend.
allowedParams()
Get the file operation parameters.
getBackend()
Get the backend this operation is for.
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 normalizeIfValidStoragePath($path)
Normalize a string if it is a valid storage path.
Base class for all backends using particular storage medium.
precheck(array &$predicates)
Check preconditions of the operation without writing anything.
FileBackendStore $backend
Placeholder operation that has no params and does nothing.
doPrecheck(array &$predicates)
static normalizeStoragePath($storagePath)
Normalize a storage path by cleaning up directory separators.
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
static newDependencies()
Get a new empty dependency tracking array for paths read/written to.
storagePathsChanged()
Get a list of storage paths written to for this operation.
doPrecheck(array &$predicates)
fileExists($source, array $predicates)
Check if a file will exist in storage when this operation is attempted.
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
doPrecheck(array &$predicates)
Create a file in the backend with the given content.
doPrecheck(array &$predicates)
static newGood($value=null)
Factory function for good results.
failed()
Check if this operation failed precheck() or attempt()
__construct(FileBackendStore $backend, array $params)
Build a new batch file operation transaction.
Allows to change the fields on the form that will be generated $name