Go to the documentation of this file.
57 parent::__construct( $info );
60 $this->hasAccessibleSharedCache =
true;
62 $this->
hasSha1Storage = ( $info[
'storageLayout'] ?? null ) ===
'sha1';
66 'backend' => $this->backend,
67 'repoName' => $this->name,
79 if ( isset( $row->img_name ) ) {
80 return call_user_func( $this->fileFromRowFactory, $row, $this );
81 } elseif ( isset( $row->oi_name ) ) {
82 return call_user_func( $this->oldFileFromRowFactory, $row, $this );
84 throw new MWException( __METHOD__ .
': invalid row' );
109 wfDebug( __METHOD__ .
": skipped because storage uses sha1 paths" );
117 $storageKeys = array_unique( $storageKeys );
118 foreach ( $storageKeys as $key ) {
120 $path =
"$root/$hashPath$key";
121 $dbw->startAtomic( __METHOD__ );
126 if ( !$deleted && !$hidden ) {
127 wfDebug( __METHOD__ .
": deleting $key" );
128 $op = [
'op' =>
'delete',
'src' =>
$path ];
130 $status->error(
'undelete-cleanup-error',
$path );
131 $status->failCount++;
134 wfDebug( __METHOD__ .
": $key still in use" );
135 $status->successCount++;
137 $dbw->endAtomic( __METHOD__ );
151 $options = ( $lock ===
'lock' ) ? [
'FOR UPDATE' ] : [];
155 return (
bool)$dbw->selectField(
'filearchive',
'1',
156 [
'fa_storage_group' =>
'deleted',
'fa_storage_key' => $key ],
169 $options = ( $lock ===
'lock' ) ? [
'FOR UPDATE' ] : [];
176 return (
bool)$dbw->selectField(
'oldimage',
'1',
177 [
'oi_sha1' => $sha1,
178 'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(),
".$ext" ),
191 $sha1 = strtok( $key,
'.' );
192 if ( is_string( $sha1 ) && strlen( $sha1 ) === 32 && $sha1[0] ===
'0' ) {
193 $sha1 = substr( $sha1, 1 );
208 if ( $memcKey ===
false ) {
215 $method = __METHOD__;
216 $redirDbKey = $this->wanCache->getWithSetCallback(
219 function ( $oldValue, &$ttl, array &$setOpts ) use ( $method,
$title ) {
222 $setOpts += Database::getCacheSetOptions(
$dbr );
224 $row =
$dbr->selectRow(
225 [
'page',
'redirect' ],
226 [
'rd_namespace',
'rd_title' ],
228 'page_namespace' =>
$title->getNamespace(),
229 'page_title' =>
$title->getDBkey(),
235 return ( $row && $row->rd_namespace ==
NS_FILE )
239 [
'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
243 if ( $redirDbKey !==
' ' && strval( $redirDbKey ) !==
'' ) {
255 foreach ( $items as $item ) {
256 if ( is_array( $item ) ) {
259 $searchSet[
$title->getDBkey()] = $item;
264 $searchSet[
$title->getDBkey()] = [];
269 $fileMatchesSearch =
function (
File $file, array $search ) {
276 $user = ( !empty( $search[
'private'] ) && $search[
'private'] instanceof
User )
283 ( empty( $search[
'time'] ) && !
$file->isOld() ) ||
284 ( !empty( $search[
'time'] ) && $search[
'time'] ===
$file->getTimestamp() )
292 use ( $fileMatchesSearch, $flags )
294 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
296 foreach ( $res as $row ) {
300 $dbKeysLook = [ strtr(
$file->getName(),
' ',
'_' ) ];
301 if ( !empty( $info[
'initialCapital'] ) ) {
303 $dbKeysLook[] = $contLang->lcfirst(
$file->getName() );
305 foreach ( $dbKeysLook as $dbKey ) {
306 if ( isset( $searchSet[$dbKey] )
307 && $fileMatchesSearch(
$file, $searchSet[$dbKey] )
310 ? [
'title' => $dbKey,
'timestamp' =>
$file->getTimestamp() ]
312 unset( $searchSet[$dbKey] );
322 foreach ( array_keys( $searchSet ) as $dbKey ) {
326 if ( count( $imgNames ) ) {
328 $res =
$dbr->select( $fileQuery[
'tables'], $fileQuery[
'fields'], [
'img_name' => $imgNames ],
329 __METHOD__, [], $fileQuery[
'joins'] );
330 $applyMatchingFiles(
$res, $searchSet, $finalFiles );
335 foreach ( $searchSet as $dbKey => $search ) {
336 if ( isset( $search[
'time'] ) ) {
337 $oiConds[] =
$dbr->makeList(
340 'oi_timestamp' =>
$dbr->timestamp( $search[
'time'] )
347 if ( count( $oiConds ) ) {
349 $res =
$dbr->select( $fileQuery[
'tables'], $fileQuery[
'fields'],
351 __METHOD__, [], $fileQuery[
'joins'] );
352 $applyMatchingFiles(
$res, $searchSet, $finalFiles );
356 foreach ( $searchSet as $dbKey => $search ) {
357 if ( !empty( $search[
'ignoreRedirect'] ) ) {
364 if ( $redir && $redir->getNamespace() ===
NS_FILE ) {
366 if (
$file && $fileMatchesSearch(
$file, $search ) ) {
369 $finalFiles[$dbKey] = [
370 'title' =>
$file->getTitle()->getDBkey(),
371 'timestamp' =>
$file->getTimestamp()
374 $finalFiles[$dbKey] =
$file;
394 $fileQuery[
'tables'],
395 $fileQuery[
'fields'],
396 [
'img_sha1' => $hash ],
398 [
'ORDER BY' =>
'img_name' ],
403 foreach (
$res as $row ) {
428 $fileQuery[
'tables'],
429 $fileQuery[
'fields'],
432 [
'ORDER BY' =>
'img_name' ],
437 foreach (
$res as $row ) {
454 $selectOptions = [
'ORDER BY' =>
'img_name',
'LIMIT' => intval( $limit ) ];
460 $fileQuery[
'tables'],
461 $fileQuery[
'fields'],
462 'img_name ' .
$dbr->buildLike( $prefix,
$dbr->anyString() ),
470 foreach (
$res as $row ) {
498 return function ( $index ) {
516 ? $this->wanCache->makeGlobalKey(
517 'filerepo-' . $kClassSuffix,
533 $this->
getMasterDB()->onTransactionPreCommitOrIdle(
534 function () use ( $key ) {
535 $this->wanCache->delete( $key );
551 return array_merge( parent::getInfo(), [
556 public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
582 public function delete( $srcRel, $archiveRel ) {
601 wfDebug( __METHOD__ .
": skipped because storage uses sha1 paths" );
604 return parent::$function( ...
$args );
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
getInfo()
Return information about the repository.
static getCurrentWikiDbDomain()
newGood( $value=null)
Create a new good result.
getMasterDB()
Get a connection to the master DB.
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
getReplicaDB()
Get a connection to the replica DB.
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...
deletedFileHasKey( $key, $lock=null)
Check if a deleted (filearchive) file has this sha1 key.
getSharedCacheKey( $kClassSuffix,... $components)
Get a global, repository-qualified, WAN cache key.
callable $oldFileFactoryKey
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
hiddenFileHasKey( $key, $lock=null)
Check if a hidden (revision delete) file has this sha1 key.
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
Base class for file repositories.
hasSha1Storage()
Returns whether or not storage is SHA-1 based.
Implements some public methods and some protected utility functions which are required by multiple ch...
callable $oldFileFromRowFactory
newFile( $title, $time=false)
Create a new File object from the local repository.
doOperation(array $op, array $opts=[])
Same as doOperations() except it takes a single operation.
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms,...
store( $srcPath, $dstZone, $dstRel, $flags=0)
Store a file to a given destination.
getDBFactory()
Get a callback to get a DB handle given an index (DB_REPLICA/DB_MASTER)
invalidateImageRedirect(Title $title)
Invalidates image redirect cache related to that image.
storeBatch(array $triplets, $flags=0)
Store a batch of files.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
cleanupBatch(array $files, $flags=0)
Deletes a batch of files.
findFiles(array $items, $flags=0)
Find many files at once.
getNameFromTitle(Title $title)
Get the name of a file from its title object.
getLocalCacheKey( $kClassSuffix,... $components)
Get a site-local, repository-qualified, WAN cache key.
newFromArchiveName( $title, $archiveName)
static newGood( $value=null)
Factory function for good results.
bool $hasAccessibleSharedCache
Whether shared cache keys are exposed/accessible.
findBySha1s(array $hashes)
Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashe...
static getMain()
Get the RequestContext object associated with the main request.
$wgFavicon
The URL path of the shortcut icon.
findFilesByPrefix( $prefix, $limit)
Return an array of files where the name starts with $prefix.
checkRedirect(Title $title)
Checks if there is a redirect named as $title.
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Represents a title within MediaWiki.
cleanupDeletedBatch(array $storageKeys)
Delete files in the deleted directory if they are not referenced in the filearchive table.
deleteBatch(array $sourceDestPairs)
Move a group of files to the deletion archive.
findBySha1( $hash)
Get an array or iterator of file objects for files that have a given SHA-1 content hash.
if(!is_readable( $file)) $ext
skipWriteOperationIfSha1( $function, array $args)
Skips the write operation if storage is sha1-based, executes it normally otherwise.
__construct(array $info=null)
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
hasAcessibleSharedCache()
Check whether the repo has a shared cache, accessible from the current site context.
static newFromArchiveName( $title, $repo, $archiveName)
Stable to override.
publishBatch(array $ntuples, $flags=0)
Publish a batch of files.
getDeletedHashPath( $key)
Get a relative path for a deletion archive key, e.g.
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Proxy backend that manages file layout rewriting for FileRepo.
A repository that stores files in the local filesystem and registers them in the wiki's own database.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
string $dbDomain
DB domain of the repo wiki.
callable $fileFromRowFactory