16use Wikimedia\AtEase\AtEase;
135 protected $fileFactory = [ UnregisteredLocalFile::class,
'newFromTitle' ];
173 || !array_key_exists(
'name', $info )
174 || !array_key_exists(
'backend', $info )
177 " requires an array of options having both 'name' and 'backend' keys.\n" );
181 $this->name = $info[
'name'];
183 $this->backend = $info[
'backend'];
186 MediaWikiServices::getInstance()->getFileBackendGroup()->get( $info[
'backend'] );
190 $optionalSettings = [
191 'descBaseUrl',
'scriptDirUrl',
'articleUrl',
'fetchDescription',
192 'thumbScriptUrl',
'pathDisclosureProtection',
'descriptionCacheExpiry',
193 'favicon',
'thumbProxyUrl',
'thumbProxySecret',
'disableLocalTransform'
195 foreach ( $optionalSettings as $var ) {
196 if ( isset( $info[$var] ) ) {
197 $this->$var = $info[$var];
203 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized(
NS_FILE );
204 $this->initialCapital = $info[
'initialCapital'] ?? $localCapitalLinks;
205 if ( $localCapitalLinks && !$this->initialCapital ) {
213 throw new InvalidArgumentException(
214 'File repos with initial capital false are not allowed on wikis where the File ' .
215 'namespace has initial capital true' );
218 $this->url = $info[
'url'] ??
false;
219 $defaultThumbUrl = $this->url ? $this->url .
'/thumb' :
false;
220 $this->thumbUrl = $info[
'thumbUrl'] ?? $defaultThumbUrl;
221 $this->hashLevels = $info[
'hashLevels'] ?? 2;
223 $this->transformVia404 = !empty( $info[
'transformVia404'] );
224 $this->abbrvThreshold = $info[
'abbrvThreshold'] ?? 255;
225 $this->isPrivate = !empty( $info[
'isPrivate'] );
227 $this->zones = $info[
'zones'] ?? [];
228 foreach ( [
'public',
'thumb',
'transcoded',
'temp',
'deleted' ] as $zone ) {
229 if ( !isset( $this->zones[$zone][
'container'] ) ) {
230 $this->zones[$zone][
'container'] =
"{$this->name}-{$zone}";
232 if ( !isset( $this->zones[$zone][
'directory'] ) ) {
233 $this->zones[$zone][
'directory'] =
'';
235 if ( !isset( $this->zones[$zone][
'urlsByExt'] ) ) {
236 $this->zones[$zone][
'urlsByExt'] = [];
242 $this->wanCache = $info[
'wanCache'] ?? WANObjectCache::newEmpty();
261 return $this->backend->getReadOnlyReason();
271 foreach ( (array)$doZones as $zone ) {
273 if ( $root ===
null ) {
274 throw new MWException(
"No '$zone' zone defined in the {$this->name} repo." );
286 return substr( $url, 0, 9 ) ==
'mwrepo://';
298 $path =
'mwrepo://' . $this->name;
299 if ( $suffix !==
false ) {
300 $path .=
'/' . rawurlencode( $suffix );
314 if ( in_array( $zone, [
'public',
'thumb',
'transcoded' ] ) ) {
316 if (
$ext !==
null && isset( $this->zones[$zone][
'urlsByExt'][
$ext] ) ) {
319 return $this->zones[$zone][
'urlsByExt'][
$ext];
320 } elseif ( isset( $this->zones[$zone][
'url'] ) ) {
322 return $this->zones[$zone][
'url'];
332 return $this->thumbUrl;
334 return "{$this->url}/transcoded";
356 if ( substr( $url, 0, 9 ) !=
'mwrepo://' ) {
357 throw new MWException( __METHOD__ .
': unknown protocol' );
359 $bits = explode(
'/', substr( $url, 9 ), 3 );
360 if ( count( $bits ) != 3 ) {
361 throw new MWException( __METHOD__ .
": invalid mwrepo URL: $url" );
363 list( $repo, $zone, $rel ) = $bits;
364 if ( $repo !== $this->name ) {
365 throw new MWException( __METHOD__ .
": fetching from a foreign repo is not supported" );
367 $base = $this->getZonePath( $zone );
369 throw new MWException( __METHOD__ .
": invalid zone: $zone" );
372 return $base .
'/' . rawurldecode( $rel );
382 if ( !isset( $this->zones[$zone] ) ) {
383 return [
null, null ];
386 return [ $this->zones[$zone][
'container'], $this->zones[$zone][
'directory'] ];
396 list( $container,
$base ) = $this->getZoneLocation( $zone );
397 if ( $container ===
null ||
$base ===
null ) {
400 $backendName = $this->backend->getName();
405 return "mwstore://$backendName/{$container}{$base}";
425 if ( $this->oldFileFactory ) {
426 return call_user_func( $this->oldFileFactory,
$title, $this, $time );
431 return call_user_func( $this->fileFactory,
$title, $this );
455 if ( !empty( $options[
'private'] ) && !( $options[
'private'] instanceof
Authority ) ) {
456 throw new InvalidArgumentException(
457 __METHOD__ .
' called with the `private` option set to something ' .
458 'other than an Authority object'
466 if ( isset( $options[
'bypassCache'] ) ) {
467 $options[
'latest'] = $options[
'bypassCache'];
469 $time = $options[
'time'] ??
false;
470 $flags = !empty( $options[
'latest'] ) ? File::READ_LATEST : 0;
471 # First try the current version of the file to see if it precedes the timestamp
472 $img = $this->newFile(
$title );
476 $img->load( $flags );
477 if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
480 # Now try an old version of the file
481 if ( $time !==
false ) {
482 $img = $this->newFile(
$title, $time );
484 $img->load( $flags );
485 if ( $img->exists() ) {
486 if ( !$img->isDeleted( File::DELETED_FILE ) ) {
490 !empty( $options[
'private'] ) &&
491 $img->userCan( File::DELETED_FILE, $options[
'private'] )
500 if ( !empty( $options[
'ignoreRedirect'] ) ) {
503 $redir = $this->checkRedirect(
$title );
505 $img = $this->newFile( $redir );
509 $img->load( $flags );
510 if ( $img->exists() ) {
511 $img->redirectedFrom(
$title->getDBkey() );
539 foreach ( $items as $item ) {
540 if ( is_array( $item ) ) {
543 unset( $options[
'title'] );
546 !empty( $options[
'private'] ) &&
547 !( $options[
'private'] instanceof
Authority )
549 $options[
'private'] = RequestContext::getMain()->getAuthority();
557 $searchName = File::normalizeTitle(
$title )->getDBkey();
558 if ( $flags & self::NAME_AND_TIME_ONLY ) {
559 $result[$searchName] = [
560 'title' =>
$file->getTitle()->getDBkey(),
561 'timestamp' =>
$file->getTimestamp()
564 $result[$searchName] =
$file;
583 if ( !empty( $options[
'private'] ) && !( $options[
'private'] instanceof
Authority ) ) {
584 throw new InvalidArgumentException(
585 __METHOD__ .
' called with the `private` option set to something ' .
586 'other than an Authority object'
590 $time = $options[
'time'] ??
false;
591 # First try to find a matching current version of a file...
592 if ( !$this->fileFactoryKey ) {
595 $img = call_user_func( $this->fileFactoryKey, $sha1, $this, $time );
596 if ( $img && $img->exists() ) {
599 # Now try to find a matching old version of a file...
600 if ( $time !==
false && $this->oldFileFactoryKey ) {
601 $img = call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
602 if ( $img && $img->exists() ) {
603 if ( !$img->isDeleted( File::DELETED_FILE ) ) {
607 !empty( $options[
'private'] ) &&
608 $img->userCan( File::DELETED_FILE, $options[
'private'] )
640 $files = $this->findBySha1( $hash );
641 if ( count( $files ) ) {
642 $result[$hash] = $files;
667 return $this->thumbScriptUrl;
676 return $this->thumbProxyUrl;
685 return $this->thumbProxySecret;
694 return $this->transformVia404;
704 return !$this->disableLocalTransform;
715 $this->initialCapital !=
716 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized(
NS_FILE )
718 $name =
$title->getDBkey();
719 if ( $this->initialCapital ) {
720 $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
723 $name =
$title->getDBkey();
735 return $this->getZonePath(
'public' );
746 return self::getHashPathForLevel( $name, $this->hashLevels );
757 $parts = explode(
'!', $suffix, 2 );
758 $name = $parts[1] ?? $suffix;
759 return self::getHashPathForLevel( $name, $this->hashLevels );
768 if ( $levels == 0 ) {
771 $hash = md5( $name );
773 for ( $i = 1; $i <= $levels; $i++ ) {
774 $path .= substr( $hash, 0, $i ) .
'/';
787 return $this->hashLevels;
806 public function makeUrl( $query =
'', $entry =
'index' ) {
807 if ( isset( $this->scriptDirUrl ) ) {
808 return wfAppendQuery(
"{$this->scriptDirUrl}/{$entry}.php", $query );
828 if ( $this->descBaseUrl !==
null ) {
829 # "http://example.com/wiki/File:"
830 return $this->descBaseUrl . $encName;
832 if ( $this->articleUrl !==
null ) {
833 # "http://example.com/wiki/$1"
834 # We use "Image:" as the canonical namespace for
835 # compatibility across all MediaWiki versions.
836 return str_replace(
'$1',
837 "Image:$encName", $this->articleUrl );
839 if ( $this->scriptDirUrl !==
null ) {
840 # "http://example.com/w"
841 # We use "Image:" as the canonical namespace for
842 # compatibility across all MediaWiki versions,
843 # and just sort of hope index.php is right. ;)
844 return $this->makeUrl(
"title=Image:$encName" );
861 $query =
'action=render';
862 if (
$lang !==
null ) {
863 $query .=
'&uselang=' . urlencode(
$lang );
865 if ( isset( $this->scriptDirUrl ) ) {
866 return $this->makeUrl(
871 $descUrl = $this->getDescriptionUrl( $name );
886 if ( isset( $this->scriptDirUrl ) ) {
889 return $this->makeUrl(
'title=MediaWiki:Filepage.css&action=raw&ctype=text/css' );
912 public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
913 $this->assertWritableRepo();
915 $status = $this->storeBatch( [ [ $srcPath, $dstZone, $dstRel ] ], $flags );
916 if ( $status->successCount == 0 ) {
917 $status->setOK(
false );
938 $this->assertWritableRepo();
940 if ( $flags & self::DELETE_SOURCE ) {
941 throw new InvalidArgumentException(
"DELETE_SOURCE not supported in " . __METHOD__ );
944 $status = $this->newGood();
945 $backend = $this->backend;
949 foreach ( $triplets as $triplet ) {
950 list( $src, $dstZone, $dstRel ) = $triplet;
951 $srcPath = ( $src instanceof
FSFile ) ? $src->getPath() : $src;
953 .
"( \$src='$srcPath', \$dstZone='$dstZone', \$dstRel='$dstRel' )"
956 if ( $src instanceof
FSFile ) {
959 $src = $this->resolveToStoragePathIfVirtual( $src );
963 $root = $this->getZonePath( $dstZone );
967 if ( !$this->validateFilename( $dstRel ) ) {
968 throw new MWException(
'Validation error in $dstRel' );
970 $dstPath =
"$root/$dstRel";
971 $dstDir = dirname( $dstPath );
973 if ( !$this->initDirectory( $dstDir )->isOK() ) {
974 return $this->newFatal(
'directorycreateerror', $dstDir );
982 'overwrite' => ( $flags & self::OVERWRITE ) ?
true :
false,
983 'overwriteSame' => ( $flags & self::OVERWRITE_SAME ) ?
true :
false,
988 $opts = [
'force' =>
true ];
989 if ( $flags & self::SKIP_LOCKING ) {
990 $opts[
'nonLocking'] =
true;
993 return $status->merge( $backend->doOperations( $operations, $opts ) );
1007 $this->assertWritableRepo();
1009 $status = $this->newGood();
1012 foreach ( $files as
$path ) {
1013 if ( is_array(
$path ) ) {
1015 list( $zone, $rel ) =
$path;
1016 $path = $this->getZonePath( $zone ) .
"/$rel";
1019 $path = $this->resolveToStoragePathIfVirtual(
$path );
1021 $operations[] = [
'op' =>
'delete',
'src' =>
$path ];
1024 $opts = [
'force' =>
true ];
1025 if ( $flags & self::SKIP_LOCKING ) {
1026 $opts[
'nonLocking'] =
true;
1029 return $status->merge( $this->backend->doOperations( $operations, $opts ) );
1050 return $this->quickImportBatch( [ [ $src, $dst, $options ] ] );
1068 $status = $this->newGood();
1070 foreach ( $triples as $triple ) {
1071 list( $src, $dst ) = $triple;
1072 if ( $src instanceof
FSFile ) {
1075 $src = $this->resolveToStoragePathIfVirtual( $src );
1078 $dst = $this->resolveToStoragePathIfVirtual( $dst );
1080 if ( !isset( $triple[2] ) ) {
1082 } elseif ( is_string( $triple[2] ) ) {
1084 $headers = [
'Content-Disposition' => $triple[2] ];
1085 } elseif ( is_array( $triple[2] ) && isset( $triple[2][
'headers'] ) ) {
1086 $headers = $triple[2][
'headers'];
1095 'headers' => $headers
1097 $status->merge( $this->initDirectory( dirname( $dst ) ) );
1100 return $status->merge( $this->backend->doQuickOperations( $operations ) );
1112 return $this->quickPurgeBatch( [
$path ] );
1123 return $this->newGood()->merge(
1124 $this->backend->clean(
1125 [
'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ]
1139 $status = $this->newGood();
1141 foreach ( $paths as
$path ) {
1144 'src' => $this->resolveToStoragePathIfVirtual(
$path ),
1145 'ignoreMissingSource' =>
true
1148 $status->merge( $this->backend->doQuickOperations( $operations ) );
1164 $this->assertWritableRepo();
1166 $date = MWTimestamp::getInstance()->format(
'YmdHis' );
1167 $hashPath = $this->getHashPath( $originalName );
1168 $dstUrlRel = $hashPath . $date .
'!' . rawurlencode( $originalName );
1169 $virtualUrl = $this->getVirtualUrl(
'temp' ) .
'/' . $dstUrlRel;
1171 $result = $this->quickImport( $srcPath, $virtualUrl );
1172 $result->value = $virtualUrl;
1184 $this->assertWritableRepo();
1186 $temp = $this->getVirtualUrl(
'temp' );
1187 if ( !str_starts_with( $virtualUrl, $temp ) ) {
1188 wfDebug( __METHOD__ .
": Invalid temp virtual URL" );
1193 return $this->quickPurge( $virtualUrl )->isOK();
1205 public function concatenate( array $srcPaths, $dstPath, $flags = 0 ) {
1206 $this->assertWritableRepo();
1208 $status = $this->newGood();
1211 foreach ( $srcPaths as $srcPath ) {
1213 $source = $this->resolveToStoragePathIfVirtual( $srcPath );
1218 $params = [
'srcs' => $sources,
'dst' => $dstPath ];
1219 $status->merge( $this->backend->concatenate( $params ) );
1220 if ( !$status->isOK() ) {
1225 if ( $flags & self::DELETE_SOURCE ) {
1226 $status->merge( $this->quickPurgeBatch( $srcPaths ) );
1230 $status->setResult(
true );
1259 $src, $dstRel, $archiveRel, $flags = 0, array $options = []
1261 $this->assertWritableRepo();
1263 $status = $this->publishBatch(
1264 [ [ $src, $dstRel, $archiveRel, $options ] ], $flags );
1265 if ( $status->successCount == 0 ) {
1266 $status->setOK(
false );
1268 $status->value = $status->value[0] ??
false;
1286 $this->assertWritableRepo();
1288 $backend = $this->backend;
1290 $this->initZones(
'public' );
1292 $status = $this->newGood( [] );
1295 $sourceFSFilesToDelete = [];
1297 foreach ( $ntuples as $ntuple ) {
1298 list( $src, $dstRel, $archiveRel ) = $ntuple;
1299 $srcPath = ( $src instanceof
FSFile ) ? $src->getPath() : $src;
1301 $options = $ntuple[3] ?? [];
1303 $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
1304 if ( !$this->validateFilename( $dstRel ) ) {
1305 throw new MWException(
'Validation error in $dstRel' );
1307 if ( !$this->validateFilename( $archiveRel ) ) {
1308 throw new MWException(
'Validation error in $archiveRel' );
1311 $publicRoot = $this->getZonePath(
'public' );
1312 $dstPath =
"$publicRoot/$dstRel";
1313 $archivePath =
"$publicRoot/$archiveRel";
1315 $dstDir = dirname( $dstPath );
1316 $archiveDir = dirname( $archivePath );
1318 if ( !$this->initDirectory( $dstDir )->isOK() ) {
1319 return $this->newFatal(
'directorycreateerror', $dstDir );
1321 if ( !$this->initDirectory( $archiveDir )->isOK() ) {
1322 return $this->newFatal(
'directorycreateerror', $archiveDir );
1326 $headers = $options[
'headers'] ?? [];
1337 'dst' => $archivePath,
1338 'ignoreMissingSource' =>
true
1344 'op' => ( $flags & self::DELETE_SOURCE ) ?
'move' :
'copy',
1347 'overwrite' =>
true,
1348 'headers' => $headers
1355 'overwrite' =>
true,
1356 'headers' => $headers
1358 if ( $flags & self::DELETE_SOURCE ) {
1359 $sourceFSFilesToDelete[] = $srcPath;
1365 $status->merge( $backend->doOperations( $operations ) );
1367 foreach ( $ntuples as $i => $ntuple ) {
1368 list( , , $archiveRel ) = $ntuple;
1369 $archivePath = $this->getZonePath(
'public' ) .
"/$archiveRel";
1370 if ( $this->fileExists( $archivePath ) ) {
1371 $status->value[$i] =
'archived';
1373 $status->value[$i] =
'new';
1377 foreach ( $sourceFSFilesToDelete as
$file ) {
1378 AtEase::suppressWarnings();
1380 AtEase::restoreWarnings();
1394 $path = $this->resolveToStoragePathIfVirtual( $dir );
1397 $params = [
'dir' =>
$path ];
1398 if ( $this->isPrivate
1399 || $container === $this->zones[
'deleted'][
'container']
1400 || $container === $this->zones[
'temp'][
'container']
1402 # Take all available measures to prevent web accessibility of new deleted
1403 # directories, in case the user has not configured offline storage
1404 $params = [
'noAccess' =>
true,
'noListing' =>
true ] + $params;
1407 return $this->newGood()->merge( $this->backend->prepare( $params ) );
1417 $this->assertWritableRepo();
1419 return $this->newGood()->merge(
1420 $this->backend->clean(
1421 [
'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ]
1433 $result = $this->fileExistsBatch( [
$file ] );
1446 $paths = array_map( [ $this,
'resolveToStoragePathIfVirtual' ], $files );
1447 $this->backend->preloadFileStat( [
'srcs' => $paths ] );
1450 foreach ( $files as $key =>
$file ) {
1451 $path = $this->resolveToStoragePathIfVirtual(
$file );
1452 $result[$key] = $this->backend->fileExists( [
'src' =>
$path ] );
1468 public function delete( $srcRel, $archiveRel ) {
1469 $this->assertWritableRepo();
1471 return $this->deleteBatch( [ [ $srcRel, $archiveRel ] ] );
1492 $this->assertWritableRepo();
1495 $this->initZones( [
'public',
'deleted' ] );
1497 $status = $this->newGood();
1499 $backend = $this->backend;
1502 foreach ( $sourceDestPairs as [ $srcRel, $archiveRel ] ) {
1503 if ( !$this->validateFilename( $srcRel ) ) {
1504 throw new MWException( __METHOD__ .
':Validation error in $srcRel' );
1505 } elseif ( !$this->validateFilename( $archiveRel ) ) {
1506 throw new MWException( __METHOD__ .
':Validation error in $archiveRel' );
1509 $publicRoot = $this->getZonePath(
'public' );
1510 $srcPath =
"{$publicRoot}/$srcRel";
1512 $deletedRoot = $this->getZonePath(
'deleted' );
1513 $archivePath =
"{$deletedRoot}/{$archiveRel}";
1514 $archiveDir = dirname( $archivePath );
1517 if ( !$this->initDirectory( $archiveDir )->isGood() ) {
1518 return $this->newFatal(
'directorycreateerror', $archiveDir );
1524 'dst' => $archivePath,
1527 'overwriteSame' =>
true
1534 $opts = [
'force' =>
true ];
1535 return $status->merge( $backend->doOperations( $operations, $opts ) );
1545 $this->assertWritableRepo();
1557 if ( strlen( $key ) < 31 ) {
1558 throw new MWException(
"Invalid storage key '$key'." );
1561 for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) {
1562 $path .= $key[$i] .
'/';
1577 if ( self::isVirtualUrl(
$path ) ) {
1578 return $this->resolveVirtualUrl(
$path );
1592 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1594 return $this->backend->getLocalCopy( [
'src' =>
$path ] );
1606 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1608 return $this->backend->getLocalReference( [
'src' =>
$path ] );
1619 $fsFile = $this->getLocalReference( $virtualUrl );
1620 $mwProps =
new MWFileProps( MediaWikiServices::getInstance()->getMimeAnalyzer() );
1622 $props = $mwProps->getPropsFromPath( $fsFile->getPath(),
true );
1624 $props = $mwProps->newPlaceholderProps();
1637 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1639 return $this->backend->getFileTimestamp( [
'src' =>
$path ] );
1649 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1651 return $this->backend->getFileSize( [
'src' =>
$path ] );
1661 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1663 return $this->backend->getFileSha1Base36( [
'src' =>
$path ] );
1676 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1677 $params = [
'src' =>
$path,
'headers' => $headers,
'options' => $optHeaders ];
1680 ob_start(
null, 1048576 );
1681 ob_implicit_flush(
true );
1683 $status = $this->newGood()->merge( $this->backend->streamFile( $params ) );
1687 if ( ob_get_status() ) {
1703 $this->enumFilesInStorage( $callback );
1714 $publicRoot = $this->getZonePath(
'public' );
1715 $numDirs = 1 << ( $this->hashLevels * 4 );
1718 for ( $flatIndex = 0; $flatIndex < $numDirs; $flatIndex++ ) {
1719 $hexString = sprintf(
"%0{$this->hashLevels}x", $flatIndex );
1720 $path = $publicRoot;
1721 for ( $hexPos = 0; $hexPos < $this->hashLevels; $hexPos++ ) {
1722 $path .=
'/' . substr( $hexString, 0, $hexPos + 1 );
1724 $iterator = $this->backend->getFileList( [
'dir' =>
$path ] );
1725 if ( $iterator ===
null ) {
1726 throw new MWException( __METHOD__ .
': could not get file listing for ' .
$path );
1728 foreach ( $iterator as $name ) {
1730 call_user_func( $callback,
"{$path}/{$name}" );
1742 if ( strval( $filename ) ==
'' ) {
1754 private function getErrorCleanupFunction() {
1755 switch ( $this->pathDisclosureProtection ) {
1758 $callback = [ $this,
'passThrough' ];
1761 $callback = [ $this,
'paranoidClean' ];
1794 $status = Status::newFatal( $message, ...$parameters );
1795 $status->cleanCallback = $this->getErrorCleanupFunction();
1807 $status = Status::newGood( $value );
1808 $status->cleanCallback = $this->getErrorCleanupFunction();
1841 $sitename = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Sitename );
1843 if ( $this->isLocal() ) {
1848 return wfMessageFallback(
'shared-repo-name-' . $this->name,
'shared-repo' )->text();
1859 if ( strlen( $name ) > $this->abbrvThreshold ) {
1861 $name = (
$ext ==
'' ) ?
'thumbnail' :
"thumbnail.$ext";
1873 return $this->getName() ==
'local';
1903 return $this->wanCache->makeKey(
1904 'filerepo-' . $kClassSuffix,
1920 'name' =>
"{$this->name}-temp",
1921 'backend' => $this->backend,
1926 'container' => $this->zones[
'temp'][
'container'],
1927 'directory' => $this->zones[
'temp'][
'directory']
1930 'container' => $this->zones[
'temp'][
'container'],
1931 'directory' => $this->zones[
'temp'][
'directory'] ==
''
1933 : $this->zones[
'temp'][
'directory'] .
'/thumb'
1936 'container' => $this->zones[
'temp'][
'container'],
1937 'directory' => $this->zones[
'temp'][
'directory'] ==
''
1939 : $this->zones[
'temp'][
'directory'] .
'/transcoded'
1942 '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 ) ) {
2009 return $this->hasSha1Storage;
2017 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,...
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
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.
MimeMagic helper wrapper.
A class containing constants representing the names of configuration variables.
FileRepo for temporary files created by FileRepo::getTempRepo()
UploadStash is intended to accomplish a few things:
Multi-datacenter aware caching interface.
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