17 use Wikimedia\AtEase\AtEase;
136 protected $fileFactory = [ UnregisteredLocalFile::class,
'newFromTitle' ];
174 || !array_key_exists(
'name', $info )
175 || !array_key_exists(
'backend', $info )
178 " requires an array of options having both 'name' and 'backend' keys.\n" );
182 $this->name = $info[
'name'];
184 $this->backend = $info[
'backend'];
187 MediaWikiServices::getInstance()->getFileBackendGroup()->get( $info[
'backend'] );
191 $optionalSettings = [
192 'descBaseUrl',
'scriptDirUrl',
'articleUrl',
'fetchDescription',
193 'thumbScriptUrl',
'pathDisclosureProtection',
'descriptionCacheExpiry',
194 'favicon',
'thumbProxyUrl',
'thumbProxySecret',
'disableLocalTransform'
196 foreach ( $optionalSettings as $var ) {
197 if ( isset( $info[$var] ) ) {
198 $this->$var = $info[$var];
204 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized(
NS_FILE );
205 $this->initialCapital = $info[
'initialCapital'] ?? $localCapitalLinks;
206 if ( $localCapitalLinks && !$this->initialCapital ) {
214 throw new InvalidArgumentException(
215 'File repos with initial capital false are not allowed on wikis where the File ' .
216 'namespace has initial capital true' );
219 $this->url = $info[
'url'] ??
false;
220 $defaultThumbUrl = $this->url ? $this->url .
'/thumb' :
false;
221 $this->thumbUrl = $info[
'thumbUrl'] ?? $defaultThumbUrl;
222 $this->hashLevels = $info[
'hashLevels'] ?? 2;
224 $this->transformVia404 = !empty( $info[
'transformVia404'] );
225 $this->abbrvThreshold = $info[
'abbrvThreshold'] ?? 255;
226 $this->isPrivate = !empty( $info[
'isPrivate'] );
228 $this->zones = $info[
'zones'] ?? [];
229 foreach ( [
'public',
'thumb',
'transcoded',
'temp',
'deleted' ] as $zone ) {
230 if ( !isset( $this->zones[$zone][
'container'] ) ) {
231 $this->zones[$zone][
'container'] =
"{$this->name}-{$zone}";
233 if ( !isset( $this->zones[$zone][
'directory'] ) ) {
234 $this->zones[$zone][
'directory'] =
'';
236 if ( !isset( $this->zones[$zone][
'urlsByExt'] ) ) {
237 $this->zones[$zone][
'urlsByExt'] = [];
262 return $this->backend->getReadOnlyReason();
272 foreach ( (array)$doZones as $zone ) {
274 if ( $root ===
null ) {
275 throw new MWException(
"No '$zone' zone defined in the {$this->name} repo." );
287 return str_starts_with( $url,
'mwrepo://' );
299 $path =
'mwrepo://' . $this->name;
300 if ( $suffix !==
false ) {
301 $path .=
'/' . rawurlencode( $suffix );
315 if ( in_array( $zone, [
'public',
'thumb',
'transcoded' ] ) ) {
317 if (
$ext !==
null && isset( $this->zones[$zone][
'urlsByExt'][
$ext] ) ) {
320 return $this->zones[$zone][
'urlsByExt'][
$ext];
321 } elseif ( isset( $this->zones[$zone][
'url'] ) ) {
323 return $this->zones[$zone][
'url'];
333 return $this->thumbUrl;
335 return "{$this->url}/transcoded";
357 if ( !str_starts_with( $url,
'mwrepo://' ) ) {
358 throw new MWException( __METHOD__ .
': unknown protocol' );
360 $bits = explode(
'/', substr( $url, 9 ), 3 );
361 if ( count( $bits ) != 3 ) {
362 throw new MWException( __METHOD__ .
": invalid mwrepo URL: $url" );
364 [ $repo, $zone, $rel ] = $bits;
365 if ( $repo !== $this->name ) {
366 throw new MWException( __METHOD__ .
": fetching from a foreign repo is not supported" );
368 $base = $this->getZonePath( $zone );
370 throw new MWException( __METHOD__ .
": invalid zone: $zone" );
373 return $base .
'/' . rawurldecode( $rel );
383 if ( !isset( $this->zones[$zone] ) ) {
384 return [
null, null ];
387 return [ $this->zones[$zone][
'container'], $this->zones[$zone][
'directory'] ];
397 [ $container, $base ] = $this->getZoneLocation( $zone );
398 if ( $container ===
null || $base ===
null ) {
401 $backendName = $this->backend->getName();
406 return "mwstore://$backendName/{$container}{$base}";
426 if ( $this->oldFileFactory ) {
427 return call_user_func( $this->oldFileFactory,
$title, $this, $time );
432 return call_user_func( $this->fileFactory,
$title, $this );
456 if ( !empty( $options[
'private'] ) && !( $options[
'private'] instanceof
Authority ) ) {
457 throw new InvalidArgumentException(
458 __METHOD__ .
' called with the `private` option set to something ' .
459 'other than an Authority object'
467 if ( isset( $options[
'bypassCache'] ) ) {
468 $options[
'latest'] = $options[
'bypassCache'];
470 $time = $options[
'time'] ??
false;
471 $flags = !empty( $options[
'latest'] ) ? File::READ_LATEST : 0;
472 # First try the current version of the file to see if it precedes the timestamp
473 $img = $this->newFile(
$title );
477 $img->load( $flags );
478 if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
481 # Now try an old version of the file
482 if ( $time !==
false ) {
483 $img = $this->newFile(
$title, $time );
485 $img->load( $flags );
486 if ( $img->exists() ) {
491 !empty( $options[
'private'] ) &&
501 if ( !empty( $options[
'ignoreRedirect'] ) ) {
504 $redir = $this->checkRedirect(
$title );
506 $img = $this->newFile( $redir );
510 $img->load( $flags );
511 if ( $img->exists() ) {
512 $img->redirectedFrom(
$title->getDBkey() );
540 foreach ( $items as $item ) {
541 if ( is_array( $item ) ) {
544 unset( $options[
'title'] );
547 !empty( $options[
'private'] ) &&
548 !( $options[
'private'] instanceof
Authority )
559 if ( $flags & self::NAME_AND_TIME_ONLY ) {
560 $result[$searchName] = [
561 'title' =>
$file->getTitle()->getDBkey(),
562 'timestamp' =>
$file->getTimestamp()
565 $result[$searchName] =
$file;
584 if ( !empty( $options[
'private'] ) && !( $options[
'private'] instanceof
Authority ) ) {
585 throw new InvalidArgumentException(
586 __METHOD__ .
' called with the `private` option set to something ' .
587 'other than an Authority object'
591 $time = $options[
'time'] ??
false;
592 # First try to find a matching current version of a file...
593 if ( !$this->fileFactoryKey ) {
596 $img = call_user_func( $this->fileFactoryKey, $sha1, $this, $time );
597 if ( $img && $img->exists() ) {
600 # Now try to find a matching old version of a file...
601 if ( $time !==
false && $this->oldFileFactoryKey ) {
602 $img = call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
603 if ( $img && $img->exists() ) {
608 !empty( $options[
'private'] ) &&
641 $files = $this->findBySha1( $hash );
642 if ( count( $files ) ) {
643 $result[$hash] = $files;
668 return $this->thumbScriptUrl;
677 return $this->thumbProxyUrl;
686 return $this->thumbProxySecret;
695 return $this->transformVia404;
705 return !$this->disableLocalTransform;
716 $this->initialCapital !=
717 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized(
NS_FILE )
719 $name =
$title->getDBkey();
720 if ( $this->initialCapital ) {
721 $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
724 $name =
$title->getDBkey();
736 return $this->getZonePath(
'public' );
747 return self::getHashPathForLevel( $name, $this->hashLevels );
758 $parts = explode(
'!', $suffix, 2 );
759 $name = $parts[1] ?? $suffix;
760 return self::getHashPathForLevel( $name, $this->hashLevels );
769 if ( $levels == 0 ) {
772 $hash = md5( $name );
774 for ( $i = 1; $i <= $levels; $i++ ) {
775 $path .= substr( $hash, 0, $i ) .
'/';
788 return $this->hashLevels;
807 public function makeUrl( $query =
'', $entry =
'index' ) {
808 if ( isset( $this->scriptDirUrl ) ) {
809 return wfAppendQuery(
"{$this->scriptDirUrl}/{$entry}.php", $query );
829 if ( $this->descBaseUrl !==
null ) {
830 # "http://example.com/wiki/File:"
831 return $this->descBaseUrl . $encName;
833 if ( $this->articleUrl !==
null ) {
834 # "http://example.com/wiki/$1"
835 # We use "Image:" as the canonical namespace for
836 # compatibility across all MediaWiki versions.
837 return str_replace(
'$1',
838 "Image:$encName", $this->articleUrl );
840 if ( $this->scriptDirUrl !==
null ) {
841 # "http://example.com/w"
842 # We use "Image:" as the canonical namespace for
843 # compatibility across all MediaWiki versions,
844 # and just sort of hope index.php is right. ;)
845 return $this->makeUrl(
"title=Image:$encName" );
862 $query =
'action=render';
863 if (
$lang !==
null ) {
864 $query .=
'&uselang=' . urlencode(
$lang );
866 if ( isset( $this->scriptDirUrl ) ) {
867 return $this->makeUrl(
872 $descUrl = $this->getDescriptionUrl( $name );
887 if ( isset( $this->scriptDirUrl ) ) {
890 return $this->makeUrl(
'title=MediaWiki:Filepage.css&action=raw&ctype=text/css' );
913 public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
914 $this->assertWritableRepo();
916 $status = $this->storeBatch( [ [ $srcPath, $dstZone, $dstRel ] ], $flags );
917 if ( $status->successCount == 0 ) {
918 $status->setOK(
false );
939 $this->assertWritableRepo();
941 if ( $flags & self::DELETE_SOURCE ) {
942 throw new InvalidArgumentException(
"DELETE_SOURCE not supported in " . __METHOD__ );
945 $status = $this->newGood();
946 $backend = $this->backend;
950 foreach ( $triplets as $triplet ) {
951 [ $src, $dstZone, $dstRel ] = $triplet;
952 $srcPath = ( $src instanceof
FSFile ) ? $src->getPath() : $src;
954 .
"( \$src='$srcPath', \$dstZone='$dstZone', \$dstRel='$dstRel' )"
957 if ( $src instanceof
FSFile ) {
960 $src = $this->resolveToStoragePathIfVirtual( $src );
964 $root = $this->getZonePath( $dstZone );
968 if ( !$this->validateFilename( $dstRel ) ) {
969 throw new MWException(
'Validation error in $dstRel' );
971 $dstPath =
"$root/$dstRel";
972 $dstDir = dirname( $dstPath );
974 if ( !$this->initDirectory( $dstDir )->isOK() ) {
975 return $this->newFatal(
'directorycreateerror', $dstDir );
983 'overwrite' => (bool)( $flags & self::OVERWRITE ),
984 'overwriteSame' => (bool)( $flags & self::OVERWRITE_SAME ),
989 $opts = [
'force' =>
true ];
990 if ( $flags & self::SKIP_LOCKING ) {
991 $opts[
'nonLocking'] =
true;
994 return $status->merge( $backend->doOperations( $operations, $opts ) );
1008 $this->assertWritableRepo();
1010 $status = $this->newGood();
1013 foreach ( $files as
$path ) {
1014 if ( is_array(
$path ) ) {
1016 [ $zone, $rel ] =
$path;
1017 $path = $this->getZonePath( $zone ) .
"/$rel";
1020 $path = $this->resolveToStoragePathIfVirtual(
$path );
1022 $operations[] = [
'op' =>
'delete',
'src' =>
$path ];
1025 $opts = [
'force' =>
true ];
1026 if ( $flags & self::SKIP_LOCKING ) {
1027 $opts[
'nonLocking'] =
true;
1030 return $status->merge( $this->backend->doOperations( $operations, $opts ) );
1051 return $this->quickImportBatch( [ [ $src, $dst, $options ] ] );
1069 $status = $this->newGood();
1071 foreach ( $triples as $triple ) {
1072 [ $src, $dst ] = $triple;
1073 if ( $src instanceof
FSFile ) {
1076 $src = $this->resolveToStoragePathIfVirtual( $src );
1079 $dst = $this->resolveToStoragePathIfVirtual( $dst );
1081 if ( !isset( $triple[2] ) ) {
1083 } elseif ( is_string( $triple[2] ) ) {
1085 $headers = [
'Content-Disposition' => $triple[2] ];
1086 } elseif ( is_array( $triple[2] ) && isset( $triple[2][
'headers'] ) ) {
1087 $headers = $triple[2][
'headers'];
1096 'headers' => $headers
1098 $status->merge( $this->initDirectory( dirname( $dst ) ) );
1101 return $status->merge( $this->backend->doQuickOperations( $operations ) );
1113 return $this->quickPurgeBatch( [
$path ] );
1124 return $this->newGood()->merge(
1125 $this->backend->clean(
1126 [
'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ]
1140 $status = $this->newGood();
1142 foreach ( $paths as
$path ) {
1145 'src' => $this->resolveToStoragePathIfVirtual(
$path ),
1146 'ignoreMissingSource' =>
true
1149 $status->merge( $this->backend->doQuickOperations( $operations ) );
1165 $this->assertWritableRepo();
1168 $hashPath = $this->getHashPath( $originalName );
1169 $dstUrlRel = $hashPath . $date .
'!' . rawurlencode( $originalName );
1170 $virtualUrl = $this->getVirtualUrl(
'temp' ) .
'/' . $dstUrlRel;
1172 $result = $this->quickImport( $srcPath, $virtualUrl );
1173 $result->value = $virtualUrl;
1185 $this->assertWritableRepo();
1187 $temp = $this->getVirtualUrl(
'temp' );
1188 if ( !str_starts_with( $virtualUrl, $temp ) ) {
1189 wfDebug( __METHOD__ .
": Invalid temp virtual URL" );
1194 return $this->quickPurge( $virtualUrl )->isOK();
1206 public function concatenate( array $srcPaths, $dstPath, $flags = 0 ) {
1207 $this->assertWritableRepo();
1209 $status = $this->newGood();
1212 foreach ( $srcPaths as $srcPath ) {
1214 $source = $this->resolveToStoragePathIfVirtual( $srcPath );
1219 $params = [
'srcs' => $sources,
'dst' => $dstPath ];
1220 $status->merge( $this->backend->concatenate( $params ) );
1221 if ( !$status->isOK() ) {
1226 if ( $flags & self::DELETE_SOURCE ) {
1227 $status->merge( $this->quickPurgeBatch( $srcPaths ) );
1231 $status->setResult(
true );
1260 $src, $dstRel, $archiveRel, $flags = 0, array $options = []
1262 $this->assertWritableRepo();
1264 $status = $this->publishBatch(
1265 [ [ $src, $dstRel, $archiveRel, $options ] ], $flags );
1266 if ( $status->successCount == 0 ) {
1267 $status->setOK(
false );
1269 $status->value = $status->value[0] ??
false;
1287 $this->assertWritableRepo();
1289 $backend = $this->backend;
1291 $this->initZones(
'public' );
1293 $status = $this->newGood( [] );
1296 $sourceFSFilesToDelete = [];
1298 foreach ( $ntuples as $ntuple ) {
1299 [ $src, $dstRel, $archiveRel ] = $ntuple;
1300 $srcPath = ( $src instanceof
FSFile ) ? $src->getPath() : $src;
1302 $options = $ntuple[3] ?? [];
1304 $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
1305 if ( !$this->validateFilename( $dstRel ) ) {
1306 throw new MWException(
'Validation error in $dstRel' );
1308 if ( !$this->validateFilename( $archiveRel ) ) {
1309 throw new MWException(
'Validation error in $archiveRel' );
1312 $publicRoot = $this->getZonePath(
'public' );
1313 $dstPath =
"$publicRoot/$dstRel";
1314 $archivePath =
"$publicRoot/$archiveRel";
1316 $dstDir = dirname( $dstPath );
1317 $archiveDir = dirname( $archivePath );
1319 if ( !$this->initDirectory( $dstDir )->isOK() ) {
1320 return $this->newFatal(
'directorycreateerror', $dstDir );
1322 if ( !$this->initDirectory( $archiveDir )->isOK() ) {
1323 return $this->newFatal(
'directorycreateerror', $archiveDir );
1327 $headers = $options[
'headers'] ?? [];
1338 'dst' => $archivePath,
1339 'ignoreMissingSource' =>
true
1345 'op' => ( $flags & self::DELETE_SOURCE ) ?
'move' :
'copy',
1348 'overwrite' =>
true,
1349 'headers' => $headers
1356 'overwrite' =>
true,
1357 'headers' => $headers
1359 if ( $flags & self::DELETE_SOURCE ) {
1360 $sourceFSFilesToDelete[] = $srcPath;
1366 $status->merge( $backend->doOperations( $operations ) );
1368 foreach ( $ntuples as $i => $ntuple ) {
1369 [ , , $archiveRel ] = $ntuple;
1370 $archivePath = $this->getZonePath(
'public' ) .
"/$archiveRel";
1371 if ( $this->fileExists( $archivePath ) ) {
1372 $status->value[$i] =
'archived';
1374 $status->value[$i] =
'new';
1378 foreach ( $sourceFSFilesToDelete as
$file ) {
1379 AtEase::suppressWarnings();
1381 AtEase::restoreWarnings();
1395 $path = $this->resolveToStoragePathIfVirtual( $dir );
1398 $params = [
'dir' =>
$path ];
1399 if ( $this->isPrivate
1400 || $container === $this->zones[
'deleted'][
'container']
1401 || $container === $this->zones[
'temp'][
'container']
1403 # Take all available measures to prevent web accessibility of new deleted
1404 # directories, in case the user has not configured offline storage
1405 $params = [
'noAccess' =>
true,
'noListing' =>
true ] + $params;
1408 return $this->newGood()->merge( $this->backend->prepare( $params ) );
1418 $this->assertWritableRepo();
1420 return $this->newGood()->merge(
1421 $this->backend->clean(
1422 [
'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ]
1434 $result = $this->fileExistsBatch( [
$file ] );
1447 $paths = array_map( [ $this,
'resolveToStoragePathIfVirtual' ], $files );
1448 $this->backend->preloadFileStat( [
'srcs' => $paths ] );
1451 foreach ( $files as $key =>
$file ) {
1452 $path = $this->resolveToStoragePathIfVirtual(
$file );
1453 $result[$key] = $this->backend->fileExists( [
'src' =>
$path ] );
1469 public function delete( $srcRel, $archiveRel ) {
1470 $this->assertWritableRepo();
1472 return $this->deleteBatch( [ [ $srcRel, $archiveRel ] ] );
1493 $this->assertWritableRepo();
1496 $this->initZones( [
'public',
'deleted' ] );
1498 $status = $this->newGood();
1500 $backend = $this->backend;
1503 foreach ( $sourceDestPairs as [ $srcRel, $archiveRel ] ) {
1504 if ( !$this->validateFilename( $srcRel ) ) {
1505 throw new MWException( __METHOD__ .
':Validation error in $srcRel' );
1506 } elseif ( !$this->validateFilename( $archiveRel ) ) {
1507 throw new MWException( __METHOD__ .
':Validation error in $archiveRel' );
1510 $publicRoot = $this->getZonePath(
'public' );
1511 $srcPath =
"{$publicRoot}/$srcRel";
1513 $deletedRoot = $this->getZonePath(
'deleted' );
1514 $archivePath =
"{$deletedRoot}/{$archiveRel}";
1515 $archiveDir = dirname( $archivePath );
1518 if ( !$this->initDirectory( $archiveDir )->isGood() ) {
1519 return $this->newFatal(
'directorycreateerror', $archiveDir );
1525 'dst' => $archivePath,
1528 'overwriteSame' =>
true
1535 $opts = [
'force' =>
true ];
1536 return $status->merge( $backend->doOperations( $operations, $opts ) );
1546 $this->assertWritableRepo();
1558 if ( strlen( $key ) < 31 ) {
1559 throw new MWException(
"Invalid storage key '$key'." );
1562 for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) {
1563 $path .= $key[$i] .
'/';
1578 if ( self::isVirtualUrl(
$path ) ) {
1579 return $this->resolveVirtualUrl(
$path );
1593 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1595 return $this->backend->getLocalCopy( [
'src' =>
$path ] );
1607 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1609 return $this->backend->getLocalReference( [
'src' =>
$path ] );
1620 $fsFile = $this->getLocalReference( $virtualUrl );
1621 $mwProps =
new MWFileProps( MediaWikiServices::getInstance()->getMimeAnalyzer() );
1623 $props = $mwProps->getPropsFromPath( $fsFile->getPath(),
true );
1625 $props = $mwProps->newPlaceholderProps();
1638 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1640 return $this->backend->getFileTimestamp( [
'src' =>
$path ] );
1650 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1652 return $this->backend->getFileSize( [
'src' =>
$path ] );
1662 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1664 return $this->backend->getFileSha1Base36( [
'src' =>
$path ] );
1677 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1678 $params = [
'src' =>
$path,
'headers' => $headers,
'options' => $optHeaders ];
1681 ob_start(
null, 1048576 );
1682 ob_implicit_flush(
true );
1684 $status = $this->newGood()->merge( $this->backend->streamFile( $params ) );
1688 if ( ob_get_status() ) {
1704 $this->enumFilesInStorage( $callback );
1715 $publicRoot = $this->getZonePath(
'public' );
1716 $numDirs = 1 << ( $this->hashLevels * 4 );
1719 for ( $flatIndex = 0; $flatIndex < $numDirs; $flatIndex++ ) {
1720 $hexString = sprintf(
"%0{$this->hashLevels}x", $flatIndex );
1721 $path = $publicRoot;
1722 for ( $hexPos = 0; $hexPos < $this->hashLevels; $hexPos++ ) {
1723 $path .=
'/' . substr( $hexString, 0, $hexPos + 1 );
1725 $iterator = $this->backend->getFileList( [
'dir' =>
$path ] );
1726 if ( $iterator ===
null ) {
1727 throw new MWException( __METHOD__ .
': could not get file listing for ' .
$path );
1729 foreach ( $iterator as $name ) {
1731 call_user_func( $callback,
"{$path}/{$name}" );
1743 if ( strval( $filename ) ==
'' ) {
1755 private function getErrorCleanupFunction() {
1756 switch ( $this->pathDisclosureProtection ) {
1759 $callback = [ $this,
'passThrough' ];
1762 $callback = [ $this,
'paranoidClean' ];
1796 $status->cleanCallback = $this->getErrorCleanupFunction();
1809 $status->cleanCallback = $this->getErrorCleanupFunction();
1842 $sitename = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Sitename );
1844 if ( $this->isLocal() ) {
1849 return wfMessageFallback(
'shared-repo-name-' . $this->name,
'shared-repo' )->text();
1860 if ( strlen( $name ) > $this->abbrvThreshold ) {
1862 $name = (
$ext ==
'' ) ?
'thumbnail' :
"thumbnail.$ext";
1874 return $this->getName() ==
'local';
1904 return $this->wanCache->makeKey(
1905 'filerepo-' . $kClassSuffix,
1921 'name' =>
"{$this->name}-temp",
1922 'backend' => $this->backend,
1927 'container' => $this->zones[
'temp'][
'container'],
1928 'directory' => $this->zones[
'temp'][
'directory']
1931 'container' => $this->zones[
'temp'][
'container'],
1932 'directory' => $this->zones[
'temp'][
'directory'] ==
''
1934 : $this->zones[
'temp'][
'directory'] .
'/thumb'
1937 'container' => $this->zones[
'temp'][
'container'],
1938 'directory' => $this->zones[
'temp'][
'directory'] ==
''
1940 : $this->zones[
'temp'][
'directory'] .
'/transcoded'
1943 'hashLevels' => $this->hashLevels,
1975 'name' => $this->getName(),
1976 'displayname' => $this->getDisplayName(),
1977 'rootUrl' => $this->getZoneUrl(
'public' ),
1978 'local' => $this->isLocal(),
1981 $optionalSettings = [
1989 'descriptionCacheExpiry',
1991 foreach ( $optionalSettings as $k ) {
1992 if ( isset( $this->$k ) ) {
1993 $ret[$k] = $this->$k;
1996 if ( isset( $this->favicon ) ) {
1998 $ret[
'favicon'] = MediaWikiServices::getInstance()->getUrlUtils()
1999 ->expand( $this->favicon );
2010 return $this->hasSha1Storage;
2018 return $this->supportsSha1URLs;
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfUrlencode( $s)
We want some things to be included as literal characters in our title URLs for prettiness,...
wfMessageFallback(... $keys)
This function accepts multiple message keys and returns a message instance for the first message whic...
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Class representing a non-directory file on the file system.
Base class for all file backend classes (including multi-write backends).
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
static splitStoragePath( $storagePath)
Split a storage path into a backend name, a container name, and a relative file path.
static extensionFromPath( $path, $case='lowercase')
Get the final extension from a storage or FS path.
static isPathTraversalFree( $path)
Check if a relative path has no directory traversals.
Base class for file repositories.
string $pathDisclosureProtection
May be 'paranoid' to remove all parameters from error messages, 'none' to leave the paths in unchange...
getTempHashPath( $suffix)
Get a relative path including trailing slash, e.g.
int $hashLevels
The number of directory levels for hash-based division of files.
getTempRepo()
Get a temporary private FileRepo associated with this repo.
cleanupDeletedBatch(array $storageKeys)
Delete files in the deleted directory if they are not referenced in the filearchive table.
resolveVirtualUrl( $url)
Get the backend storage path corresponding to a virtual URL.
nameForThumb( $name)
Get the portion of the file that contains the origin file name.
publishBatch(array $ntuples, $flags=0)
Publish a batch of files.
findFiles(array $items, $flags=0)
Find many files at once.
newFatal( $message,... $parameters)
Create a new fatal error.
getThumbProxyUrl()
Get the URL thumb.php requests are being proxied to.
getZoneLocation( $zone)
The storage container and base path of a zone.
fileExists( $file)
Checks existence of a file.
getFileSha1( $virtualUrl)
Get the sha1 (base 36) of a file with a given virtual URL/storage path.
quickImportBatch(array $triples)
Import a batch of files from the local file system into the repo.
assertWritableRepo()
Throw an exception if this repo is read-only by design.
getRootDirectory()
Get the public zone root storage directory of the repository.
supportsSha1URLs()
Returns whether or not repo supports having originals SHA-1s in the thumb URLs.
newGood( $value=null)
Create a new good result.
findFilesByPrefix( $prefix, $limit)
Return an array of files where the name starts with $prefix.
getHashLevels()
Get the number of hash directory levels.
string $thumbProxySecret
Secret key to pass as an X-Swift-Secret header to the proxied thumb service.
streamFileWithStatus( $virtualUrl, $headers=[], $optHeaders=[])
Attempt to stream a file with the given virtual URL/storage path.
getName()
Get the name of this repository, as specified by $info['name]' to the constructor.
store( $srcPath, $dstZone, $dstRel, $flags=0)
Store a file to a given destination.
findFile( $title, $options=[])
Find an instance of the named file created at the specified time Returns false if the file does not e...
callable false $oldFileFactoryKey
Override these in the base class.
getVirtualUrl( $suffix=false)
Get a URL referring to this repository, with the private mwrepo protocol.
quickPurge( $path)
Purge a file from the repo.
quickPurgeBatch(array $paths)
Purge a batch of files from the repo.
passThrough( $param)
Path disclosure protection function.
static getHashPathForLevel( $name, $levels)
array $zones
Map of zones to config.
callable false $fileFactoryKey
Override these in the base class.
checkRedirect( $title)
Checks if there is a redirect named as $title.
getDisplayName()
Get the human-readable name of the repo.
getSharedCacheKey( $kClassSuffix,... $components)
Get a global, repository-qualified, WAN cache key.
getLocalCacheKey( $kClassSuffix,... $components)
Get a site-local, repository-qualified, WAN cache key.
bool $disableLocalTransform
Disable local image scaling.
storeBatch(array $triplets, $flags=0)
Store a batch of files.
enumFiles( $callback)
Call a callback function for every public regular file in the repository.
canTransformLocally()
Returns true if the repository can transform files locally.
hasSha1Storage()
Returns whether or not storage is SHA-1 based.
cleanupBatch(array $files, $flags=0)
Deletes a batch of files.
publish( $src, $dstRel, $archiveRel, $flags=0, array $options=[])
Copy or move a file either from a storage path, virtual URL, or file system path, into this repositor...
initDirectory( $dir)
Creates a directory with the appropriate zone permissions.
int $abbrvThreshold
File names over this size will use the short form of thumbnail names.
makeUrl( $query='', $entry='index')
Make an url to this repo.
findBySha1s(array $hashes)
Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashe...
string $thumbProxyUrl
URL of where to proxy thumb.php requests to.
concatenate(array $srcPaths, $dstPath, $flags=0)
Concatenate a list of temporary files into a target file location.
null string $favicon
The URL to a favicon (optional, may be a server-local path URL).
fileExistsBatch(array $files)
Checks existence of an array of files.
int $descriptionCacheExpiry
paranoidClean( $param)
Path disclosure protection function.
initZones( $doZones=[])
Ensure that a single zone or list of zones is defined for usage.
getFileProps( $virtualUrl)
Get properties of a file with a given virtual URL/storage path.
isLocal()
Returns true if this the local file repository.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
getUploadStash(UserIdentity $user=null)
Get an UploadStash associated with this repo.
getDescriptionUrl( $name)
Get the URL of an image description page.
cleanDir( $dir)
Deletes a directory if empty.
resolveToStoragePathIfVirtual( $path)
If a path is a virtual URL, resolve it to a storage path.
getDeletedHashPath( $key)
Get a relative path for a deletion archive key, e.g.
getNameFromTitle( $title)
Get the name of a file from its title.
invalidateImageRedirect( $title)
Invalidates image redirect cache related to that image Doesn't do anything for repositories that don'...
getFileSize( $virtualUrl)
Get the size of a file with a given virtual URL/storage path.
getThumbProxySecret()
Get the secret key for the proxied thumb service.
bool $fetchDescription
Whether to fetch commons image description pages and display them on the local wiki.
string false $url
Public zone URL.
callable $fileFactory
Override these in the base class.
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
getDescriptionStylesheetUrl()
Get the URL of the stylesheet to apply to description pages.
bool $transformVia404
Whether to skip media file transformation on parse and rely on a 404 handler instead.
getFileTimestamp( $virtualUrl)
Get the timestamp of a file with a given virtual URL/storage path.
bool $isPrivate
Whether all zones should be private (e.g.
string $scriptDirUrl
URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g.
string $descBaseUrl
URL of image description pages, e.g.
getZoneUrl( $zone, $ext=null)
Get the URL corresponding to one of the four basic zones.
getReadOnlyReason()
Get an explanatory message if this repo is read-only.
newFile( $title, $time=false)
Create a new File object from the local repository.
storeTemp( $originalName, $srcPath)
Pick a random name in the temp zone and store a file to it.
quickCleanDir( $dir)
Deletes a directory if empty.
canTransformVia404()
Returns true if the repository can transform files via a 404 handler.
enumFilesInStorage( $callback)
Call a callback function for every public file in the repository.
validateFilename( $filename)
Determine if a relative path is valid, i.e.
findFileFromKey( $sha1, $options=[])
Find an instance of the file with this key, created at the specified time Returns false if the file d...
int $deletedHashLevels
The number of directory levels for hash-based division of deleted files.
string $thumbScriptUrl
URL of thumb.php.
backendSupportsUnicodePaths()
__construct(array $info=null)
string false $thumbUrl
The base thumbnail URL.
bool $initialCapital
Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE], determines whether filenames impl...
getLocalCopy( $virtualUrl)
Get a local FS copy of a file with a given virtual URL/storage path.
deleteBatch(array $sourceDestPairs)
Move a group of files to the deletion archive.
getHashPath( $name)
Get a relative path including trailing slash, e.g.
callable false $oldFileFactory
Override these in the base class.
quickImport( $src, $dst, $options=null)
Import a file from the local file system into the repo.
string $articleUrl
Equivalent to $wgArticlePath, e.g.
getDescriptionRenderUrl( $name, $lang=null)
Get the URL of the content-only fragment of the description page.
freeTemp( $virtualUrl)
Remove a temporary file or mark it for garbage collection.
findBySha1( $hash)
Get an array or iterator of file objects for files that have a given SHA-1 content hash.
getBackend()
Get the file backend instance.
getInfo()
Return information about the repository.
getThumbScriptUrl()
Get the URL of thumb.php.
getLocalReference( $virtualUrl)
Get a local FS file with a given virtual URL/storage path.
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
MimeMagic helper wrapper.
static getInstance( $ts=false)
Get a timestamp instance in GMT.
A class containing constants representing the names of configuration variables.
static getMain()
Get the RequestContext object associated with the main request.
static newFatal( $message,... $parameters)
Factory function for fatal errors.
static newGood( $value=null)
Factory function for good results.
FileRepo for temporary files created by FileRepo::getTempRepo()
UploadStash is intended to accomplish a few things:
static newEmpty()
Get an instance that wraps EmptyBagOStuff.
Interface for objects (potentially) representing an editable wiki page.
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
if(!is_readable( $file)) $ext
if(!isset( $args[0])) $lang