MediaWiki  master
LocalRepo.php
Go to the documentation of this file.
1 <?php
33 
41 class LocalRepo extends FileRepo {
43  protected $fileFactory = [ LocalFile::class, 'newFromTitle' ];
45  protected $fileFactoryKey = [ LocalFile::class, 'newFromKey' ];
47  protected $fileFromRowFactory = [ LocalFile::class, 'newFromRow' ];
49  protected $oldFileFromRowFactory = [ OldLocalFile::class, 'newFromRow' ];
51  protected $oldFileFactory = [ OldLocalFile::class, 'newFromTitle' ];
53  protected $oldFileFactoryKey = [ OldLocalFile::class, 'newFromKey' ];
54 
56  protected $dbDomain;
59 
61  protected $blobStore;
62 
64  protected $useJsonMetadata = false;
65 
67  protected $useSplitMetadata = false;
68 
70  protected $splitMetadataThreshold = 1000;
71 
73  protected $updateCompatibleMetadata = false;
74 
76  protected $reserializeMetadata = false;
77 
78  public function __construct( array $info = null ) {
79  parent::__construct( $info );
80 
81  $this->dbDomain = WikiMap::getCurrentWikiDbDomain();
82  $this->hasAccessibleSharedCache = true;
83 
84  $this->hasSha1Storage = ( $info['storageLayout'] ?? null ) === 'sha1';
85 
86  if ( $this->hasSha1Storage() ) {
87  $this->backend = new FileBackendDBRepoWrapper( [
88  'backend' => $this->backend,
89  'repoName' => $this->name,
90  'dbHandleFactory' => $this->getDBFactory()
91  ] );
92  }
93 
94  foreach (
95  [
96  'useJsonMetadata',
97  'useSplitMetadata',
98  'splitMetadataThreshold',
99  'updateCompatibleMetadata',
100  'reserializeMetadata',
101  ] as $option
102  ) {
103  if ( isset( $info[$option] ) ) {
104  $this->$option = $info[$option];
105  }
106  }
107  }
108 
114  public function newFileFromRow( $row ) {
115  if ( isset( $row->img_name ) ) {
116  return call_user_func( $this->fileFromRowFactory, $row, $this );
117  } elseif ( isset( $row->oi_name ) ) {
118  return call_user_func( $this->oldFileFromRowFactory, $row, $this );
119  } else {
120  throw new MWException( __METHOD__ . ': invalid row' );
121  }
122  }
123 
129  public function newFromArchiveName( $title, $archiveName ) {
131  return OldLocalFile::newFromArchiveName( $title, $this, $archiveName );
132  }
133 
144  public function cleanupDeletedBatch( array $storageKeys ) {
145  if ( $this->hasSha1Storage() ) {
146  wfDebug( __METHOD__ . ": skipped because storage uses sha1 paths" );
147  return Status::newGood();
148  }
149 
150  $backend = $this->backend; // convenience
151  $root = $this->getZonePath( 'deleted' );
152  $dbw = $this->getPrimaryDB();
153  $status = $this->newGood();
154  $storageKeys = array_unique( $storageKeys );
155  foreach ( $storageKeys as $key ) {
156  $hashPath = $this->getDeletedHashPath( $key );
157  $path = "$root/$hashPath$key";
158  $dbw->startAtomic( __METHOD__ );
159  // Check for usage in deleted/hidden files and preemptively
160  // lock the key to avoid any future use until we are finished.
161  $deleted = $this->deletedFileHasKey( $key, 'lock' );
162  $hidden = $this->hiddenFileHasKey( $key, 'lock' );
163  if ( !$deleted && !$hidden ) { // not in use now
164  wfDebug( __METHOD__ . ": deleting $key" );
165  $op = [ 'op' => 'delete', 'src' => $path ];
166  if ( !$backend->doOperation( $op )->isOK() ) {
167  $status->error( 'undelete-cleanup-error', $path );
168  $status->failCount++;
169  }
170  } else {
171  wfDebug( __METHOD__ . ": $key still in use" );
172  $status->successCount++;
173  }
174  $dbw->endAtomic( __METHOD__ );
175  }
176 
177  return $status;
178  }
179 
187  protected function deletedFileHasKey( $key, $lock = null ) {
188  $dbw = $this->getPrimaryDB();
189  return (bool)$dbw->selectField( 'filearchive', '1',
190  [ 'fa_storage_group' => 'deleted', 'fa_storage_key' => $key ],
191  __METHOD__,
192  $lock === 'lock' ? [ 'FOR UPDATE' ] : []
193  );
194  }
195 
203  protected function hiddenFileHasKey( $key, $lock = null ) {
204  $sha1 = self::getHashFromKey( $key );
205  $ext = File::normalizeExtension( substr( $key, strcspn( $key, '.' ) + 1 ) );
206 
207  $dbw = $this->getPrimaryDB();
208  return (bool)$dbw->selectField( 'oldimage', '1',
209  [
210  'oi_sha1' => $sha1,
211  'oi_archive_name ' . $dbw->buildLike( $dbw->anyString(), ".$ext" ),
212  $dbw->bitAnd( 'oi_deleted', File::DELETED_FILE ) => File::DELETED_FILE,
213  ],
214  __METHOD__,
215  $lock === 'lock' ? [ 'FOR UPDATE' ] : []
216  );
217  }
218 
225  public static function getHashFromKey( $key ) {
226  $sha1 = strtok( $key, '.' );
227  if ( is_string( $sha1 ) && strlen( $sha1 ) === 32 && $sha1[0] === '0' ) {
228  $sha1 = substr( $sha1, 1 );
229  }
230  return $sha1;
231  }
232 
239  public function checkRedirect( $title ) {
240  $title = File::normalizeTitle( $title, 'exception' );
241 
242  $memcKey = $this->getSharedCacheKey( 'file-redirect', md5( $title->getDBkey() ) );
243  if ( $memcKey === false ) {
244  $memcKey = $this->getLocalCacheKey( 'file-redirect', md5( $title->getDBkey() ) );
245  $expiry = 300; // no invalidation, 5 minutes
246  } else {
247  $expiry = 86400; // has invalidation, 1 day
248  }
249 
250  $method = __METHOD__;
251  $redirDbKey = $this->wanCache->getWithSetCallback(
252  $memcKey,
253  $expiry,
254  function ( $oldValue, &$ttl, array &$setOpts ) use ( $method, $title ) {
255  $dbr = $this->getReplicaDB(); // possibly remote DB
256 
257  $setOpts += Database::getCacheSetOptions( $dbr );
258 
259  $row = $dbr->selectRow(
260  [ 'page', 'redirect' ],
261  [ 'rd_namespace', 'rd_title' ],
262  [
263  'page_namespace' => $title->getNamespace(),
264  'page_title' => $title->getDBkey(),
265  'rd_from = page_id'
266  ],
267  $method
268  );
269 
270  return ( $row && $row->rd_namespace == NS_FILE )
271  ? Title::makeTitle( $row->rd_namespace, $row->rd_title )->getDBkey()
272  : ''; // negative cache
273  },
274  [ 'pcTTL' => WANObjectCache::TTL_PROC_LONG ]
275  );
276 
277  // @note: also checks " " for b/c
278  if ( $redirDbKey !== ' ' && strval( $redirDbKey ) !== '' ) {
279  // Page is a redirect to another file
280  return Title::newFromText( $redirDbKey, NS_FILE );
281  }
282 
283  return false; // no redirect
284  }
285 
286  public function findFiles( array $items, $flags = 0 ) {
287  $finalFiles = []; // map of (DB key => corresponding File) for matches
288 
289  $searchSet = []; // map of (normalized DB key => search params)
290  foreach ( $items as $item ) {
291  if ( is_array( $item ) ) {
292  $title = File::normalizeTitle( $item['title'] );
293  if ( $title ) {
294  $searchSet[$title->getDBkey()] = $item;
295  }
296  } else {
297  $title = File::normalizeTitle( $item );
298  if ( $title ) {
299  $searchSet[$title->getDBkey()] = [];
300  }
301  }
302  }
303 
304  $fileMatchesSearch = static function ( File $file, array $search ) {
305  // Note: file name comparison done elsewhere (to handle redirects)
306 
307  // Fallback to RequestContext::getMain should be replaced with a better
308  // way of setting the user that should be used; currently it needs to be
309  // set for each file individually. See T263033#6477586
310  $contextPerformer = RequestContext::getMain()->getAuthority();
311  $performer = ( !empty( $search['private'] ) && $search['private'] instanceof Authority )
312  ? $search['private']
313  : $contextPerformer;
314 
315  return (
316  $file->exists() &&
317  (
318  ( empty( $search['time'] ) && !$file->isOld() ) ||
319  ( !empty( $search['time'] ) && $search['time'] === $file->getTimestamp() )
320  ) &&
321  ( !empty( $search['private'] ) || !$file->isDeleted( File::DELETED_FILE ) ) &&
322  $file->userCan( File::DELETED_FILE, $performer )
323  );
324  };
325 
326  $applyMatchingFiles = function ( IResultWrapper $res, &$searchSet, &$finalFiles )
327  use ( $fileMatchesSearch, $flags )
328  {
329  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
330  $info = $this->getInfo();
331  foreach ( $res as $row ) {
332  $file = $this->newFileFromRow( $row );
333  // There must have been a search for this DB key, but this has to handle the
334  // cases were title capitalization is different on the client and repo wikis.
335  $dbKeysLook = [ strtr( $file->getName(), ' ', '_' ) ];
336  if ( !empty( $info['initialCapital'] ) ) {
337  // Search keys for "hi.png" and "Hi.png" should use the "Hi.png file"
338  $dbKeysLook[] = $contLang->lcfirst( $file->getName() );
339  }
340  foreach ( $dbKeysLook as $dbKey ) {
341  if ( isset( $searchSet[$dbKey] )
342  && $fileMatchesSearch( $file, $searchSet[$dbKey] )
343  ) {
344  $finalFiles[$dbKey] = ( $flags & FileRepo::NAME_AND_TIME_ONLY )
345  ? [ 'title' => $dbKey, 'timestamp' => $file->getTimestamp() ]
346  : $file;
347  unset( $searchSet[$dbKey] );
348  }
349  }
350  }
351  };
352 
353  $dbr = $this->getReplicaDB();
354 
355  // Query image table
356  $imgNames = [];
357  foreach ( array_keys( $searchSet ) as $dbKey ) {
358  $imgNames[] = $this->getNameFromTitle( File::normalizeTitle( $dbKey ) );
359  }
360 
361  if ( count( $imgNames ) ) {
362  $fileQuery = LocalFile::getQueryInfo();
363  $res = $dbr->select( $fileQuery['tables'], $fileQuery['fields'], [ 'img_name' => $imgNames ],
364  __METHOD__, [], $fileQuery['joins'] );
365  $applyMatchingFiles( $res, $searchSet, $finalFiles );
366  }
367 
368  // Query old image table
369  $oiConds = []; // WHERE clause array for each file
370  foreach ( $searchSet as $dbKey => $search ) {
371  if ( isset( $search['time'] ) ) {
372  $oiConds[] = $dbr->makeList(
373  [
374  'oi_name' => $this->getNameFromTitle( File::normalizeTitle( $dbKey ) ),
375  'oi_timestamp' => $dbr->timestamp( $search['time'] )
376  ],
377  LIST_AND
378  );
379  }
380  }
381 
382  if ( count( $oiConds ) ) {
383  $fileQuery = OldLocalFile::getQueryInfo();
384  $res = $dbr->select( $fileQuery['tables'], $fileQuery['fields'],
385  $dbr->makeList( $oiConds, LIST_OR ),
386  __METHOD__, [], $fileQuery['joins'] );
387  $applyMatchingFiles( $res, $searchSet, $finalFiles );
388  }
389 
390  // Check for redirects...
391  foreach ( $searchSet as $dbKey => $search ) {
392  if ( !empty( $search['ignoreRedirect'] ) ) {
393  continue;
394  }
395 
396  $title = File::normalizeTitle( $dbKey );
397  $redir = $this->checkRedirect( $title ); // hopefully hits memcached
398 
399  if ( $redir && $redir->getNamespace() === NS_FILE ) {
400  $file = $this->newFile( $redir );
401  if ( $file && $fileMatchesSearch( $file, $search ) ) {
402  $file->redirectedFrom( $title->getDBkey() );
403  if ( $flags & FileRepo::NAME_AND_TIME_ONLY ) {
404  $finalFiles[$dbKey] = [
405  'title' => $file->getTitle()->getDBkey(),
406  'timestamp' => $file->getTimestamp()
407  ];
408  } else {
409  $finalFiles[$dbKey] = $file;
410  }
411  }
412  }
413  }
414 
415  return $finalFiles;
416  }
417 
425  public function findBySha1( $hash ) {
426  $dbr = $this->getReplicaDB();
427  $fileQuery = LocalFile::getQueryInfo();
428  $res = $dbr->select(
429  $fileQuery['tables'],
430  $fileQuery['fields'],
431  [ 'img_sha1' => $hash ],
432  __METHOD__,
433  [ 'ORDER BY' => 'img_name' ],
434  $fileQuery['joins']
435  );
436 
437  $result = [];
438  foreach ( $res as $row ) {
439  $result[] = $this->newFileFromRow( $row );
440  }
441  $res->free();
442 
443  return $result;
444  }
445 
455  public function findBySha1s( array $hashes ) {
456  if ( $hashes === [] ) {
457  return []; // empty parameter
458  }
459 
460  $dbr = $this->getReplicaDB();
461  $fileQuery = LocalFile::getQueryInfo();
462  $res = $dbr->select(
463  $fileQuery['tables'],
464  $fileQuery['fields'],
465  [ 'img_sha1' => $hashes ],
466  __METHOD__,
467  [ 'ORDER BY' => 'img_name' ],
468  $fileQuery['joins']
469  );
470 
471  $result = [];
472  foreach ( $res as $row ) {
473  $file = $this->newFileFromRow( $row );
474  $result[$file->getSha1()][] = $file;
475  }
476  $res->free();
477 
478  return $result;
479  }
480 
488  public function findFilesByPrefix( $prefix, $limit ) {
489  $selectOptions = [ 'ORDER BY' => 'img_name', 'LIMIT' => intval( $limit ) ];
490 
491  // Query database
492  $dbr = $this->getReplicaDB();
493  $fileQuery = LocalFile::getQueryInfo();
494  $res = $dbr->select(
495  $fileQuery['tables'],
496  $fileQuery['fields'],
497  'img_name ' . $dbr->buildLike( $prefix, $dbr->anyString() ),
498  __METHOD__,
499  $selectOptions,
500  $fileQuery['joins']
501  );
502 
503  // Build file objects
504  $files = [];
505  foreach ( $res as $row ) {
506  $files[] = $this->newFileFromRow( $row );
507  }
508 
509  return $files;
510  }
511 
516  public function getReplicaDB() {
517  return wfGetDB( DB_REPLICA );
518  }
519 
525  public function getPrimaryDB() {
526  return wfGetDB( DB_PRIMARY );
527  }
528 
534  public function getMasterDB() {
535  wfDeprecated( __METHOD__, '1.37' );
536  return $this->getPrimaryDB();
537  }
538 
543  protected function getDBFactory() {
544  return static function ( $index ) {
545  return wfGetDB( $index );
546  };
547  }
548 
555  protected function hasAcessibleSharedCache() {
557  }
558 
559  public function getSharedCacheKey( $kClassSuffix, ...$components ) {
560  // T267668: do not include the repo name in the key
561  return $this->hasAcessibleSharedCache()
562  ? $this->wanCache->makeGlobalKey(
563  'filerepo-' . $kClassSuffix,
564  $this->dbDomain,
565  ...$components
566  )
567  : false;
568  }
569 
576  public function invalidateImageRedirect( $title ) {
577  $key = $this->getSharedCacheKey( 'file-redirect', md5( $title->getDBkey() ) );
578  if ( $key ) {
579  $this->getPrimaryDB()->onTransactionPreCommitOrIdle(
580  function () use ( $key ) {
581  $this->wanCache->delete( $key );
582  },
583  __METHOD__
584  );
585  }
586  }
587 
594  public function getInfo() {
595  global $wgFavicon;
596 
597  return array_merge( parent::getInfo(), [
598  'favicon' => wfExpandUrl( $wgFavicon ),
599  ] );
600  }
601 
602  public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
603  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
604  }
605 
606  public function storeBatch( array $triplets, $flags = 0 ) {
607  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
608  }
609 
610  public function cleanupBatch( array $files, $flags = 0 ) {
611  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
612  }
613 
614  public function publish(
615  $src,
616  $dstRel,
617  $archiveRel,
618  $flags = 0,
619  array $options = []
620  ) {
621  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
622  }
623 
624  public function publishBatch( array $ntuples, $flags = 0 ) {
625  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
626  }
627 
628  public function delete( $srcRel, $archiveRel ) {
629  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
630  }
631 
632  public function deleteBatch( array $sourceDestPairs ) {
633  return $this->skipWriteOperationIfSha1( __FUNCTION__, func_get_args() );
634  }
635 
643  protected function skipWriteOperationIfSha1( $function, array $args ) {
644  $this->assertWritableRepo(); // fail out if read-only
645 
646  if ( $this->hasSha1Storage() ) {
647  wfDebug( __METHOD__ . ": skipped because storage uses sha1 paths" );
648  return Status::newGood();
649  } else {
650  return parent::$function( ...$args );
651  }
652  }
653 
663  public function isJsonMetadataEnabled() {
664  return $this->useJsonMetadata;
665  }
666 
673  public function isSplitMetadataEnabled() {
675  }
676 
683  public function getSplitMetadataThreshold() {
685  }
686 
687  public function isMetadataUpdateEnabled() {
689  }
690 
691  public function isMetadataReserializeEnabled() {
693  }
694 
701  public function getBlobStore(): ?BlobStore {
702  if ( !$this->blobStore ) {
703  $this->blobStore = MediaWikiServices::getInstance()->getBlobStoreFactory()
704  ->newBlobStore( $this->dbDomain );
705  }
706  return $this->blobStore;
707  }
708 }
LIST_OR
const LIST_OR
Definition: Defines.php:46
LocalRepo\$reserializeMetadata
bool $reserializeMetadata
Definition: LocalRepo.php:76
LocalRepo\getSplitMetadataThreshold
getSplitMetadataThreshold()
Get the threshold above which metadata items should be split into separate storage,...
Definition: LocalRepo.php:683
Page\PageIdentity
Interface for objects (potentially) representing an editable wiki page.
Definition: PageIdentity.php:64
LocalRepo\$splitMetadataThreshold
int null $splitMetadataThreshold
Definition: LocalRepo.php:70
Wikimedia\Rdbms\Database
Relational database abstraction object.
Definition: Database.php:52
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:382
LocalRepo\getInfo
getInfo()
Return information about the repository.
Definition: LocalRepo.php:594
LocalRepo\isMetadataReserializeEnabled
isMetadataReserializeEnabled()
Definition: LocalRepo.php:691
LocalRepo\checkRedirect
checkRedirect( $title)
Checks if there is a redirect named as $title.
Definition: LocalRepo.php:239
WikiMap\getCurrentWikiDbDomain
static getCurrentWikiDbDomain()
Definition: WikiMap.php:293
LocalRepo\newFileFromRow
newFileFromRow( $row)
Definition: LocalRepo.php:114
FileRepo\newGood
newGood( $value=null)
Create a new good result.
Definition: FileRepo.php:1816
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:199
LocalRepo\getMasterDB
getMasterDB()
Get a connection to the primary DB.
Definition: LocalRepo.php:534
OldLocalFile\getQueryInfo
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new oldlocalfile object.
Definition: OldLocalFile.php:137
LocalRepo\getReplicaDB
getReplicaDB()
Get a connection to the replica DB.
Definition: LocalRepo.php:516
LocalRepo\publish
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...
Definition: LocalRepo.php:614
LIST_AND
const LIST_AND
Definition: Defines.php:43
LocalRepo\deletedFileHasKey
deletedFileHasKey( $key, $lock=null)
Check if a deleted (filearchive) file has this sha1 key.
Definition: LocalRepo.php:187
LocalRepo\getBlobStore
getBlobStore()
Get a BlobStore for storing and retrieving large metadata, or null if that can't be done.
Definition: LocalRepo.php:701
LocalRepo\getSharedCacheKey
getSharedCacheKey( $kClassSuffix,... $components)
Get a global, repository-qualified, WAN cache key.
Definition: LocalRepo.php:559
LocalRepo\$useJsonMetadata
bool $useJsonMetadata
Definition: LocalRepo.php:64
LocalRepo\$oldFileFactoryKey
callable $oldFileFactoryKey
Definition: LocalRepo.php:53
LocalRepo\invalidateImageRedirect
invalidateImageRedirect( $title)
Invalidates image redirect cache related to that image.
Definition: LocalRepo.php:576
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
LocalRepo\$oldFileFactory
callable $oldFileFactory
Definition: LocalRepo.php:51
LocalRepo\$blobStore
BlobStore $blobStore
Definition: LocalRepo.php:61
FileRepo\getZonePath
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
Definition: FileRepo.php:400
FileRepo\$backend
FileBackend $backend
Definition: FileRepo.php:68
$res
$res
Definition: testCompression.php:57
LocalRepo\hiddenFileHasKey
hiddenFileHasKey( $key, $lock=null)
Check if a hidden (revision delete) file has this sha1 key.
Definition: LocalRepo.php:203
LocalRepo\getHashFromKey
static getHashFromKey( $key)
Gets the SHA1 hash from a storage key.
Definition: LocalRepo.php:225
File\normalizeTitle
static normalizeTitle( $title, $exception=false)
Given a string or Title object return either a valid Title object with namespace NS_FILE or null.
Definition: File.php:205
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
LocalRepo\$updateCompatibleMetadata
bool $updateCompatibleMetadata
Definition: LocalRepo.php:73
$dbr
$dbr
Definition: testCompression.php:54
FileRepo\getNameFromTitle
getNameFromTitle( $title)
Get the name of a file from its title.
Definition: FileRepo.php:718
FileRepo
Base class for file repositories.
Definition: FileRepo.php:45
LocalRepo\isMetadataUpdateEnabled
isMetadataUpdateEnabled()
Definition: LocalRepo.php:687
FileRepo\hasSha1Storage
hasSha1Storage()
Returns whether or not storage is SHA-1 based.
Definition: FileRepo.php:2008
File
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition: File.php:66
LocalRepo\$oldFileFromRowFactory
callable $oldFileFromRowFactory
Definition: LocalRepo.php:49
FileRepo\newFile
newFile( $title, $time=false)
Create a new File object from the local repository.
Definition: FileRepo.php:424
MWException
MediaWiki exception.
Definition: MWException.php:29
FileBackend\doOperation
doOperation(array $op, array $opts=[])
Same as doOperations() except it takes a single operation.
Definition: FileBackend.php:505
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
Definition: GlobalFunctions.php:997
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:26
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:2200
File\normalizeExtension
static normalizeExtension( $extension)
Normalize a file extension to the common form, making it lowercase and checking some synonyms,...
Definition: File.php:254
LocalRepo\store
store( $srcPath, $dstZone, $dstRel, $flags=0)
Store a file to a given destination.
Definition: LocalRepo.php:602
LocalRepo\getDBFactory
getDBFactory()
Get a callback to get a DB handle given an index (DB_REPLICA/DB_PRIMARY)
Definition: LocalRepo.php:543
LocalRepo\storeBatch
storeBatch(array $triplets, $flags=0)
Store a batch of files.
Definition: LocalRepo.php:606
$args
if( $line===false) $args
Definition: mcc.php:124
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:650
DB_REPLICA
const DB_REPLICA
Definition: defines.php:25
wfDebug
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:894
LocalRepo\$useSplitMetadata
bool $useSplitMetadata
Definition: LocalRepo.php:67
LocalRepo\cleanupBatch
cleanupBatch(array $files, $flags=0)
Deletes a batch of files.
Definition: LocalRepo.php:610
LocalRepo\findFiles
findFiles(array $items, $flags=0)
Find many files at once.
Definition: LocalRepo.php:286
MediaWiki\Permissions\Authority
This interface represents the authority associated the current execution context, such as a web reque...
Definition: Authority.php:37
FileRepo\getLocalCacheKey
getLocalCacheKey( $kClassSuffix,... $components)
Get a site-local, repository-qualified, WAN cache key.
Definition: FileRepo.php:1912
LocalRepo\newFromArchiveName
newFromArchiveName( $title, $archiveName)
Definition: LocalRepo.php:129
StatusValue\newGood
static newGood( $value=null)
Factory function for good results.
Definition: StatusValue.php:82
DB_PRIMARY
const DB_PRIMARY
Definition: defines.php:27
LocalRepo\$hasAccessibleSharedCache
bool $hasAccessibleSharedCache
Whether shared cache keys are exposed/accessible.
Definition: LocalRepo.php:58
LocalRepo\$fileFactory
callable $fileFactory
Definition: LocalRepo.php:43
LocalRepo\$fileFactoryKey
callable $fileFactoryKey
Definition: LocalRepo.php:45
LocalRepo\findBySha1s
findBySha1s(array $hashes)
Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashe...
Definition: LocalRepo.php:455
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:484
$wgFavicon
$wgFavicon
The URL path of the shortcut icon.
Definition: DefaultSettings.php:404
LocalRepo\findFilesByPrefix
findFilesByPrefix( $prefix, $limit)
Return an array of files where the name starts with $prefix.
Definition: LocalRepo.php:488
MediaWiki\Storage\BlobStore
Service for loading and storing data blobs.
Definition: BlobStore.php:35
LocalFile\getQueryInfo
static getQueryInfo(array $options=[])
Return the tables, fields, and join conditions to be selected to create a new localfile object.
Definition: LocalFile.php:267
LocalRepo\cleanupDeletedBatch
cleanupDeletedBatch(array $storageKeys)
Delete files in the deleted directory if they are not referenced in the filearchive table.
Definition: LocalRepo.php:144
$path
$path
Definition: NoLocalSettings.php:25
LocalRepo\deleteBatch
deleteBatch(array $sourceDestPairs)
Move a group of files to the deletion archive.
Definition: LocalRepo.php:632
LocalRepo\findBySha1
findBySha1( $hash)
Get an array or iterator of file objects for files that have a given SHA-1 content hash.
Definition: LocalRepo.php:425
$ext
if(!is_readable( $file)) $ext
Definition: router.php:48
$hashes
$hashes
Definition: testCompression.php:71
LocalRepo\isJsonMetadataEnabled
isJsonMetadataEnabled()
Returns true if files should store metadata in JSON format.
Definition: LocalRepo.php:663
File\DELETED_FILE
const DELETED_FILE
Definition: File.php:70
LocalRepo\skipWriteOperationIfSha1
skipWriteOperationIfSha1( $function, array $args)
Skips the write operation if storage is sha1-based, executes it normally otherwise.
Definition: LocalRepo.php:643
NS_FILE
const NS_FILE
Definition: Defines.php:70
MediaWiki\Linker\LinkTarget
Definition: LinkTarget.php:26
LocalRepo\isSplitMetadataEnabled
isSplitMetadataEnabled()
Returns true if files should split up large metadata, storing parts of it in the BlobStore.
Definition: LocalRepo.php:673
LocalRepo\__construct
__construct(array $info=null)
Definition: LocalRepo.php:78
LocalRepo\hasAcessibleSharedCache
hasAcessibleSharedCache()
Check whether the repo has a shared cache, accessible from the current site context.
Definition: LocalRepo.php:555
OldLocalFile\newFromArchiveName
static newFromArchiveName( $title, $repo, $archiveName)
Definition: OldLocalFile.php:69
LocalRepo\publishBatch
publishBatch(array $ntuples, $flags=0)
Publish a batch of files.
Definition: LocalRepo.php:624
FileRepo\getDeletedHashPath
getDeletedHashPath( $key)
Get a relative path for a deletion archive key, e.g.
Definition: FileRepo.php:1566
FileRepo\assertWritableRepo
assertWritableRepo()
Throw an exception if this repo is read-only by design.
Definition: FileRepo.php:1974
LocalRepo\getPrimaryDB
getPrimaryDB()
Get a connection to the primary DB.
Definition: LocalRepo.php:525
FileRepo\NAME_AND_TIME_ONLY
const NAME_AND_TIME_ONLY
Definition: FileRepo.php:51
FileBackendDBRepoWrapper
Proxy backend that manages file layout rewriting for FileRepo.
Definition: FileBackendDBRepoWrapper.php:41
LocalRepo
A repository that stores files in the local filesystem and registers them in the wiki's own database.
Definition: LocalRepo.php:41
wfExpandUrl
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
Definition: GlobalFunctions.php:474
LocalRepo\$dbDomain
string $dbDomain
DB domain of the repo wiki.
Definition: LocalRepo.php:56
LocalRepo\$fileFromRowFactory
callable $fileFromRowFactory
Definition: LocalRepo.php:47