Go to the documentation of this file.
23 use Wikimedia\Timestamp\ConvertibleTimestamp;
72 parent::__construct( $config );
73 $this->mimeCallback = $config[
'mimeCallback'] ??
null;
76 $this->cheapCache =
new MapCacheLRU( self::CACHE_CHEAP_SIZE );
77 $this->expensiveCache =
new MapCacheLRU( self::CACHE_EXPENSIVE_SIZE );
292 if ( $nsrc !== $ndst &&
$status->isOK() ) {
356 $start_time = microtime(
true );
358 $sec = microtime(
true ) - $start_time;
361 " failed to concatenate " .
count(
$params[
'srcs'] ) .
" file(s) [$sec sec]" );
379 Wikimedia\suppressWarnings();
380 $ok = ( is_file( $tmpPath ) && filesize( $tmpPath ) == 0 );
381 Wikimedia\restoreWarnings();
383 $status->fatal(
'backend-fail-opentemp', $tmpPath );
390 foreach ( $fsFiles
as $path => &$fsFile ) {
403 $tmpHandle = fopen( $tmpPath,
'ab' );
404 if ( $tmpHandle ===
false ) {
405 $status->fatal(
'backend-fail-opentemp', $tmpPath );
411 foreach ( $fsFiles
as $virtualSource => $fsFile ) {
413 $sourceHandle = fopen( $fsFile->getPath(),
'rb' );
414 if ( $sourceHandle ===
false ) {
415 fclose( $tmpHandle );
416 $status->fatal(
'backend-fail-read', $virtualSource );
421 if ( !stream_copy_to_stream( $sourceHandle, $tmpHandle ) ) {
422 fclose( $sourceHandle );
423 fclose( $tmpHandle );
424 $status->fatal(
'backend-fail-writetemp', $tmpPath );
428 fclose( $sourceHandle );
430 if ( !fclose( $tmpHandle ) ) {
431 $status->fatal(
'backend-fail-closetemp', $tmpPath );
446 if ( $dir ===
null ) {
452 if ( $shard !==
null ) {
455 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
481 if ( $dir ===
null ) {
487 if ( $shard !==
null ) {
490 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
516 if ( $dir ===
null ) {
522 if ( $shard !==
null ) {
525 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
553 if ( $subDirsRel !==
null ) {
554 foreach ( $subDirsRel
as $subDirRel ) {
555 $subDir =
$params[
'dir'] .
"/{$subDirRel}";
558 unset( $subDirsRel );
563 if ( $dir ===
null ) {
570 $filesLockEx = [
$params[
'dir'] ];
576 if ( $shard !==
null ) {
580 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
606 return ( $stat ===
null ) ? null : (bool)$stat;
613 return $stat ? $stat[
'mtime'] :
false;
620 return $stat ? $stat[
'size'] :
false;
625 if (
$path ===
null ) {
629 $latest = !empty(
$params[
'latest'] );
630 if ( !$latest && !$this->cheapCache->hasField(
$path,
'stat', self::CACHE_TTL ) ) {
633 if ( $this->cheapCache->hasField(
$path,
'stat', self::CACHE_TTL ) ) {
634 $stat = $this->cheapCache->getField(
$path,
'stat' );
637 if ( is_array( $stat ) ) {
638 if ( !$latest || $stat[
'latest'] ) {
641 } elseif ( in_array( $stat, [
'NOT_EXIST',
'NOT_EXIST_LATEST' ] ) ) {
642 if ( !$latest || $stat ===
'NOT_EXIST_LATEST' ) {
648 if ( is_array( $stat ) ) {
650 $stat[
'latest'] = $stat[
'latest'] ?? $latest;
651 $this->cheapCache->setField(
$path,
'stat', $stat );
653 if ( isset( $stat[
'sha1'] ) ) {
654 $this->cheapCache->setField(
$path,
'sha1',
655 [
'hash' => $stat[
'sha1'],
'latest' => $latest ] );
657 if ( isset( $stat[
'xattr'] ) ) {
659 $this->cheapCache->setField(
$path,
'xattr',
660 [
'map' => $stat[
'xattr'],
'latest' => $latest ] );
662 } elseif ( $stat ===
false ) {
663 $this->cheapCache->setField(
$path,
'stat', $latest ?
'NOT_EXIST_LATEST' :
'NOT_EXIST' );
664 $this->cheapCache->setField(
$path,
'xattr', [
'map' =>
false,
'latest' => $latest ] );
665 $this->cheapCache->setField(
$path,
'sha1', [
'hash' =>
false,
'latest' => $latest ] );
666 $this->logger->debug( __METHOD__ .
': File {path} does not exist', [
670 $this->logger->warning( __METHOD__ .
': Could not stat file {path}', [
701 Wikimedia\suppressWarnings();
702 $contents[
$path] = $fsFile ? file_get_contents( $fsFile->getPath() ) :
false;
703 Wikimedia\restoreWarnings();
711 if (
$path ===
null ) {
715 $latest = !empty(
$params[
'latest'] );
716 if ( $this->cheapCache->hasField(
$path,
'xattr', self::CACHE_TTL ) ) {
717 $stat = $this->cheapCache->getField(
$path,
'xattr' );
720 if ( !$latest || $stat[
'latest'] ) {
726 $this->cheapCache->setField(
$path,
'xattr', [
'map' => $fields,
'latest' => $latest ] );
737 return [
'headers' => [],
'metadata' => [] ];
742 if (
$path ===
null ) {
746 $latest = !empty(
$params[
'latest'] );
747 if ( $this->cheapCache->hasField(
$path,
'sha1', self::CACHE_TTL ) ) {
748 $stat = $this->cheapCache->getField(
$path,
'sha1' );
751 if ( !$latest || $stat[
'latest'] ) {
752 return $stat[
'hash'];
756 $this->cheapCache->setField(
$path,
'sha1', [
'hash' => $hash,
'latest' => $latest ] );
771 return $fsFile->getSha1Base36();
789 $latest = !empty(
$params[
'latest'] );
793 if (
$path ===
null ) {
794 $fsFiles[$src] =
null;
795 } elseif ( $this->expensiveCache->hasField(
$path,
'localRef' ) ) {
796 $val = $this->expensiveCache->getField(
$path,
'localRef' );
799 if ( !$latest || $val[
'latest'] ) {
800 $fsFiles[$src] = $val[
'object'];
805 $params[
'srcs'] = array_diff(
$params[
'srcs'], array_keys( $fsFiles ) );
807 $fsFiles[
$path] = $fsFile;
809 $this->expensiveCache->setField(
$path,
'localRef',
810 [
'object' => $fsFile,
'latest' => $latest ] );
856 $params[
'options'] =
$params[
'options'] ?? [];
860 if ( ( empty(
$params[
'headless'] ) ||
$params[
'headers'] ) && headers_sent() ) {
861 print
"Headers already sent, terminating.\n";
907 if ( $dir ===
null ) {
910 if ( $shard !==
null ) {
913 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
921 } elseif ( $exists ===
null ) {
942 if ( $dir ===
null ) {
945 if ( $shard !==
null ) {
949 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
972 if ( $dir ===
null ) {
975 if ( $shard !==
null ) {
979 $this->logger->debug( __METHOD__ .
": iterating over all container shards.\n" );
1024 foreach ( $ops
as $operation ) {
1025 $opName = $operation[
'op'];
1026 if ( isset( $supportedOps[$opName] ) ) {
1027 $class = $supportedOps[$opName];
1031 $performOps[] =
new $class( $this,
$params, $this->logger );
1052 $paths = [
'sh' => [],
'ex' => [] ];
1053 foreach ( $performOps
as $fileOp ) {
1054 $paths[
'sh'] = array_merge( $paths[
'sh'], $fileOp->storagePathsRead() );
1055 $paths[
'ex'] = array_merge( $paths[
'ex'], $fileOp->storagePathsChanged() );
1058 $paths[
'sh'] = array_diff( $paths[
'sh'], $paths[
'ex'] );
1060 $paths[
'sh'] = array_merge( $paths[
'sh'], array_map(
'dirname', $paths[
'ex'] ) );
1079 $ops = array_map( [ $this,
'sanitizeOpHeaders' ], $ops );
1085 if ( empty( $opts[
'nonLocking'] ) ) {
1097 if ( empty( $opts[
'preserveCache'] ) ) {
1103 foreach ( $performOps
as $performOp ) {
1104 $paths = array_merge( $paths, $performOp->storagePathsRead() );
1105 $paths = array_merge( $paths, $performOp->storagePathsChanged() );
1109 $this->cheapCache->setMaxSize( max( 2 *
count( $paths ), self::CACHE_CHEAP_SIZE ) );
1114 $ok = $this->
preloadFileStat( [
'srcs' => $paths,
'latest' =>
true ] );
1122 $subStatus = $this->
newStatus(
'backend-fail-internal', $this->
name );
1123 foreach ( $ops
as $i => $op ) {
1124 $subStatus->success[$i] =
false;
1125 ++$subStatus->failCount;
1133 $status->success = $subStatus->success;
1136 $this->cheapCache->setMaxSize( self::CACHE_CHEAP_SIZE );
1146 $ops = array_map( [ $this,
'sanitizeOpHeaders' ], $ops );
1151 $supportedOps = [
'create',
'store',
'copy',
'move',
'delete',
'describe',
'null' ];
1153 $async = ( $this->parallelize ===
'implicit' &&
count( $ops ) > 1 );
1157 $fileOpHandles = [];
1158 $curFileOpHandles = [];
1161 if ( !in_array(
$params[
'op'], $supportedOps ) ) {
1162 throw new FileBackendError(
"Operation '{$params['op']}' is not supported." );
1164 $method =
$params[
'op'] .
'Internal';
1165 $subStatus = $this->$method( [
'async' => $async ] +
$params );
1167 if (
count( $curFileOpHandles ) >= $maxConcurrency ) {
1168 $fileOpHandles[] = $curFileOpHandles;
1169 $curFileOpHandles = [];
1171 $curFileOpHandles[$index] = $subStatus->value;
1173 $statuses[$index] = $subStatus;
1176 if (
count( $curFileOpHandles ) ) {
1177 $fileOpHandles[] = $curFileOpHandles;
1180 foreach ( $fileOpHandles
as $fileHandleBatch ) {
1184 foreach ( $statuses
as $index => $subStatus ) {
1186 if ( $subStatus->isOK() ) {
1187 $status->success[$index] =
true;
1190 $status->success[$index] =
false;
1210 foreach ( $fileOpHandles
as $fileOpHandle ) {
1212 throw new InvalidArgumentException(
"Expected FileBackendStoreOpHandle object." );
1213 } elseif ( $fileOpHandle->backend->getName() !== $this->
getName() ) {
1214 throw new InvalidArgumentException(
"Expected handle for this file backend." );
1219 foreach ( $fileOpHandles
as $fileOpHandle ) {
1220 $fileOpHandle->closeResources();
1235 if (
count( $fileOpHandles ) ) {
1236 throw new LogicException(
"Backend does not support asynchronous operations." );
1254 static $longs = [
'content-disposition' ];
1256 if ( isset( $op[
'headers'] ) ) {
1260 $maxHVLen = in_array(
$name, $longs ) ? INF : 255;
1261 if ( strlen(
$name ) > 255 || strlen(
$value ) > $maxHVLen ) {
1262 trigger_error(
"Header '$name: $value' is too long." );
1267 $op[
'headers'] = $newHeaders;
1277 $fullConts[] = $fullCont;
1285 if ( is_array( $paths ) ) {
1286 $paths = array_map(
'FileBackend::normalizeStoragePath', $paths );
1287 $paths = array_filter( $paths,
'strlen' );
1289 if ( $paths ===
null ) {
1290 $this->cheapCache->clear();
1291 $this->expensiveCache->clear();
1294 $this->cheapCache->clear(
$path );
1295 $this->expensiveCache->clear(
$path );
1315 $params[
'concurrency'] = ( $this->parallelize !==
'off' ) ? $this->concurrency : 1;
1317 if ( $stats ===
null ) {
1321 $latest = !empty(
$params[
'latest'] );
1322 foreach ( $stats
as $path => $stat ) {
1324 if (
$path ===
null ) {
1327 if ( is_array( $stat ) ) {
1329 $stat[
'latest'] = $stat[
'latest'] ?? $latest;
1330 $this->cheapCache->setField(
$path,
'stat', $stat );
1332 if ( isset( $stat[
'sha1'] ) ) {
1333 $this->cheapCache->setField(
$path,
'sha1',
1334 [
'hash' => $stat[
'sha1'],
'latest' => $latest ] );
1336 if ( isset( $stat[
'xattr'] ) ) {
1338 $this->cheapCache->setField(
$path,
'xattr',
1339 [
'map' => $stat[
'xattr'],
'latest' => $latest ] );
1341 } elseif ( $stat ===
false ) {
1342 $this->cheapCache->setField(
$path,
'stat',
1343 $latest ?
'NOT_EXIST_LATEST' :
'NOT_EXIST' );
1344 $this->cheapCache->setField(
$path,
'xattr',
1345 [
'map' =>
false,
'latest' => $latest ] );
1346 $this->cheapCache->setField(
$path,
'sha1',
1347 [
'hash' =>
false,
'latest' => $latest ] );
1348 $this->logger->debug( __METHOD__ .
': File {path} does not exist', [
1353 $this->logger->warning( __METHOD__ .
': Could not stat file {path}', [
1418 return (
bool)preg_match(
'/^[a-z0-9][a-z0-9-_.]{0,199}$/i', $container );
1436 if ( $backend === $this->
name ) {
1438 if ( $relPath !==
null && self::isValidShortContainerName( $shortCont ) ) {
1443 if ( $relPath !==
null ) {
1446 if ( self::isValidContainerName( $container ) ) {
1449 if ( $container !==
null ) {
1450 return [ $container, $relPath, $cShard ];
1457 return [
null,
null, null ];
1477 if ( $cShard !==
null && substr( $relPath, -1 ) !==
'/' ) {
1478 return [ $container, $relPath ];
1481 return [
null, null ];
1494 if ( $levels == 1 || $levels == 2 ) {
1496 $char = (
$base == 36 ) ?
'[0-9a-z]' :
'[0-9a-f]';
1499 if ( $levels === 1 ) {
1500 $hashDirRegex =
'(' . $char .
')';
1503 $hashDirRegex = $char .
'/(' . $char .
'{2})';
1505 $hashDirRegex =
'(' . $char .
')/(' . $char .
')';
1512 if ( preg_match(
"!^(?:[^/]{2,}/)*$hashDirRegex(?:/|$)!", $relPath, $m ) ) {
1513 return '.' . implode(
'', array_slice( $m, 1 ) );
1533 return ( $shard !==
null );
1545 if ( isset( $this->shardViaHashLevels[$container] ) ) {
1546 $config = $this->shardViaHashLevels[$container];
1547 $hashLevels = (int)$config[
'levels'];
1548 if ( $hashLevels == 1 || $hashLevels == 2 ) {
1549 $hashBase = (int)$config[
'base'];
1550 if ( $hashBase == 16 || $hashBase == 36 ) {
1551 return [ $hashLevels, $hashBase, $config[
'repeat'] ];
1556 return [ 0, 0,
false ];
1568 if ( $digits > 0 ) {
1569 $numShards =
$base ** $digits;
1570 for ( $index = 0; $index < $numShards; $index++ ) {
1571 $shards[] =
'.' . Wikimedia\base_convert( $index, 10,
$base, $digits );
1585 if ( $this->domainId !=
'' ) {
1586 return "{$this->domainId}-$container";
1615 return $relStoragePath;
1625 return "filebackend:{$this->name}:{$this->domainId}:container:{$container}";
1635 $this->memCache->set( $this->
containerCacheKey( $container ), $val, 14 * 86400 );
1645 if ( !$this->memCache->delete( $this->containerCacheKey( $container ), 300 ) ) {
1646 trigger_error(
"Unable to delete stat cache for container $container." );
1663 foreach ( $items
as $item ) {
1664 if ( self::isStoragePath( $item ) ) {
1666 } elseif ( is_string( $item ) ) {
1673 if ( $fullCont !==
null ) {
1680 $values = $this->memCache->getMulti( array_keys( $contNames ) );
1681 foreach ( $values
as $cacheKey => $val ) {
1682 $contInfo[$contNames[$cacheKey]] = $val;
1706 return "filebackend:{$this->name}:{$this->domainId}:file:" . sha1(
$path );
1719 if (
$path ===
null ) {
1722 $mtime = ConvertibleTimestamp::convert( TS_UNIX, $val[
'mtime'] );
1723 $ttl = $this->memCache->adaptiveTTL( $mtime, 7 * 86400, 300, 0.1 );
1726 $this->memCache->set( $key, $val, $ttl );
1739 if (
$path ===
null ) {
1742 if ( !$this->memCache->delete( $this->fileCacheKey(
$path ), 300 ) ) {
1743 trigger_error(
"Unable to delete stat cache for file $path." );
1760 foreach ( $items
as $item ) {
1761 if ( self::isStoragePath( $item ) ) {
1766 $paths = array_filter( $paths,
'strlen' );
1770 if ( $rel !==
null ) {
1775 $values = $this->memCache->getMulti( array_keys( $pathNames ) );
1776 foreach ( $values
as $cacheKey => $val ) {
1777 $path = $pathNames[$cacheKey];
1778 if ( is_array( $val ) ) {
1779 $val[
'latest'] =
false;
1780 $this->cheapCache->setField(
$path,
'stat', $val );
1781 if ( isset( $val[
'sha1'] ) ) {
1782 $this->cheapCache->setField(
$path,
'sha1',
1783 [
'hash' => $val[
'sha1'],
'latest' =>
false ] );
1785 if ( isset( $val[
'xattr'] ) ) {
1787 $this->cheapCache->setField(
$path,
'xattr',
1788 [
'map' => $val[
'xattr'],
'latest' =>
false ] );
1802 $newXAttr = [
'headers' => [],
'metadata' => [] ];
1805 $newXAttr[
'headers'][strtolower(
$name )] =
$value;
1809 $newXAttr[
'metadata'][strtolower(
$name )] =
$value;
1822 $opts[
'concurrency'] = 1;
1823 if ( $this->parallelize ===
'implicit' ) {
1824 if ( !isset( $opts[
'parallelize'] ) || $opts[
'parallelize'] ) {
1827 } elseif ( $this->parallelize ===
'explicit' ) {
1828 if ( !empty( $opts[
'parallelize'] ) ) {
1845 if ( $this->mimeCallback ) {
1846 return call_user_func_array( $this->mimeCallback, func_get_args() );
1849 $mime = ( $fsPath !== null ) ? mime_content_type( $fsPath ) :
false;
1850 return $mime ?:
'unknown/unknown';
1876 array_map(
'fclose', $this->resourcesToClose );
1917 $iter =
new AppendIterator();
1918 foreach ( $suffixes
as $suffix ) {
1919 $iter->append( $this->
listFromShard( $this->container . $suffix ) );
1922 parent::__construct( $iter );
1926 $rel = $this->getInnerIterator()->current();
1927 $path = $this->params[
'dir'] .
"/{$rel}";
1928 if ( $this->backend->isSingleShardPathInternal(
$path ) ) {
1930 } elseif ( isset( $this->multiShardPaths[$rel] ) ) {
1934 $this->multiShardPaths[$rel] = 1;
1942 $this->multiShardPaths = [];
1959 $list = $this->backend->getDirectoryListInternal(
1961 if ( $list ===
null ) {
1962 return new ArrayIterator( [] );
1964 return is_array( $list ) ?
new ArrayIterator( $list ) : $list;
1974 $list = $this->backend->getFileListInternal(
1976 if ( $list ===
null ) {
1977 return new ArrayIterator( [] );
1979 return is_array( $list ) ?
new ArrayIterator( $list ) : $list;
doGetFileXAttributes(array $params)
isPathUsableInternal( $storagePath)
Check if a file can be created or changed at a given storage path.
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
directoryExists(array $params)
Check if a directory exists at a given storage path.
getOperationsInternal(array $ops)
Return a list of FileOp objects from a list of operations.
FileBackendStore $backend
listFromShard( $container)
Get the list for a given container shard.
Status::newGood()` to allow deletion, and then `return false` from the hook function. Ensure you consume the 'ChangeTagAfterDelete' hook to carry out custom deletion actions. $tag:name of the tag $user:user initiating the action & $status:Status object. See above. 'ChangeTagsListActive':Allows you to nominate which of the tags your extension uses are in active use. & $tags:list of all active tags. Append to this array. 'ChangeTagsAfterUpdateTags':Called after tags have been updated with the ChangeTags::updateTags function. Params:$addedTags:tags effectively added in the update $removedTags:tags effectively removed in the update $prevTags:tags that were present prior to the update $rc_id:recentchanges table id $rev_id:revision table id $log_id:logging table id $params:tag params $rc:RecentChange being tagged when the tagging accompanies the action, or null $user:User who performed the tagging when the tagging is subsequent to the action, or null 'ChangeTagsAllowedAdd':Called when checking if a user can add tags to a change. & $allowedTags:List of all the tags the user is allowed to add. Any tags the user wants to add( $addTags) that are not in this array will cause it to fail. You may add or remove tags to this array as required. $addTags:List of tags user intends to add. $user:User who is adding the tags. 'ChangeUserGroups':Called before user groups are changed. $performer:The User who will perform the change $user:The User whose groups will be changed & $add:The groups that will be added & $remove:The groups that will be removed 'Collation::factory':Called if $wgCategoryCollation is an unknown collation. $collationName:Name of the collation in question & $collationObject:Null. Replace with a subclass of the Collation class that implements the collation given in $collationName. 'ConfirmEmailComplete':Called after a user 's email has been confirmed successfully. $user:user(object) whose email is being confirmed 'ContentAlterParserOutput':Modify parser output for a given content object. Called by Content::getParserOutput after parsing has finished. Can be used for changes that depend on the result of the parsing but have to be done before LinksUpdate is called(such as adding tracking categories based on the rendered HTML). $content:The Content to render $title:Title of the page, as context $parserOutput:ParserOutput to manipulate 'ContentGetParserOutput':Customize parser output for a given content object, called by AbstractContent::getParserOutput. May be used to override the normal model-specific rendering of page content. $content:The Content to render $title:Title of the page, as context $revId:The revision ID, as context $options:ParserOptions for rendering. To avoid confusing the parser cache, the output can only depend on parameters provided to this hook function, not on global state. $generateHtml:boolean, indicating whether full HTML should be generated. If false, generation of HTML may be skipped, but other information should still be present in the ParserOutput object. & $output:ParserOutput, to manipulate or replace 'ContentHandlerDefaultModelFor':Called when the default content model is determined for a given title. May be used to assign a different model for that title. $title:the Title in question & $model:the model name. Use with CONTENT_MODEL_XXX constants. 'ContentHandlerForModelID':Called when a ContentHandler is requested for a given content model name, but no entry for that model exists in $wgContentHandlers. Note:if your extension implements additional models via this hook, please use GetContentModels hook to make them known to core. $modeName:the requested content model name & $handler:set this to a ContentHandler object, if desired. 'ContentModelCanBeUsedOn':Called to determine whether that content model can be used on a given page. This is especially useful to prevent some content models to be used in some special location. $contentModel:ID of the content model in question $title:the Title in question. & $ok:Output parameter, whether it is OK to use $contentModel on $title. Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok. 'ContribsPager::getQueryInfo':Before the contributions query is about to run & $pager:Pager object for contributions & $queryInfo:The query for the contribs Pager 'ContribsPager::reallyDoQuery':Called before really executing the query for My Contributions & $data:an array of results of all contribs queries $pager:The ContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'ContributionsLineEnding':Called before a contributions HTML line is finished $page:SpecialPage object for contributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'ContributionsToolLinks':Change tool links above Special:Contributions $id:User identifier $title:User page title & $tools:Array of tool links $specialPage:SpecialPage instance for context and services. Can be either SpecialContributions or DeletedContributionsPage. Extensions should type hint against a generic SpecialPage though. 'ConvertContent':Called by AbstractContent::convert when a conversion to another content model is requested. Handler functions that modify $result should generally return false to disable further attempts at conversion. $content:The Content object to be converted. $toModel:The ID of the content model to convert to. $lossy:boolean indicating whether lossy conversion is allowed. & $result:Output parameter, in case the handler function wants to provide a converted Content object. Note that $result->getContentModel() must return $toModel. 'ContentSecurityPolicyDefaultSource':Modify the allowed CSP load sources. This affects all directives except for the script directive. If you want to add a script source, see ContentSecurityPolicyScriptSource hook. & $defaultSrc:Array of Content-Security-Policy allowed sources $policyConfig:Current configuration for the Content-Security-Policy header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyDirectives':Modify the content security policy directives. Use this only if ContentSecurityPolicyDefaultSource and ContentSecurityPolicyScriptSource do not meet your needs. & $directives:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'ContentSecurityPolicyScriptSource':Modify the allowed CSP script sources. Note that you also have to use ContentSecurityPolicyDefaultSource if you want non-script sources to be loaded from whatever you add. & $scriptSrc:Array of CSP directives $policyConfig:Current configuration for the CSP header $mode:ContentSecurityPolicy::REPORT_ONLY_MODE or ContentSecurityPolicy::FULL_MODE depending on type of header 'CustomEditor':When invoking the page editor Return true to allow the normal editor to be used, or false if implementing a custom editor, e.g. for a special namespace, etc. $article:Article being edited $user:User performing the edit 'DatabaseOraclePostInit':Called after initialising an Oracle database $db:the DatabaseOracle object 'DeletedContribsPager::reallyDoQuery':Called before really executing the query for Special:DeletedContributions Similar to ContribsPager::reallyDoQuery & $data:an array of results of all contribs queries $pager:The DeletedContribsPager object hooked into $offset:Index offset, inclusive $limit:Exact query limit $descending:Query direction, false for ascending, true for descending 'DeletedContributionsLineEnding':Called before a DeletedContributions HTML line is finished. Similar to ContributionsLineEnding $page:SpecialPage object for DeletedContributions & $ret:the HTML line $row:the DB row for this line & $classes:the classes to add to the surrounding< li > & $attribs:associative array of other HTML attributes for the< li > element. Currently only data attributes reserved to MediaWiki are allowed(see Sanitizer::isReservedDataAttribute). 'DeleteUnknownPreferences':Called by the cleanupPreferences.php maintenance script to build a WHERE clause with which to delete preferences that are not known about. This hook is used by extensions that have dynamically-named preferences that should not be deleted in the usual cleanup process. For example, the Gadgets extension creates preferences prefixed with 'gadget-', and so anything with that prefix is excluded from the deletion. &where:An array that will be passed as the $cond parameter to IDatabase::select() to determine what will be deleted from the user_properties table. $db:The IDatabase object, useful for accessing $db->buildLike() etc. 'DifferenceEngineAfterLoadNewText':called in DifferenceEngine::loadNewText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before returning true from this function. $differenceEngine:DifferenceEngine object 'DifferenceEngineLoadTextAfterNewContentIsLoaded':called in DifferenceEngine::loadText() after the new revision 's content has been loaded into the class member variable $differenceEngine->mNewContent but before checking if the variable 's value is null. This hook can be used to inject content into said class member variable. $differenceEngine:DifferenceEngine object 'DifferenceEngineMarkPatrolledLink':Allows extensions to change the "mark as patrolled" link which is shown both on the diff header as well as on the bottom of a page, usually wrapped in a span element which has class="patrollink". $differenceEngine:DifferenceEngine object & $markAsPatrolledLink:The "mark as patrolled" link HTML(string) $rcid:Recent change ID(rc_id) for this change(int) 'DifferenceEngineMarkPatrolledRCID':Allows extensions to possibly change the rcid parameter. For example the rcid might be set to zero due to the user being the same as the performer of the change but an extension might still want to show it under certain conditions. & $rcid:rc_id(int) of the change or 0 $differenceEngine:DifferenceEngine object $change:RecentChange object $user:User object representing the current user 'DifferenceEngineNewHeader':Allows extensions to change the $newHeader variable, which contains information about the new revision, such as the revision 's author, whether the revision was marked as a minor edit or not, etc. $differenceEngine:DifferenceEngine object & $newHeader:The string containing the various #mw-diff-otitle[1-5] divs, which include things like revision author info, revision comment, RevisionDelete link and more $formattedRevisionTools:Array containing revision tools, some of which may have been injected with the DiffRevisionTools hook $nextlink:String containing the link to the next revision(if any) $status
static isValidShortContainerName( $container)
Check if a short container name is valid.
Iterator for listing regular files.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getFileSha1Base36(array $params)
Get a SHA-1 hash of the file at a storage path in the backend.
static normalizeContainerPath( $path)
Validate and normalize a relative storage path.
processing should stop and the error should be shown to the user * false
The most up to date schema for the tables in the database will always be tables sql in the maintenance directory
directoriesAreVirtual()
Is this a key/value store where directories are just virtual? Virtual directories exists in so much a...
Base class for all file backend classes (including multi-write backends).
A BagOStuff object with no objects in it.
resolveStoragePath( $storagePath)
Splits a storage path into an internal container name, an internal relative file name,...
MapCacheLRU $expensiveCache
Map of paths to large (RAM/disk) cache items.
sanitizeOpHeaders(array $op)
Normalize and filter HTTP headers from a file operation.
getName()
Get the unique backend name.
copyInternal(array $params)
Copy a file from one storage path to another in the backend.
File backend exception for checked exceptions (e.g.
getScopedFileLocks(array $paths, $type, StatusValue $status, $timeout=0)
Lock the files at the given storage paths in the backend.
FileBackendStore helper function to handle listings that span container shards.
doGetFileSha1Base36(array $params)
fileExists(array $params)
Check if a file exists at a storage path in the backend.
deleteFileCache( $path)
Delete the cached stat info for a file path.
static normalizeStoragePath( $storagePath)
Normalize a storage path by cleaning up directory separators.
executeOpHandlesInternal(array $fileOpHandles)
Execute a list of FileBackendStoreOpHandle handles in parallel.
Class representing a cache/ephemeral data store.
isSingleShardPathInternal( $storagePath)
Check if a storage path maps to a single shard.
doDeleteInternal(array $params)
getFileSize(array $params)
Get the size (bytes) of a file at a storage path in the backend.
concatenate(array $params)
Concatenate a list of storage files into a single file system file.
getContainerHashLevels( $container)
Get the sharding config for a container.
doGetFileStat(array $params)
deleteContainerCache( $container)
Delete the cached info for a container.
getFileContentsMulti(array $params)
Like getFileContents() except it takes an array of storage paths and returns a map of storage paths t...
clearCache(array $paths=null)
Invalidate any in-process file stat and property cache.
MapCacheLRU $cheapCache
Map of paths to small (RAM/disk) cache items.
doPublishInternal( $container, $dir, array $params)
getFileListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
doOperationsInternal(array $ops, array $opts)
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
Iterator for listing directories.
Functions related to the output of file content.
static isValidContainerName( $container)
Check if a full container name is valid.
static placeholderProps()
Placeholder file properties to use for files that don't exist.
deleteInternal(array $params)
Delete a file at the storage path.
static newEmpty()
Get an instance that wraps EmptyBagOStuff.
and how to run hooks for an and one after Each event has a name
resolveContainerName( $container)
Resolve a container name, checking if it's allowed by the backend.
doPrimeContainerCache(array $containerInfo)
Fill the backend-specific process cache given an array of resolved container names and their correspo...
callable $mimeCallback
Method to get the MIME type of files.
getDirectoryListInternal( $container, $dir, array $params)
Do not call this function from places outside FileBackend.
getScopedLocksForOps(array $ops, StatusValue $status)
Get an array of scoped locks needed for a batch of file operations.
static normalizeXAttributes(array $xattr)
Normalize file headers/metadata to the FileBackend::getFileXAttributes() format.
setConcurrencyFlags(array $opts)
Set the 'concurrency' option from a list of operation options.
getLocalCopyMulti(array $params)
Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to T...
int $concurrency
How many operations can be done in parallel.
getFileProps(array $params)
Get the properties of the file at a storage path in the backend.
FileBackendStore $backend
doConcatenate(array $params)
doDirectoryExists( $container, $dir, array $params)
getLocalReferenceMulti(array $params)
Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths...
preloadFileStat(array $params)
Preload file stat information (concurrently if possible) into in-process cache.
doGetLocalReferenceMulti(array $params)
const CACHE_EXPENSIVE_SIZE
Handles a simple LRU key/value map with a maximum number of entries.
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
getPathsToLockForOpsInternal(array $performOps)
Get a list of storage paths to lock for a list of operations Returns an array with LockManager::LOCK_...
doCreateInternal(array $params)
getContainerShard( $container, $relPath)
Get the container name shard suffix for a given path.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
listFromShard( $container)
Get the list for a given container shard.
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
getContentType( $storagePath, $content, $fsPath)
Get the content type to use in HEAD/GET requests for a file.
doCleanInternal( $container, $dir, array $params)
doCopyInternal(array $params)
doClearCache(array $paths=null)
Clears any additional stat caches for storage paths.
if( $ext=='php'|| $ext=='php5') $mime
doStoreInternal(array $params)
doMoveInternal(array $params)
getFileStat(array $params)
Get quick information about a file at a storage path in the backend.
static attempt(array $performOps, array $opts, FileJournal $journal)
Attempt to perform a series of file operations.
containerCacheKey( $container)
Get the cache key for a container.
resolveStoragePathReal( $storagePath)
Like resolveStoragePath() except null values are returned if the container is sharded and the shard c...
Multi-datacenter aware caching interface.
moveInternal(array $params)
Move a file from one storage path to another in the backend.
preloadCache(array $paths)
Preload persistent file stat cache and property cache into in-process cache.
__construct(FileBackendStore $backend, $container, $dir, array $suffixes, array $params)
getContainerSuffixes( $container)
Get a list of full container shard suffixes for a container.
Base class for all backends using particular storage medium.
getDirectoryList(array $params)
Get an iterator to list all directories under a storage directory.
FileBackendStore helper class for performing asynchronous file operations.
static send404Message( $fname, $flags=0)
Send out a standard 404 message for a file.
fullContainerName( $container)
Get the full container name, including the wiki ID prefix.
doDescribeInternal(array $params)
doExecuteOpHandlesInternal(array $fileOpHandles)
primeContainerCache(array $items)
Do a batch lookup from cache for container stats for all containers used in a list of container names...
setFileCache( $path, array $val)
Set the cached stat info for a file path.
primeFileCache(array $items)
Do a batch lookup from cache for file stats for all paths used in a list of storage paths or FileOp o...
fileCacheKey( $path)
Get the cache key for a file path.
doPrepareInternal( $container, $dir, array $params)
doGetLocalCopyMulti(array $params)
doGetFileContentsMulti(array $params)
string $name
Unique backend name.
createInternal(array $params)
Create a file in the backend with the given contents.
resolveContainerPath( $container, $relStoragePath)
Resolve a relative storage path, checking if it's allowed by the backend.
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
string $container
Full container name.
storeInternal(array $params)
Store a file into the backend from a file on disk.
doStreamFile(array $params)
streamFile(array $params)
Stream the file at a storage path in the backend.
array $shardViaHashLevels
Map of container names to sharding config.
getTopDirectoryList(array $params)
Same as FileBackend::getDirectoryList() except only lists directories that are immediately under the ...
getFileXAttributes(array $params)
Get metadata about a file at a storage path in the backend.
getFileHttpUrl(array $params)
getLocalReference(array $params)
Returns a file system file, identical to the file at a storage path.
nullInternal(array $params)
No-op file operation that does nothing.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
getFileList(array $params)
Get an iterator to list all stored files under a storage directory.
maxFileSizeInternal()
Get the maximum allowable file size given backend medium restrictions and basic performance constrain...
getFileTimestamp(array $params)
Get the last-modified timestamp of the file at a storage path.
describeInternal(array $params)
Alter metadata for a file at the storage path.
doGetFileStatMulti(array $params)
Get file stat information (concurrently if possible) for several files.
__construct(array $config)
doSecureInternal( $container, $dir, array $params)
setContainerCache( $container, array $val)
Set the cached info for a container.
scopedProfileSection( $section)
newStatus()
Yields the result of the status wrapper callback on either:
string $directory
Resolved relative path.
doQuickOperationsInternal(array $ops)
closeResources()
Close all open file handles.
listFromShard( $container)
Get the list for a given container shard.