Go to the documentation of this file.
31 use Psr\Log\LoggerAwareInterface;
32 use Psr\Log\LoggerInterface;
33 use Wikimedia\ScopedCallback;
164 $this->
name = $config[
'name'];
165 $this->domainId = isset( $config[
'domainId'] )
166 ? $config[
'domainId']
168 if ( !preg_match(
'!^[a-zA-Z0-9-_]{1,255}$!', $this->
name ) ) {
169 throw new InvalidArgumentException(
"Backend name '{$this->name}' is invalid." );
170 } elseif ( !is_string( $this->domainId ) ) {
171 throw new InvalidArgumentException(
172 "Backend domain ID not provided for '{$this->name}'." );
174 $this->lockManager = isset( $config[
'lockManager'] )
175 ? $config[
'lockManager']
177 $this->fileJournal = isset( $config[
'fileJournal'] )
178 ? $config[
'fileJournal']
180 $this->readOnly = isset( $config[
'readOnly'] )
181 ? (
string)$config[
'readOnly']
183 $this->parallelize = isset( $config[
'parallelize'] )
184 ? (
string)$config[
'parallelize']
186 $this->concurrency = isset( $config[
'concurrency'] )
187 ? (int)$config[
'concurrency']
189 $this->obResetFunc = isset( $config[
'obResetFunc'] )
190 ? $config[
'obResetFunc']
191 : [ $this,
'resetOutputBuffer' ];
192 $this->streamMimeFunc = isset( $config[
'streamMimeFunc'] )
193 ? $config[
'streamMimeFunc']
195 $this->statusWrapper = isset( $config[
'statusWrapper'] ) ? $config[
'statusWrapper'] :
null;
197 $this->profiler = isset( $config[
'profiler'] ) ? $config[
'profiler'] :
null;
198 $this->logger = isset( $config[
'logger'] ) ? $config[
'logger'] : new \Psr\Log\NullLogger();
199 $this->statusWrapper = isset( $config[
'statusWrapper'] ) ? $config[
'statusWrapper'] :
null;
200 $this->tmpDirectory = isset( $config[
'tmpDirectory'] ) ? $config[
'tmpDirectory'] :
null;
243 return ( $this->readOnly !=
'' );
252 return ( $this->readOnly !=
'' ) ? $this->readOnly :
false;
273 return ( $this->
getFeatures() & $bitfield ) === $bitfield;
425 if ( empty( $opts[
'bypassReadOnly'] ) && $this->
isReadOnly() ) {
426 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
428 if ( !
count( $ops ) ) {
433 if ( empty( $opts[
'force'] ) ) {
434 unset( $opts[
'nonLocking'] );
476 return $this->
doOperation( [
'op' =>
'create' ] + $params, $opts );
490 return $this->
doOperation( [
'op' =>
'store' ] + $params, $opts );
504 return $this->
doOperation( [
'op' =>
'copy' ] + $params, $opts );
518 return $this->
doOperation( [
'op' =>
'move' ] + $params, $opts );
532 return $this->
doOperation( [
'op' =>
'delete' ] + $params, $opts );
547 return $this->
doOperation( [
'op' =>
'describe' ] + $params, $opts );
663 if ( empty( $opts[
'bypassReadOnly'] ) && $this->
isReadOnly() ) {
664 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
666 if ( !
count( $ops ) ) {
671 foreach ( $ops
as &$op ) {
672 $op[
'overwrite'] =
true;
820 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
851 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
884 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
910 return $this->
newStatus(
'backend-fail-readonly', $this->
name, $this->readOnly );
914 return $this->
doClean( $params );
931 if ( PHP_SAPI !=
'cli' ) {
932 $old = ignore_user_abort(
true );
933 return new ScopedCallback(
function ()
use ( $old ) {
934 ignore_user_abort( $old );
973 [
'srcs' => [ $params[
'src'] ] ] +
$params );
975 return $contents[
$params[
'src']];
1101 [
'srcs' => [ $params[
'src'] ] ] +
$params );
1103 return $fsFiles[
$params[
'src']];
1134 [
'srcs' => [ $params[
'src'] ] ] +
$params );
1136 return $tmpFiles[
$params[
'src']];
1259 return $this->
getFileList( [
'topOnly' =>
true ] + $params );
1310 $paths = array_map(
'FileBackend::normalizeStoragePath', $paths );
1312 return $this->
wrapStatus( $this->lockManager->lock( $paths,
$type, $timeout ) );
1323 $paths = array_map(
'FileBackend::normalizeStoragePath', $paths );
1325 return $this->
wrapStatus( $this->lockManager->unlock( $paths,
$type ) );
1347 if (
$type ===
'mixed' ) {
1348 foreach ( $paths
as &$typePaths ) {
1349 $typePaths = array_map(
'FileBackend::normalizeStoragePath', $typePaths );
1352 $paths = array_map(
'FileBackend::normalizeStoragePath', $paths );
1384 return "mwstore://{$this->name}";
1417 foreach ( $ops
as &$op ) {
1418 $src = isset( $op[
'src'] ) ? $op[
'src'] :
null;
1419 if ( $src instanceof
FSFile ) {
1420 $op[
'srcRef'] = $src;
1421 $op[
'src'] = $src->getPath();
1437 return ( strpos(
$path,
'mwstore://' ) === 0 );
1449 if ( self::isStoragePath( $storagePath ) ) {
1451 $parts = explode(
'/', substr( $storagePath, 10 ), 3 );
1452 if (
count( $parts ) >= 2 && $parts[0] !=
'' && $parts[1] !=
'' ) {
1453 if (
count( $parts ) == 3 ) {
1456 return [ $parts[0], $parts[1],
'' ];
1461 return [
null,
null, null ];
1473 if ( $relPath !==
null ) {
1475 if ( $relPath !==
null ) {
1476 return ( $relPath !=
'' )
1477 ?
"mwstore://{$backend}/{$container}/{$relPath}"
1478 :
"mwstore://{$backend}/{$container}";
1494 $storagePath = dirname( $storagePath );
1497 return ( $rel ===
null ) ? null : $storagePath;
1508 $i = strrpos(
$path,
'.' );
1509 $ext = $i ? substr(
$path, $i + 1 ) :
'';
1511 if ( $case ===
'lowercase' ) {
1513 } elseif ( $case ===
'uppercase' ) {
1528 return ( self::normalizeContainerPath(
$path ) !==
null );
1544 if ( !in_array(
$type, [
'inline',
'attachment' ] ) ) {
1545 throw new InvalidArgumentException(
"Invalid Content-Disposition type '$type'." );
1549 if ( strlen( $filename ) ) {
1550 $parts[] =
"filename*=UTF-8''" . rawurlencode( basename( $filename ) );
1553 return implode(
';', $parts );
1570 $path = preg_replace(
'![/]{2,}!',
'/',
$path );
1574 if ( strpos(
$path,
'.' ) !==
false ) {
1578 strpos(
$path,
'./' ) === 0 ||
1579 strpos(
$path,
'../' ) === 0 ||
1580 strpos(
$path,
'/./' ) !==
false ||
1581 strpos(
$path,
'/../' ) !==
false
1599 $args = func_get_args();
1601 $sv = call_user_func_array( [
'StatusValue',
'newFatal' ],
$args );
1614 return $this->statusWrapper ? call_user_func( $this->statusWrapper, $sv ) : $sv;
1622 if ( $this->profiler ) {
1623 call_user_func( [ $this->profiler,
'profileIn' ],
$section );
1624 return new ScopedCallback( [ $this->profiler,
'profileOut' ], [
$section ] );
1631 while ( ob_get_status() ) {
1632 if ( !ob_end_clean() ) {
streamFile(array $params)
Stream the file at a storage path in the backend.
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
Class for handling resource locking.
doOperations(array $ops, array $opts=[])
This is the main entry point into the backend for write operations.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static normalizeContainerPath( $path)
Validate and normalize a relative storage path.
doQuickOperationsInternal(array $ops)
getScopedPHPBehaviorForOps()
Enter file operation scope.
preloadFileStat(array $params)
Preload file stat information (concurrently if possible) into in-process cache.
Base class for all file backend classes (including multi-write backends).
describe(array $params, array $opts=[])
Performs a single describe operation.
unlockFiles(array $paths, $type)
Unlock the files at the given storage paths in the backend.
const ATTR_HEADERS
Bitfield flags for supported features.
directoryExists(array $params)
Check if a directory exists at a given storage path.
getLocalReferenceMulti(array $params)
Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths...
getFileStat(array $params)
Get quick information about a file at a storage path in the backend.
getFileXAttributes(array $params)
Get metadata about a file at a storage path in the backend.
publish(array $params)
Remove measures to block web access to a storage directory and the container it belongs to.
wrapStatus(StatusValue $sv)
resolveFSFileObjects(array $ops)
Convert FSFile 'src' paths to string paths (with an 'srcRef' field set to the FSFile)
getName()
Get the unique backend name.
getDirectoryList(array $params)
Get an iterator to list all directories under a storage directory.
getScopedFileLocks(array $paths, $type, StatusValue $status, $timeout=0)
Lock the files at the given storage paths in the backend.
getDomainId()
Get the domain identifier used for this backend (possibly empty).
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup 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
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
string $readOnly
Read-only explanation message.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
static normalizeStoragePath( $storagePath)
Normalize a storage path by cleaning up directory separators.
quickMove(array $params)
Performs a single quick move operation.
getReadOnlyReason()
Get an explanatory message if this backend is read-only.
getFileHttpUrl(array $params)
Return an HTTP URL to a given file that requires no authentication to use.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
static factory(LockManager $manager, array $paths, $type, StatusValue $status, $timeout=0)
Get a ScopedLock object representing a lock on resource paths.
setLogger(LoggerInterface $logger)
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
move(array $params, array $opts=[])
Performs a single move operation.
quickDelete(array $params)
Performs a single quick delete operation.
store(array $params, array $opts=[])
Performs a single store operation.
getFileContentsMulti(array $params)
Like getFileContents() except it takes an array of storage paths and returns a map of storage paths t...
doOperation(array $op, array $opts=[])
Same as doOperations() except it takes a single operation.
Simple version of LockManager that does nothing.
getFileTimestamp(array $params)
Get the last-modified timestamp of the file at a storage path.
getFileSize(array $params)
Get the size (bytes) of a file at a storage path in the backend.
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
int $concurrency
How many operations can be done in parallel.
create(array $params, array $opts=[])
Performs a single create operation.
Class for handling file operation journaling.
getFileSha1Base36(array $params)
Get a SHA-1 hash of the file at a storage path in the backend.
getTopFileList(array $params)
Same as FileBackend::getFileList() except only lists files that are immediately under the given direc...
__construct(array $config)
Create a new backend instance from configuration.
hasFeatures( $bitfield)
Check if the backend medium supports a field of extra features.
quickStore(array $params)
Performs a single quick store operation.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
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
doQuickOperations(array $ops, array $opts=[])
Perform a set of independent file operations on some files.
quickCreate(array $params)
Performs a single quick create operation.
lockFiles(array $paths, $type, $timeout=0)
Lock the files at the given storage paths in the backend.
static newGood( $value=null)
Factory function for good results.
quickCopy(array $params)
Performs a single quick copy operation.
quickDescribe(array $params)
Performs a single quick describe operation.
getLocalCopyMulti(array $params)
Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to T...
fileExists(array $params)
Check if a file exists at a storage path in the backend.
string $tmpDirectory
Temporary file directory.
preloadCache(array $paths)
Preload persistent file stat cache and property cache into in-process cache.
string $parallelize
When to do operations in parallel.
prepare(array $params)
Prepare a storage directory for usage.
Class representing a non-directory file on the file system.
doOperationsInternal(array $ops, array $opts)
clearCache(array $paths=null)
Invalidate any in-process file stat and property cache.
object string $profiler
Class name or object With profileIn/profileOut methods.
getFileList(array $params)
Get an iterator to list all stored files under a storage directory.
getRootStoragePath()
Get the root storage path of this backend.
getScopedLocksForOps(array $ops, StatusValue $status)
Get an array of scoped locks needed for a batch of file operations.
string $name
Unique backend name.
clean(array $params)
Delete a storage directory if it is empty.
getLocalCopy(array $params)
Get a local copy on disk of the file at a storage path in the backend.
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
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
getFileProps(array $params)
Get the properties of the file at a storage path in the backend.
static isPathTraversalFree( $path)
Check if a relative path has no directory traversals.
getJournal()
Get the file journal object for this backend.
concatenate(array $params)
Concatenate a list of storage files into a single file system file.
getTopDirectoryList(array $params)
Same as FileBackend::getDirectoryList() except only lists directories that are immediately under the ...
getLocalReference(array $params)
Returns a file system file, identical to the file at a storage path.
copy(array $params, array $opts=[])
Performs a single copy operation.
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
getFeatures()
Get the a bitfield of extra features supported by the backend medium.
static factory(array $config, $backend)
Create an appropriate FileJournal object from config.
getContainerStoragePath( $container)
Get the storage path for the given container for this backend.
getFileContents(array $params)
Get the contents of a file at a storage path in the backend.
doQuickOperation(array $op)
Same as doQuickOperations() except it takes a single operation.
getWikiId()
Alias to getDomainId()
scopedProfileSection( $section)
newStatus()
Yields the result of the status wrapper callback on either:
secure(array $params)
Take measures to block web access to a storage directory and the container it belongs to.
the array() calling protocol came about after MediaWiki 1.4rc1.
static parentStoragePath( $storagePath)
Get the parent storage directory of a storage path.
string $domainId
Unique domain name.
isReadOnly()
Check if this backend is read-only.
static makeContentDisposition( $type, $filename='')
Build a Content-Disposition header value per RFC 6266.