70 parent::__construct( $config );
73 if ( isset( $config[
'basePath'] ) ) {
74 $this->basePath = rtrim( $config[
'basePath'],
'/' );
76 $this->basePath = null;
79 if ( isset( $config[
'containerPaths'] ) ) {
80 $this->containerPaths = (
array)$config[
'containerPaths'];
81 foreach ( $this->containerPaths
as &
$path ) {
82 $path = rtrim( $path,
'/' );
86 $this->fileMode = isset( $config[
'fileMode'] ) ? $config[
'fileMode'] : 0644;
87 if ( isset( $config[
'fileOwner'] ) && function_exists(
'posix_getuid' ) ) {
88 $this->fileOwner = $config[
'fileOwner'];
90 $this->currentUser = posix_getpwuid( posix_getuid() )[
'name'];
100 if ( isset( $this->containerPaths[$container] ) || isset( $this->basePath ) ) {
103 return $relStoragePath;
118 if ( preg_match(
'![^/]{256}!',
$path ) ) {
122 return !preg_match(
'![:*?"<>|]!',
$path );
137 if ( isset( $this->containerPaths[$shortCont] ) ) {
138 return $this->containerPaths[$shortCont];
139 } elseif ( isset( $this->basePath ) ) {
140 return "{$this->basePath}/{$fullCont}";
154 if ( $relPath === null ) {
159 if ( $relPath !=
'' ) {
160 $fsPath .=
"/{$relPath}";
168 if ( $fsPath === null ) {
171 $parentDir = dirname( $fsPath );
173 if ( file_exists( $fsPath ) ) {
174 $ok = is_file( $fsPath ) && is_writable( $fsPath );
176 $ok = is_dir( $parentDir ) && is_writable( $parentDir );
179 if ( $this->fileOwner !== null && $this->currentUser !== $this->fileOwner ) {
181 trigger_error( __METHOD__ .
": PHP process owner is not '{$this->fileOwner}'." );
191 if ( $dest === null ) {
192 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
197 if ( !empty( $params[
'async'] ) ) {
200 $status->fatal(
'backend-fail-create', $params[
'dst'] );
205 $bytes = file_put_contents( $tempFile->getPath(), $params[
'content'] );
207 if ( $bytes ===
false ) {
208 $status->fatal(
'backend-fail-create', $params[
'dst'] );
212 $cmd = implode(
' ', [
218 if ( $errors !==
'' && !(
wfIsWindows() && $errors[0] ===
" " ) ) {
219 $status->fatal(
'backend-fail-create', $params[
'dst'] );
220 trigger_error(
"$cmd\n$errors", E_USER_WARNING );
223 $status->value =
new FSFileOpHandle( $this, $params, $handler, $cmd, $dest );
224 $tempFile->bind( $status->value );
227 $bytes = file_put_contents( $dest, $params[
'content'] );
229 if ( $bytes ===
false ) {
230 $status->fatal(
'backend-fail-create', $params[
'dst'] );
234 $this->
chmod( $dest );
244 if ( $dest === null ) {
245 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
250 if ( !empty( $params[
'async'] ) ) {
251 $cmd = implode(
' ', [
257 if ( $errors !==
'' && !(
wfIsWindows() && $errors[0] ===
" " ) ) {
258 $status->fatal(
'backend-fail-store', $params[
'src'], $params[
'dst'] );
259 trigger_error(
"$cmd\n$errors", E_USER_WARNING );
265 $ok =
copy( $params[
'src'], $dest );
268 if ( !$ok || ( filesize( $params[
'src'] ) !== filesize( $dest ) ) ) {
271 trigger_error( __METHOD__ .
": copy() failed but returned true." );
273 $status->fatal(
'backend-fail-store', $params[
'src'], $params[
'dst'] );
277 $this->
chmod( $dest );
288 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
294 if ( $dest === null ) {
295 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
301 if ( empty( $params[
'ignoreMissingSource'] ) ) {
302 $status->fatal(
'backend-fail-copy', $params[
'src'] );
308 if ( !empty( $params[
'async'] ) ) {
309 $cmd = implode(
' ', [
315 if ( $errors !==
'' && !(
wfIsWindows() && $errors[0] ===
" " ) ) {
316 $status->fatal(
'backend-fail-copy', $params[
'src'], $params[
'dst'] );
317 trigger_error(
"$cmd\n$errors", E_USER_WARNING );
326 if ( !$ok || ( filesize(
$source ) !== filesize( $dest ) ) ) {
331 trigger_error( __METHOD__ .
": copy() failed but returned true." );
333 $status->fatal(
'backend-fail-copy', $params[
'src'], $params[
'dst'] );
337 $this->
chmod( $dest );
348 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
354 if ( $dest === null ) {
355 $status->fatal(
'backend-fail-invalidpath', $params[
'dst'] );
361 if ( empty( $params[
'ignoreMissingSource'] ) ) {
362 $status->fatal(
'backend-fail-move', $params[
'src'] );
368 if ( !empty( $params[
'async'] ) ) {
369 $cmd = implode(
' ', [
375 if ( $errors !==
'' && !(
wfIsWindows() && $errors[0] ===
" " ) ) {
376 $status->fatal(
'backend-fail-move', $params[
'src'], $params[
'dst'] );
377 trigger_error(
"$cmd\n$errors", E_USER_WARNING );
387 $status->fatal(
'backend-fail-move', $params[
'src'], $params[
'dst'] );
401 $status->fatal(
'backend-fail-invalidpath', $params[
'src'] );
407 if ( empty( $params[
'ignoreMissingSource'] ) ) {
408 $status->fatal(
'backend-fail-delete', $params[
'src'] );
414 if ( !empty( $params[
'async'] ) ) {
415 $cmd = implode(
' ', [
420 if ( $errors !==
'' && !(
wfIsWindows() && $errors[0] ===
" " ) ) {
421 $status->fatal(
'backend-fail-delete', $params[
'src'] );
422 trigger_error(
"$cmd\n$errors", E_USER_WARNING );
431 $status->fatal(
'backend-fail-delete', $params[
'src'] );
450 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
451 $existed = is_dir(
$dir );
455 wfDebugLog(
'FSFileBackend', __METHOD__ .
": cannot create directory $dir" );
456 $status->fatal(
'directorycreateerror', $params[
'dir'] );
457 } elseif ( !is_writable(
$dir ) ) {
458 wfDebugLog(
'FSFileBackend', __METHOD__ .
": directory $dir is read-only" );
459 $status->fatal(
'directoryreadonlyerror', $params[
'dir'] );
460 } elseif ( !is_readable(
$dir ) ) {
461 wfDebugLog(
'FSFileBackend', __METHOD__ .
": directory $dir is not readable" );
462 $status->fatal(
'directorynotreadableerror', $params[
'dir'] );
466 if ( is_dir(
$dir ) && !$existed ) {
477 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
479 if ( !empty( $params[
'noListing'] ) && !file_exists(
"{$dir}/index.html" ) ) {
481 $bytes = file_put_contents(
"{$dir}/index.html", $this->
indexHtmlPrivate() );
483 if ( $bytes ===
false ) {
484 $status->fatal(
'backend-fail-create', $params[
'dir'] .
'/index.html' );
488 if ( !empty( $params[
'noAccess'] ) && !file_exists(
"{$contRoot}/.htaccess" ) ) {
490 $bytes = file_put_contents(
"{$contRoot}/.htaccess", $this->
htaccessPrivate() );
492 if ( $bytes ===
false ) {
493 $storeDir =
"mwstore://{$this->name}/{$shortCont}";
494 $status->fatal(
'backend-fail-create',
"{$storeDir}/.htaccess" );
505 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
507 if ( !empty( $params[
'listing'] ) && is_file(
"{$dir}/index.html" ) ) {
508 $exists = ( file_get_contents(
"{$dir}/index.html" ) === $this->
indexHtmlPrivate() );
510 if ( $exists && !unlink(
"{$dir}/index.html" ) ) {
511 $status->fatal(
'backend-fail-delete', $params[
'dir'] .
'/index.html' );
516 if ( !empty( $params[
'access'] ) && is_file(
"{$contRoot}/.htaccess" ) ) {
517 $exists = ( file_get_contents(
"{$contRoot}/.htaccess" ) === $this->
htaccessPrivate() );
519 if ( $exists && !unlink(
"{$contRoot}/.htaccess" ) ) {
520 $storeDir =
"mwstore://{$this->name}/{$shortCont}";
521 $status->fatal(
'backend-fail-delete',
"{$storeDir}/.htaccess" );
533 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
535 if ( is_dir(
$dir ) ) {
556 'size' => $stat[
'size']
558 } elseif ( !$hadError ) {
572 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
575 $exists = is_dir(
$dir );
578 return $hadError ? null : $exists;
591 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
592 $exists = is_dir(
$dir );
594 wfDebug( __METHOD__ .
"() given directory does not exist: '$dir'\n" );
597 } elseif ( !is_readable(
$dir ) ) {
598 wfDebug( __METHOD__ .
"() given directory is unreadable: '$dir'\n" );
616 $dir = ( $dirRel !=
'' ) ?
"{$contRoot}/{$dirRel}" : $contRoot;
617 $exists = is_dir(
$dir );
619 wfDebug( __METHOD__ .
"() given directory does not exist: '$dir'\n" );
622 } elseif ( !is_readable(
$dir ) ) {
623 wfDebug( __METHOD__ .
"() given directory is unreadable: '$dir'\n" );
634 foreach ( $params[
'srcs']
as $src ) {
637 $fsFiles[$src] = null;
649 foreach ( $params[
'srcs']
as $src ) {
652 $tmpFiles[$src] = null;
658 $tmpFiles[$src] = null;
660 $tmpPath = $tmpFile->getPath();
666 $tmpFiles[$src] = null;
668 $this->
chmod( $tmpPath );
669 $tmpFiles[$src] = $tmpFile;
691 foreach ( $fileOpHandles
as $index => $fileOpHandle ) {
692 $pipes[$index] = popen(
"{$fileOpHandle->cmd} 2>&1",
'r' );
696 foreach ( $pipes
as $index => $pipe ) {
699 $errs[$index] = stream_get_contents( $pipe );
703 foreach ( $fileOpHandles
as $index => $fileOpHandle ) {
705 $function = $fileOpHandle->call;
706 $function( $errs[$index],
$status, $fileOpHandle->params, $fileOpHandle->cmd );
708 if (
$status->isOK() && $fileOpHandle->chmodPath ) {
709 $this->
chmod( $fileOpHandle->chmodPath );
746 return "Deny from all\n";
763 $this->hadWarningErrors[] =
false;
764 set_error_handler( [ $this,
'handleWarning' ], E_WARNING );
773 restore_error_handler();
774 return array_pop( $this->hadWarningErrors );
785 $this->hadWarningErrors[count( $this->hadWarningErrors ) - 1] =
true;
842 if (
$path ===
false ) {
845 $this->suffixStart = strlen(
$path ) + 1;
850 }
catch ( UnexpectedValueException
$e ) {
862 if ( !empty( $this->params[
'topOnly'] ) ) {
863 # Get an iterator that will get direct sub-nodes
864 return new DirectoryIterator(
$dir );
866 # Get an iterator that will return leaf nodes (non-directories)
867 # RecursiveDirectoryIterator extends FilesystemIterator.
868 # FilesystemIterator::SKIP_DOTS default is inconsistent in PHP 5.3.x.
869 $flags = FilesystemIterator::CURRENT_AS_SELF | FilesystemIterator::SKIP_DOTS;
871 return new RecursiveIteratorIterator(
872 new RecursiveDirectoryIterator(
$dir,
$flags ),
873 RecursiveIteratorIterator::CHILD_FIRST
891 return $this->
getRelPath( $this->iter->current()->getPathname() );
902 }
catch ( UnexpectedValueException
$e ) {
903 throw new FileBackendError(
"File iterator gave UnexpectedValueException." );
915 $this->iter->rewind();
917 }
catch ( UnexpectedValueException
$e ) {
918 throw new FileBackendError(
"File iterator gave UnexpectedValueException." );
927 return $this->iter && $this->iter->valid();
945 if (
$path ===
false ) {
949 return strtr( substr(
$path, $this->suffixStart ),
'\\',
'/' );
955 while ( $this->iter->valid() ) {
956 if ( $this->iter->current()->isDot() || !$this->iter->current()->isDir() ) {
967 while ( $this->iter->valid() ) {
968 if ( !$this->iter->current()->isFile() ) {
static factory($prefix, $extension= '')
Make a new temporary file on the file system.
untrapWarnings()
Stop listening for E_WARNING errors and return true if any happened.
containerFSRoot($shortCont, $fullCont)
Given the short (unresolved) and full (resolved) name of a container, return the file system path of ...
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.
doDeleteInternal(array $params)
int $fileMode
File permission mode.
doMoveInternal(array $params)
doGetFileStat(array $params)
wfMkdirParents($dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
filterViaNext()
Filter out items by advancing to the next ones.
resolveToFSPath($storagePath)
Get the absolute file system path for a storage path.
Generic operation result class Has warning/error list, boolean status and arbitrary value...
resolveContainerPath($container, $relStoragePath)
doExecuteOpHandlesInternal(array $fileOpHandles)
doGetLocalCopyMulti(array $params)
it s the revision text itself In either if gzip is the revision text is gzipped $flags
array $containerPaths
Map of container names to root paths for custom container paths.
__construct($dir, array $params)
wfIsWindows()
Check if the operating system is Windows.
static extensionFromPath($path, $case= 'lowercase')
Get the final extension from a storage or FS path.
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
__construct(array $config)
chmod($path)
Chmod a file, suppressing the warnings.
isPathUsableInternal($storagePath)
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
Wrapper around RecursiveDirectoryIterator/DirectoryIterator that catches exception or does any custom...
File backend exception for checked exceptions (e.g.
indexHtmlPrivate()
Return the text of an index.html file to hide directory listings.
cleanPathSlashes($path)
Clean up directory separators for the given OS.
doStoreInternal(array $params)
FileBackendStore $backend
htaccessPrivate()
Return the text of a .htaccess file to make a directory private.
getFileListInternal($fullCont, $dirRel, array $params)
resolveStoragePathReal($storagePath)
Like resolveStoragePath() except null values are returned if the container is sharded and the shard c...
doDirectoryExists($fullCont, $dirRel, array $params)
initIterator($dir)
Return an appropriate iterator object to wrap.
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
doCopyInternal(array $params)
Base class for all backends using particular storage medium.
trapWarnings()
Listen for E_WARNING errors and track whether any happen.
doPrepareInternal($fullCont, $dirRel, array $params)
__construct(FSFileBackend $backend, array $params, $call, $cmd, $chmodPath=null)
string $basePath
Directory holding the container directories.
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
doPublishInternal($fullCont, $dirRel, array $params)
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
isLegalRelPath($path)
Sanity check a relative file system path for validity.
doCreateInternal(array $params)
Class representing a non-directory file on the file system.
copy(array $params, array $opts=[])
Performs a single copy operation.
getRelPath($dir)
Return only the relative path and normalize slashes to FileBackend-style.
string $currentUser
OS username running this script.
handleWarning($errno, $errstr)
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
wfEscapeShellArg()
Windows-compatible version of escapeshellarg() Windows doesn't recognise single-quotes in the shell...
doSecureInternal($fullCont, $dirRel, array $params)
doGetLocalReferenceMulti(array $params)
getDirectoryListInternal($fullCont, $dirRel, array $params)
static splitStoragePath($storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
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 modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Class for a file system (FS) based file backend.
FileBackendStore helper class for performing asynchronous file operations.
doClearCache(array $paths=null)
static newGood($value=null)
Factory function for good results.
string $fileOwner
Required OS username to own files.
doCleanInternal($fullCont, $dirRel, array $params)