MediaWiki REL1_34
FileRepo.php
Go to the documentation of this file.
1<?php
11
39class FileRepo {
40 const DELETE_SOURCE = 1;
41 const OVERWRITE = 2;
42 const OVERWRITE_SAME = 4;
43 const SKIP_LOCKING = 8;
44
46
51
54
56 protected $hasSha1Storage = false;
57
59 protected $supportsSha1URLs = false;
60
62 protected $backend;
63
65 protected $zones = [];
66
68 protected $thumbScriptUrl;
69
74
78 protected $descBaseUrl;
79
83 protected $scriptDirUrl;
84
86 protected $articleUrl;
87
93 protected $initialCapital;
94
100 protected $pathDisclosureProtection = 'simple';
101
103 protected $url;
104
106 protected $thumbUrl;
107
109 protected $hashLevels;
110
113
119
121 protected $favicon;
122
124 protected $isPrivate;
125
127 protected $fileFactory = [ UnregisteredLocalFile::class, 'newFromTitle' ];
129 protected $oldFileFactory = false;
131 protected $fileFactoryKey = false;
133 protected $oldFileFactoryKey = false;
134
138 protected $thumbProxyUrl;
141
143 protected $wanCache;
144
149 public $name;
150
155 public function __construct( array $info = null ) {
156 // Verify required settings presence
157 if (
158 $info === null
159 || !array_key_exists( 'name', $info )
160 || !array_key_exists( 'backend', $info )
161 ) {
162 throw new MWException( __CLASS__ .
163 " requires an array of options having both 'name' and 'backend' keys.\n" );
164 }
165
166 // Required settings
167 $this->name = $info['name'];
168 if ( $info['backend'] instanceof FileBackend ) {
169 $this->backend = $info['backend']; // useful for testing
170 } else {
171 $this->backend = FileBackendGroup::singleton()->get( $info['backend'] );
172 }
173
174 // Optional settings that can have no value
175 $optionalSettings = [
176 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription',
177 'thumbScriptUrl', 'pathDisclosureProtection', 'descriptionCacheExpiry',
178 'favicon', 'thumbProxyUrl', 'thumbProxySecret',
179 ];
180 foreach ( $optionalSettings as $var ) {
181 if ( isset( $info[$var] ) ) {
182 $this->$var = $info[$var];
183 }
184 }
185
186 // Optional settings that have a default
187 $this->initialCapital = $info['initialCapital'] ??
188 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE );
189 $this->url = $info['url'] ?? false; // a subclass may set the URL (e.g. ForeignAPIRepo)
190 if ( isset( $info['thumbUrl'] ) ) {
191 $this->thumbUrl = $info['thumbUrl'];
192 } else {
193 $this->thumbUrl = $this->url ? "{$this->url}/thumb" : false;
194 }
195 $this->hashLevels = $info['hashLevels'] ?? 2;
196 $this->deletedHashLevels = $info['deletedHashLevels'] ?? $this->hashLevels;
197 $this->transformVia404 = !empty( $info['transformVia404'] );
198 $this->abbrvThreshold = $info['abbrvThreshold'] ?? 255;
199 $this->isPrivate = !empty( $info['isPrivate'] );
200 // Give defaults for the basic zones...
201 $this->zones = $info['zones'] ?? [];
202 foreach ( [ 'public', 'thumb', 'transcoded', 'temp', 'deleted' ] as $zone ) {
203 if ( !isset( $this->zones[$zone]['container'] ) ) {
204 $this->zones[$zone]['container'] = "{$this->name}-{$zone}";
205 }
206 if ( !isset( $this->zones[$zone]['directory'] ) ) {
207 $this->zones[$zone]['directory'] = '';
208 }
209 if ( !isset( $this->zones[$zone]['urlsByExt'] ) ) {
210 $this->zones[$zone]['urlsByExt'] = [];
211 }
212 }
213
214 $this->supportsSha1URLs = !empty( $info['supportsSha1URLs'] );
215
216 $this->wanCache = $info['wanCache'] ?? WANObjectCache::newEmpty();
217 }
218
224 public function getBackend() {
225 return $this->backend;
226 }
227
234 public function getReadOnlyReason() {
235 return $this->backend->getReadOnlyReason();
236 }
237
245 protected function initZones( $doZones = [] ) {
246 $status = $this->newGood();
247 foreach ( (array)$doZones as $zone ) {
248 $root = $this->getZonePath( $zone );
249 if ( $root === null ) {
250 throw new MWException( "No '$zone' zone defined in the {$this->name} repo." );
251 }
252 }
253
254 return $status;
255 }
256
263 public static function isVirtualUrl( $url ) {
264 return substr( $url, 0, 9 ) == 'mwrepo://';
265 }
266
275 public function getVirtualUrl( $suffix = false ) {
276 $path = 'mwrepo://' . $this->name;
277 if ( $suffix !== false ) {
278 $path .= '/' . rawurlencode( $suffix );
279 }
280
281 return $path;
282 }
283
291 public function getZoneUrl( $zone, $ext = null ) {
292 if ( in_array( $zone, [ 'public', 'thumb', 'transcoded' ] ) ) {
293 // standard public zones
294 if ( $ext !== null && isset( $this->zones[$zone]['urlsByExt'][$ext] ) ) {
295 // custom URL for extension/zone
296 return $this->zones[$zone]['urlsByExt'][$ext];
297 } elseif ( isset( $this->zones[$zone]['url'] ) ) {
298 // custom URL for zone
299 return $this->zones[$zone]['url'];
300 }
301 }
302 switch ( $zone ) {
303 case 'public':
304 return $this->url;
305 case 'temp':
306 case 'deleted':
307 return false; // no public URL
308 case 'thumb':
309 return $this->thumbUrl;
310 case 'transcoded':
311 return "{$this->url}/transcoded";
312 default:
313 return false;
314 }
315 }
316
320 public function backendSupportsUnicodePaths() {
321 return (bool)( $this->getBackend()->getFeatures() & FileBackend::ATTR_UNICODE_PATHS );
322 }
323
332 public function resolveVirtualUrl( $url ) {
333 if ( substr( $url, 0, 9 ) != 'mwrepo://' ) {
334 throw new MWException( __METHOD__ . ': unknown protocol' );
335 }
336 $bits = explode( '/', substr( $url, 9 ), 3 );
337 if ( count( $bits ) != 3 ) {
338 throw new MWException( __METHOD__ . ": invalid mwrepo URL: $url" );
339 }
340 list( $repo, $zone, $rel ) = $bits;
341 if ( $repo !== $this->name ) {
342 throw new MWException( __METHOD__ . ": fetching from a foreign repo is not supported" );
343 }
344 $base = $this->getZonePath( $zone );
345 if ( !$base ) {
346 throw new MWException( __METHOD__ . ": invalid zone: $zone" );
347 }
348
349 return $base . '/' . rawurldecode( $rel );
350 }
351
358 protected function getZoneLocation( $zone ) {
359 if ( !isset( $this->zones[$zone] ) ) {
360 return [ null, null ]; // bogus
361 }
362
363 return [ $this->zones[$zone]['container'], $this->zones[$zone]['directory'] ];
364 }
365
372 public function getZonePath( $zone ) {
373 list( $container, $base ) = $this->getZoneLocation( $zone );
374 if ( $container === null || $base === null ) {
375 return null;
376 }
377 $backendName = $this->backend->getName();
378 if ( $base != '' ) { // may not be set
379 $base = "/{$base}";
380 }
381
382 return "mwstore://$backendName/{$container}{$base}";
383 }
384
396 public function newFile( $title, $time = false ) {
397 $title = File::normalizeTitle( $title );
398 if ( !$title ) {
399 return null;
400 }
401 if ( $time ) {
402 if ( $this->oldFileFactory ) {
403 return call_user_func( $this->oldFileFactory, $title, $this, $time );
404 } else {
405 return null;
406 }
407 } else {
408 return call_user_func( $this->fileFactory, $title, $this );
409 }
410 }
411
429 public function findFile( $title, $options = [] ) {
430 $title = File::normalizeTitle( $title );
431 if ( !$title ) {
432 return false;
433 }
434 if ( isset( $options['bypassCache'] ) ) {
435 $options['latest'] = $options['bypassCache']; // b/c
436 }
437 $time = $options['time'] ?? false;
438 $flags = !empty( $options['latest'] ) ? File::READ_LATEST : 0;
439 # First try the current version of the file to see if it precedes the timestamp
440 $img = $this->newFile( $title );
441 if ( !$img ) {
442 return false;
443 }
444 $img->load( $flags );
445 if ( $img->exists() && ( !$time || $img->getTimestamp() == $time ) ) {
446 return $img;
447 }
448 # Now try an old version of the file
449 if ( $time !== false ) {
450 $img = $this->newFile( $title, $time );
451 if ( $img ) {
452 $img->load( $flags );
453 if ( $img->exists() ) {
454 if ( !$img->isDeleted( File::DELETED_FILE ) ) {
455 return $img; // always OK
456 } elseif ( !empty( $options['private'] ) &&
457 $img->userCan( File::DELETED_FILE,
458 $options['private'] instanceof User ? $options['private'] : null
459 )
460 ) {
461 return $img;
462 }
463 }
464 }
465 }
466
467 # Now try redirects
468 if ( !empty( $options['ignoreRedirect'] ) ) {
469 return false;
470 }
471 $redir = $this->checkRedirect( $title );
472 if ( $redir && $title->getNamespace() == NS_FILE ) {
473 $img = $this->newFile( $redir );
474 if ( !$img ) {
475 return false;
476 }
477 $img->load( $flags );
478 if ( $img->exists() ) {
479 $img->redirectedFrom( $title->getDBkey() );
480
481 return $img;
482 }
483 }
484
485 return false;
486 }
487
505 public function findFiles( array $items, $flags = 0 ) {
506 $result = [];
507 foreach ( $items as $item ) {
508 if ( is_array( $item ) ) {
509 $title = $item['title'];
510 $options = $item;
511 unset( $options['title'] );
512 } else {
513 $title = $item;
514 $options = [];
515 }
516 $file = $this->findFile( $title, $options );
517 if ( $file ) {
518 $searchName = File::normalizeTitle( $title )->getDBkey(); // must be valid
519 if ( $flags & self::NAME_AND_TIME_ONLY ) {
520 $result[$searchName] = [
521 'title' => $file->getTitle()->getDBkey(),
522 'timestamp' => $file->getTimestamp()
523 ];
524 } else {
525 $result[$searchName] = $file;
526 }
527 }
528 }
529
530 return $result;
531 }
532
542 public function findFileFromKey( $sha1, $options = [] ) {
543 $time = $options['time'] ?? false;
544 # First try to find a matching current version of a file...
545 if ( !$this->fileFactoryKey ) {
546 return false; // find-by-sha1 not supported
547 }
548 $img = call_user_func( $this->fileFactoryKey, $sha1, $this, $time );
549 if ( $img && $img->exists() ) {
550 return $img;
551 }
552 # Now try to find a matching old version of a file...
553 if ( $time !== false && $this->oldFileFactoryKey ) { // find-by-sha1 supported?
554 $img = call_user_func( $this->oldFileFactoryKey, $sha1, $this, $time );
555 if ( $img && $img->exists() ) {
556 if ( !$img->isDeleted( File::DELETED_FILE ) ) {
557 return $img; // always OK
558 } elseif ( !empty( $options['private'] ) &&
559 $img->userCan( File::DELETED_FILE,
560 $options['private'] instanceof User ? $options['private'] : null
561 )
562 ) {
563 return $img;
564 }
565 }
566 }
567
568 return false;
569 }
570
579 public function findBySha1( $hash ) {
580 return [];
581 }
582
590 public function findBySha1s( array $hashes ) {
591 $result = [];
592 foreach ( $hashes as $hash ) {
593 $files = $this->findBySha1( $hash );
594 if ( count( $files ) ) {
595 $result[$hash] = $files;
596 }
597 }
598
599 return $result;
600 }
601
610 public function findFilesByPrefix( $prefix, $limit ) {
611 return [];
612 }
613
619 public function getThumbScriptUrl() {
621 }
622
628 public function getThumbProxyUrl() {
630 }
631
637 public function getThumbProxySecret() {
639 }
640
646 public function canTransformVia404() {
648 }
649
656 public function getNameFromTitle( Title $title ) {
657 if (
658 $this->initialCapital !=
659 MediaWikiServices::getInstance()->getNamespaceInfo()->isCapitalized( NS_FILE )
660 ) {
661 $name = $title->getUserCaseDBKey();
662 if ( $this->initialCapital ) {
663 $name = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $name );
664 }
665 } else {
666 $name = $title->getDBkey();
667 }
668
669 return $name;
670 }
671
677 public function getRootDirectory() {
678 return $this->getZonePath( 'public' );
679 }
680
688 public function getHashPath( $name ) {
689 return self::getHashPathForLevel( $name, $this->hashLevels );
690 }
691
699 public function getTempHashPath( $suffix ) {
700 $parts = explode( '!', $suffix, 2 ); // format is <timestamp>!<name> or just <name>
701 $name = $parts[1] ?? $suffix; // hash path is not based on timestamp
702 return self::getHashPathForLevel( $name, $this->hashLevels );
703 }
704
710 protected static function getHashPathForLevel( $name, $levels ) {
711 if ( $levels == 0 ) {
712 return '';
713 } else {
714 $hash = md5( $name );
715 $path = '';
716 for ( $i = 1; $i <= $levels; $i++ ) {
717 $path .= substr( $hash, 0, $i ) . '/';
718 }
719
720 return $path;
721 }
722 }
723
729 public function getHashLevels() {
730 return $this->hashLevels;
731 }
732
738 public function getName() {
739 return $this->name;
740 }
741
749 public function makeUrl( $query = '', $entry = 'index' ) {
750 if ( isset( $this->scriptDirUrl ) ) {
751 return wfAppendQuery( "{$this->scriptDirUrl}/{$entry}.php", $query );
752 }
753
754 return false;
755 }
756
769 public function getDescriptionUrl( $name ) {
770 $encName = wfUrlencode( $name );
771 if ( !is_null( $this->descBaseUrl ) ) {
772 # "http://example.com/wiki/File:"
773 return $this->descBaseUrl . $encName;
774 }
775 if ( !is_null( $this->articleUrl ) ) {
776 # "http://example.com/wiki/$1"
777 # We use "Image:" as the canonical namespace for
778 # compatibility across all MediaWiki versions.
779 return str_replace( '$1',
780 "Image:$encName", $this->articleUrl );
781 }
782 if ( !is_null( $this->scriptDirUrl ) ) {
783 # "http://example.com/w"
784 # We use "Image:" as the canonical namespace for
785 # compatibility across all MediaWiki versions,
786 # and just sort of hope index.php is right. ;)
787 return $this->makeUrl( "title=Image:$encName" );
788 }
789
790 return false;
791 }
792
803 public function getDescriptionRenderUrl( $name, $lang = null ) {
804 $query = 'action=render';
805 if ( !is_null( $lang ) ) {
806 $query .= '&uselang=' . urlencode( $lang );
807 }
808 if ( isset( $this->scriptDirUrl ) ) {
809 return $this->makeUrl(
810 'title=' .
811 wfUrlencode( 'Image:' . $name ) .
812 "&$query" );
813 } else {
814 $descUrl = $this->getDescriptionUrl( $name );
815 if ( $descUrl ) {
816 return wfAppendQuery( $descUrl, $query );
817 } else {
818 return false;
819 }
820 }
821 }
822
828 public function getDescriptionStylesheetUrl() {
829 if ( isset( $this->scriptDirUrl ) ) {
830 // Must match canonical query parameter order for optimum caching
831 // See Title::getCdnUrls
832 return $this->makeUrl( 'title=MediaWiki:Filepage.css&action=raw&ctype=text/css' );
833 }
834
835 return false;
836 }
837
855 public function store( $srcPath, $dstZone, $dstRel, $flags = 0 ) {
856 $this->assertWritableRepo(); // fail out if read-only
857
858 $status = $this->storeBatch( [ [ $srcPath, $dstZone, $dstRel ] ], $flags );
859 if ( $status->successCount == 0 ) {
860 $status->setOK( false );
861 }
862
863 return $status;
864 }
865
880 public function storeBatch( array $triplets, $flags = 0 ) {
881 $this->assertWritableRepo(); // fail out if read-only
882
883 if ( $flags & self::DELETE_SOURCE ) {
884 throw new InvalidArgumentException( "DELETE_SOURCE not supported in " . __METHOD__ );
885 }
886
887 $status = $this->newGood();
888 $backend = $this->backend; // convenience
889
890 $operations = [];
891 // Validate each triplet and get the store operation...
892 foreach ( $triplets as $triplet ) {
893 list( $src, $dstZone, $dstRel ) = $triplet;
894 $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
895 wfDebug( __METHOD__
896 . "( \$src='$srcPath', \$dstZone='$dstZone', \$dstRel='$dstRel' )\n"
897 );
898 // Resolve source path
899 if ( $src instanceof FSFile ) {
900 $op = 'store';
901 } else {
902 $src = $this->resolveToStoragePathIfVirtual( $src );
903 $op = FileBackend::isStoragePath( $src ) ? 'copy' : 'store';
904 }
905 // Resolve destination path
906 $root = $this->getZonePath( $dstZone );
907 if ( !$root ) {
908 throw new MWException( "Invalid zone: $dstZone" );
909 }
910 if ( !$this->validateFilename( $dstRel ) ) {
911 throw new MWException( 'Validation error in $dstRel' );
912 }
913 $dstPath = "$root/$dstRel";
914 $dstDir = dirname( $dstPath );
915 // Create destination directories for this triplet
916 if ( !$this->initDirectory( $dstDir )->isOK() ) {
917 return $this->newFatal( 'directorycreateerror', $dstDir );
918 }
919
920 // Copy the source file to the destination
921 $operations[] = [
922 'op' => $op,
923 'src' => $src, // storage path (copy) or local file path (store)
924 'dst' => $dstPath,
925 'overwrite' => ( $flags & self::OVERWRITE ) ? true : false,
926 'overwriteSame' => ( $flags & self::OVERWRITE_SAME ) ? true : false,
927 ];
928 }
929
930 // Execute the store operation for each triplet
931 $opts = [ 'force' => true ];
932 if ( $flags & self::SKIP_LOCKING ) {
933 $opts['nonLocking'] = true;
934 }
935 $status->merge( $backend->doOperations( $operations, $opts ) );
936
937 return $status;
938 }
939
950 public function cleanupBatch( array $files, $flags = 0 ) {
951 $this->assertWritableRepo(); // fail out if read-only
952
953 $status = $this->newGood();
954
955 $operations = [];
956 foreach ( $files as $path ) {
957 if ( is_array( $path ) ) {
958 // This is a pair, extract it
959 list( $zone, $rel ) = $path;
960 $path = $this->getZonePath( $zone ) . "/$rel";
961 } else {
962 // Resolve source to a storage path if virtual
963 $path = $this->resolveToStoragePathIfVirtual( $path );
964 }
965 $operations[] = [ 'op' => 'delete', 'src' => $path ];
966 }
967 // Actually delete files from storage...
968 $opts = [ 'force' => true ];
969 if ( $flags & self::SKIP_LOCKING ) {
970 $opts['nonLocking'] = true;
971 }
972 $status->merge( $this->backend->doOperations( $operations, $opts ) );
973
974 return $status;
975 }
976
994 final public function quickImport( $src, $dst, $options = null ) {
995 return $this->quickImportBatch( [ [ $src, $dst, $options ] ] );
996 }
997
1012 public function quickImportBatch( array $triples ) {
1013 $status = $this->newGood();
1014 $operations = [];
1015 foreach ( $triples as $triple ) {
1016 list( $src, $dst ) = $triple;
1017 if ( $src instanceof FSFile ) {
1018 $op = 'store';
1019 } else {
1020 $src = $this->resolveToStoragePathIfVirtual( $src );
1021 $op = FileBackend::isStoragePath( $src ) ? 'copy' : 'store';
1022 }
1023 $dst = $this->resolveToStoragePathIfVirtual( $dst );
1024
1025 if ( !isset( $triple[2] ) ) {
1026 $headers = [];
1027 } elseif ( is_string( $triple[2] ) ) {
1028 // back-compat
1029 $headers = [ 'Content-Disposition' => $triple[2] ];
1030 } elseif ( is_array( $triple[2] ) && isset( $triple[2]['headers'] ) ) {
1031 $headers = $triple[2]['headers'];
1032 } else {
1033 $headers = [];
1034 }
1035
1036 $operations[] = [
1037 'op' => $op,
1038 'src' => $src, // storage path (copy) or local path/FSFile (store)
1039 'dst' => $dst,
1040 'headers' => $headers
1041 ];
1042 $status->merge( $this->initDirectory( dirname( $dst ) ) );
1043 }
1044 $status->merge( $this->backend->doQuickOperations( $operations ) );
1045
1046 return $status;
1047 }
1048
1057 final public function quickPurge( $path ) {
1058 return $this->quickPurgeBatch( [ $path ] );
1059 }
1060
1068 public function quickCleanDir( $dir ) {
1069 $status = $this->newGood();
1070 $status->merge( $this->backend->clean(
1071 [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
1072
1073 return $status;
1074 }
1075
1084 public function quickPurgeBatch( array $paths ) {
1085 $status = $this->newGood();
1086 $operations = [];
1087 foreach ( $paths as $path ) {
1088 $operations[] = [
1089 'op' => 'delete',
1090 'src' => $this->resolveToStoragePathIfVirtual( $path ),
1091 'ignoreMissingSource' => true
1092 ];
1093 }
1094 $status->merge( $this->backend->doQuickOperations( $operations ) );
1095
1096 return $status;
1097 }
1098
1109 public function storeTemp( $originalName, $srcPath ) {
1110 $this->assertWritableRepo(); // fail out if read-only
1111
1112 $date = MWTimestamp::getInstance()->format( 'YmdHis' );
1113 $hashPath = $this->getHashPath( $originalName );
1114 $dstUrlRel = $hashPath . $date . '!' . rawurlencode( $originalName );
1115 $virtualUrl = $this->getVirtualUrl( 'temp' ) . '/' . $dstUrlRel;
1116
1117 $result = $this->quickImport( $srcPath, $virtualUrl );
1118 $result->value = $virtualUrl;
1119
1120 return $result;
1121 }
1122
1129 public function freeTemp( $virtualUrl ) {
1130 $this->assertWritableRepo(); // fail out if read-only
1131
1132 $temp = $this->getVirtualUrl( 'temp' );
1133 if ( substr( $virtualUrl, 0, strlen( $temp ) ) != $temp ) {
1134 wfDebug( __METHOD__ . ": Invalid temp virtual URL\n" );
1135
1136 return false;
1137 }
1138
1139 return $this->quickPurge( $virtualUrl )->isOK();
1140 }
1141
1151 public function concatenate( array $srcPaths, $dstPath, $flags = 0 ) {
1152 $this->assertWritableRepo(); // fail out if read-only
1153
1154 $status = $this->newGood();
1155
1156 $sources = [];
1157 foreach ( $srcPaths as $srcPath ) {
1158 // Resolve source to a storage path if virtual
1159 $source = $this->resolveToStoragePathIfVirtual( $srcPath );
1160 $sources[] = $source; // chunk to merge
1161 }
1162
1163 // Concatenate the chunks into one FS file
1164 $params = [ 'srcs' => $sources, 'dst' => $dstPath ];
1165 $status->merge( $this->backend->concatenate( $params ) );
1166 if ( !$status->isOK() ) {
1167 return $status;
1168 }
1169
1170 // Delete the sources if required
1171 if ( $flags & self::DELETE_SOURCE ) {
1172 $status->merge( $this->quickPurgeBatch( $srcPaths ) );
1173 }
1174
1175 // Make sure status is OK, despite any quickPurgeBatch() fatals
1176 $status->setResult( true );
1177
1178 return $status;
1179 }
1180
1204 public function publish(
1205 $src, $dstRel, $archiveRel, $flags = 0, array $options = []
1206 ) {
1207 $this->assertWritableRepo(); // fail out if read-only
1208
1209 $status = $this->publishBatch(
1210 [ [ $src, $dstRel, $archiveRel, $options ] ], $flags );
1211 if ( $status->successCount == 0 ) {
1212 $status->setOK( false );
1213 }
1214 $status->value = $status->value[0] ?? false;
1215
1216 return $status;
1217 }
1218
1231 public function publishBatch( array $ntuples, $flags = 0 ) {
1232 $this->assertWritableRepo(); // fail out if read-only
1233
1234 $backend = $this->backend; // convenience
1235 // Try creating directories
1236 $status = $this->initZones( 'public' );
1237 if ( !$status->isOK() ) {
1238 return $status;
1239 }
1240
1241 $status = $this->newGood( [] );
1242
1243 $operations = [];
1244 $sourceFSFilesToDelete = []; // cleanup for disk source files
1245 // Validate each triplet and get the store operation...
1246 foreach ( $ntuples as $ntuple ) {
1247 list( $src, $dstRel, $archiveRel ) = $ntuple;
1248 $srcPath = ( $src instanceof FSFile ) ? $src->getPath() : $src;
1249
1250 $options = $ntuple[3] ?? [];
1251 // Resolve source to a storage path if virtual
1252 $srcPath = $this->resolveToStoragePathIfVirtual( $srcPath );
1253 if ( !$this->validateFilename( $dstRel ) ) {
1254 throw new MWException( 'Validation error in $dstRel' );
1255 }
1256 if ( !$this->validateFilename( $archiveRel ) ) {
1257 throw new MWException( 'Validation error in $archiveRel' );
1258 }
1259
1260 $publicRoot = $this->getZonePath( 'public' );
1261 $dstPath = "$publicRoot/$dstRel";
1262 $archivePath = "$publicRoot/$archiveRel";
1263
1264 $dstDir = dirname( $dstPath );
1265 $archiveDir = dirname( $archivePath );
1266 // Abort immediately on directory creation errors since they're likely to be repetitive
1267 if ( !$this->initDirectory( $dstDir )->isOK() ) {
1268 return $this->newFatal( 'directorycreateerror', $dstDir );
1269 }
1270 if ( !$this->initDirectory( $archiveDir )->isOK() ) {
1271 return $this->newFatal( 'directorycreateerror', $archiveDir );
1272 }
1273
1274 // Set any desired headers to be use in GET/HEAD responses
1275 $headers = $options['headers'] ?? [];
1276
1277 // Archive destination file if it exists.
1278 // This will check if the archive file also exists and fail if does.
1279 // This is a sanity check to avoid data loss. On Windows and Linux,
1280 // copy() will overwrite, so the existence check is vulnerable to
1281 // race conditions unless a functioning LockManager is used.
1282 // LocalFile also uses SELECT FOR UPDATE for synchronization.
1283 $operations[] = [
1284 'op' => 'copy',
1285 'src' => $dstPath,
1286 'dst' => $archivePath,
1287 'ignoreMissingSource' => true
1288 ];
1289
1290 // Copy (or move) the source file to the destination
1291 if ( FileBackend::isStoragePath( $srcPath ) ) {
1292 $operations[] = [
1293 'op' => ( $flags & self::DELETE_SOURCE ) ? 'move' : 'copy',
1294 'src' => $srcPath,
1295 'dst' => $dstPath,
1296 'overwrite' => true, // replace current
1297 'headers' => $headers
1298 ];
1299 } else {
1300 $operations[] = [
1301 'op' => 'store',
1302 'src' => $src, // storage path (copy) or local path/FSFile (store)
1303 'dst' => $dstPath,
1304 'overwrite' => true, // replace current
1305 'headers' => $headers
1306 ];
1307 if ( $flags & self::DELETE_SOURCE ) {
1308 $sourceFSFilesToDelete[] = $srcPath;
1309 }
1310 }
1311 }
1312
1313 // Execute the operations for each triplet
1314 $status->merge( $backend->doOperations( $operations ) );
1315 // Find out which files were archived...
1316 foreach ( $ntuples as $i => $ntuple ) {
1317 list( , , $archiveRel ) = $ntuple;
1318 $archivePath = $this->getZonePath( 'public' ) . "/$archiveRel";
1319 if ( $this->fileExists( $archivePath ) ) {
1320 $status->value[$i] = 'archived';
1321 } else {
1322 $status->value[$i] = 'new';
1323 }
1324 }
1325 // Cleanup for disk source files...
1326 foreach ( $sourceFSFilesToDelete as $file ) {
1327 Wikimedia\suppressWarnings();
1328 unlink( $file ); // FS cleanup
1329 Wikimedia\restoreWarnings();
1330 }
1331
1332 return $status;
1333 }
1334
1342 protected function initDirectory( $dir ) {
1343 $path = $this->resolveToStoragePathIfVirtual( $dir );
1344 list( , $container, ) = FileBackend::splitStoragePath( $path );
1345
1346 $params = [ 'dir' => $path ];
1347 if ( $this->isPrivate
1348 || $container === $this->zones['deleted']['container']
1349 || $container === $this->zones['temp']['container']
1350 ) {
1351 # Take all available measures to prevent web accessibility of new deleted
1352 # directories, in case the user has not configured offline storage
1353 $params = [ 'noAccess' => true, 'noListing' => true ] + $params;
1354 }
1355
1356 $status = $this->newGood();
1357 $status->merge( $this->backend->prepare( $params ) );
1358
1359 return $status;
1360 }
1361
1368 public function cleanDir( $dir ) {
1369 $this->assertWritableRepo(); // fail out if read-only
1370
1371 $status = $this->newGood();
1372 $status->merge( $this->backend->clean(
1373 [ 'dir' => $this->resolveToStoragePathIfVirtual( $dir ) ] ) );
1374
1375 return $status;
1376 }
1377
1384 public function fileExists( $file ) {
1385 $result = $this->fileExistsBatch( [ $file ] );
1386
1387 return $result[0];
1388 }
1389
1396 public function fileExistsBatch( array $files ) {
1397 $paths = array_map( [ $this, 'resolveToStoragePathIfVirtual' ], $files );
1398 $this->backend->preloadFileStat( [ 'srcs' => $paths ] );
1399
1400 $result = [];
1401 foreach ( $files as $key => $file ) {
1403 $result[$key] = $this->backend->fileExists( [ 'src' => $path ] );
1404 }
1405
1406 return $result;
1407 }
1408
1419 public function delete( $srcRel, $archiveRel ) {
1420 $this->assertWritableRepo(); // fail out if read-only
1421
1422 return $this->deleteBatch( [ [ $srcRel, $archiveRel ] ] );
1423 }
1424
1442 public function deleteBatch( array $sourceDestPairs ) {
1443 $this->assertWritableRepo(); // fail out if read-only
1444
1445 // Try creating directories
1446 $status = $this->initZones( [ 'public', 'deleted' ] );
1447 if ( !$status->isOK() ) {
1448 return $status;
1449 }
1450
1451 $status = $this->newGood();
1452
1453 $backend = $this->backend; // convenience
1454 $operations = [];
1455 // Validate filenames and create archive directories
1456 foreach ( $sourceDestPairs as $pair ) {
1457 list( $srcRel, $archiveRel ) = $pair;
1458 if ( !$this->validateFilename( $srcRel ) ) {
1459 throw new MWException( __METHOD__ . ':Validation error in $srcRel' );
1460 } elseif ( !$this->validateFilename( $archiveRel ) ) {
1461 throw new MWException( __METHOD__ . ':Validation error in $archiveRel' );
1462 }
1463
1464 $publicRoot = $this->getZonePath( 'public' );
1465 $srcPath = "{$publicRoot}/$srcRel";
1466
1467 $deletedRoot = $this->getZonePath( 'deleted' );
1468 $archivePath = "{$deletedRoot}/{$archiveRel}";
1469 $archiveDir = dirname( $archivePath ); // does not touch FS
1470
1471 // Create destination directories
1472 if ( !$this->initDirectory( $archiveDir )->isOK() ) {
1473 return $this->newFatal( 'directorycreateerror', $archiveDir );
1474 }
1475
1476 $operations[] = [
1477 'op' => 'move',
1478 'src' => $srcPath,
1479 'dst' => $archivePath,
1480 // We may have 2+ identical files being deleted,
1481 // all of which will map to the same destination file
1482 'overwriteSame' => true // also see T33792
1483 ];
1484 }
1485
1486 // Move the files by execute the operations for each pair.
1487 // We're now committed to returning an OK result, which will
1488 // lead to the files being moved in the DB also.
1489 $opts = [ 'force' => true ];
1490 $status->merge( $backend->doOperations( $operations, $opts ) );
1491
1492 return $status;
1493 }
1494
1501 public function cleanupDeletedBatch( array $storageKeys ) {
1502 $this->assertWritableRepo();
1503 }
1504
1513 public function getDeletedHashPath( $key ) {
1514 if ( strlen( $key ) < 31 ) {
1515 throw new MWException( "Invalid storage key '$key'." );
1516 }
1517 $path = '';
1518 for ( $i = 0; $i < $this->deletedHashLevels; $i++ ) {
1519 $path .= $key[$i] . '/';
1520 }
1521
1522 return $path;
1523 }
1524
1533 protected function resolveToStoragePathIfVirtual( $path ) {
1534 if ( self::isVirtualUrl( $path ) ) {
1535 return $this->resolveVirtualUrl( $path );
1536 }
1537
1538 return $path;
1539 }
1540
1548 public function getLocalCopy( $virtualUrl ) {
1549 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1550
1551 return $this->backend->getLocalCopy( [ 'src' => $path ] );
1552 }
1553
1562 public function getLocalReference( $virtualUrl ) {
1563 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1564
1565 return $this->backend->getLocalReference( [ 'src' => $path ] );
1566 }
1567
1575 public function getFileProps( $virtualUrl ) {
1576 $fsFile = $this->getLocalReference( $virtualUrl );
1577 $mwProps = new MWFileProps( MediaWiki\MediaWikiServices::getInstance()->getMimeAnalyzer() );
1578 if ( $fsFile ) {
1579 $props = $mwProps->getPropsFromPath( $fsFile->getPath(), true );
1580 } else {
1581 $props = $mwProps->newPlaceholderProps();
1582 }
1583
1584 return $props;
1585 }
1586
1593 public function getFileTimestamp( $virtualUrl ) {
1594 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1595
1596 return $this->backend->getFileTimestamp( [ 'src' => $path ] );
1597 }
1598
1605 public function getFileSize( $virtualUrl ) {
1606 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1607
1608 return $this->backend->getFileSize( [ 'src' => $path ] );
1609 }
1610
1617 public function getFileSha1( $virtualUrl ) {
1618 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1619
1620 return $this->backend->getFileSha1Base36( [ 'src' => $path ] );
1621 }
1622
1632 public function streamFileWithStatus( $virtualUrl, $headers = [], $optHeaders = [] ) {
1633 $path = $this->resolveToStoragePathIfVirtual( $virtualUrl );
1634 $params = [ 'src' => $path, 'headers' => $headers, 'options' => $optHeaders ];
1635
1636 // T172851: HHVM does not flush the output properly, causing OOM
1637 ob_start( null, 1048576 );
1638 ob_implicit_flush( true );
1639
1640 $status = $this->newGood();
1641 $status->merge( $this->backend->streamFile( $params ) );
1642
1643 // T186565: Close the buffer, unless it has already been closed
1644 // in HTTPFileStreamer::resetOutputBuffers().
1645 if ( ob_get_status() ) {
1646 ob_end_flush();
1647 }
1648
1649 return $status;
1650 }
1651
1660 public function enumFiles( $callback ) {
1661 $this->enumFilesInStorage( $callback );
1662 }
1663
1671 protected function enumFilesInStorage( $callback ) {
1672 $publicRoot = $this->getZonePath( 'public' );
1673 $numDirs = 1 << ( $this->hashLevels * 4 );
1674 // Use a priori assumptions about directory structure
1675 // to reduce the tree height of the scanning process.
1676 for ( $flatIndex = 0; $flatIndex < $numDirs; $flatIndex++ ) {
1677 $hexString = sprintf( "%0{$this->hashLevels}x", $flatIndex );
1678 $path = $publicRoot;
1679 for ( $hexPos = 0; $hexPos < $this->hashLevels; $hexPos++ ) {
1680 $path .= '/' . substr( $hexString, 0, $hexPos + 1 );
1681 }
1682 $iterator = $this->backend->getFileList( [ 'dir' => $path ] );
1683 foreach ( $iterator as $name ) {
1684 // Each item returned is a public file
1685 call_user_func( $callback, "{$path}/{$name}" );
1686 }
1687 }
1688 }
1689
1696 public function validateFilename( $filename ) {
1697 if ( strval( $filename ) == '' ) {
1698 return false;
1699 }
1700
1701 return FileBackend::isPathTraversalFree( $filename );
1702 }
1703
1710 switch ( $this->pathDisclosureProtection ) {
1711 case 'none':
1712 case 'simple': // b/c
1713 $callback = [ $this, 'passThrough' ];
1714 break;
1715 default: // 'paranoid'
1716 $callback = [ $this, 'paranoidClean' ];
1717 }
1718 return $callback;
1719 }
1720
1727 function paranoidClean( $param ) {
1728 return '[hidden]';
1729 }
1730
1737 function passThrough( $param ) {
1738 return $param;
1739 }
1740
1747 public function newFatal( $message /*, parameters...*/ ) {
1748 $status = Status::newFatal( ...func_get_args() );
1749 $status->cleanCallback = $this->getErrorCleanupFunction();
1750
1751 return $status;
1752 }
1753
1760 public function newGood( $value = null ) {
1761 $status = Status::newGood( $value );
1762 $status->cleanCallback = $this->getErrorCleanupFunction();
1763
1764 return $status;
1765 }
1766
1775 public function checkRedirect( Title $title ) {
1776 return false;
1777 }
1778
1787 }
1788
1794 public function getDisplayName() {
1795 global $wgSitename;
1796
1797 if ( $this->isLocal() ) {
1798 return $wgSitename;
1799 }
1800
1801 // 'shared-repo-name-wikimediacommons' is used when $wgUseInstantCommons = true
1802 return wfMessageFallback( 'shared-repo-name-' . $this->name, 'shared-repo' )->text();
1803 }
1804
1812 public function nameForThumb( $name ) {
1813 if ( strlen( $name ) > $this->abbrvThreshold ) {
1815 $name = ( $ext == '' ) ? 'thumbnail' : "thumbnail.$ext";
1816 }
1817
1818 return $name;
1819 }
1820
1826 public function isLocal() {
1827 return $this->getName() == 'local';
1828 }
1829
1838 public function getSharedCacheKey( /*...*/ ) {
1839 return false;
1840 }
1841
1849 public function getLocalCacheKey( /*...*/ ) {
1850 $args = func_get_args();
1851 array_unshift( $args, 'filerepo', $this->getName() );
1852
1853 return $this->wanCache->makeKey( ...$args );
1854 }
1855
1864 public function getTempRepo() {
1865 return new TempFileRepo( [
1866 'name' => "{$this->name}-temp",
1867 'backend' => $this->backend,
1868 'zones' => [
1869 'public' => [
1870 // Same place storeTemp() uses in the base repo, though
1871 // the path hashing is mismatched, which is annoying.
1872 'container' => $this->zones['temp']['container'],
1873 'directory' => $this->zones['temp']['directory']
1874 ],
1875 'thumb' => [
1876 'container' => $this->zones['temp']['container'],
1877 'directory' => $this->zones['temp']['directory'] == ''
1878 ? 'thumb'
1879 : $this->zones['temp']['directory'] . '/thumb'
1880 ],
1881 'transcoded' => [
1882 'container' => $this->zones['temp']['container'],
1883 'directory' => $this->zones['temp']['directory'] == ''
1884 ? 'transcoded'
1885 : $this->zones['temp']['directory'] . '/transcoded'
1886 ]
1887 ],
1888 'hashLevels' => $this->hashLevels, // performance
1889 'isPrivate' => true // all in temp zone
1890 ] );
1891 }
1892
1899 public function getUploadStash( User $user = null ) {
1900 return new UploadStash( $this, $user );
1901 }
1902
1910 protected function assertWritableRepo() {
1911 }
1912
1919 public function getInfo() {
1920 $ret = [
1921 'name' => $this->getName(),
1922 'displayname' => $this->getDisplayName(),
1923 'rootUrl' => $this->getZoneUrl( 'public' ),
1924 'local' => $this->isLocal(),
1925 ];
1926
1927 $optionalSettings = [
1928 'url', 'thumbUrl', 'initialCapital', 'descBaseUrl', 'scriptDirUrl', 'articleUrl',
1929 'fetchDescription', 'descriptionCacheExpiry', 'favicon'
1930 ];
1931 foreach ( $optionalSettings as $k ) {
1932 if ( isset( $this->$k ) ) {
1933 $ret[$k] = $this->$k;
1934 }
1935 }
1936
1937 return $ret;
1938 }
1939
1944 public function hasSha1Storage() {
1945 return $this->hasSha1Storage;
1946 }
1947
1952 public function supportsSha1URLs() {
1954 }
1955}
$wgSitename
Name of the site.
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...
if( $line===false) $args
Definition cdb.php:64
Class representing a non-directory file on the file system.
Definition FSFile.php:32
Base class for all file backend classes (including multi-write backends).
static isStoragePath( $path)
Check if a given path is a "mwstore://" path.
const ATTR_UNICODE_PATHS
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.
doOperations(array $ops, array $opts=[])
This is the main entry point into the backend for write operations.
static isPathTraversalFree( $path)
Check if a relative path has no directory traversals.
Base class for file repositories.
Definition FileRepo.php:39
string $pathDisclosureProtection
May be 'paranoid' to remove all parameters from error messages, 'none' to leave the paths in unchange...
Definition FileRepo.php:100
getTempHashPath( $suffix)
Get a relative path including trailing slash, e.g.
Definition FileRepo.php:699
int $hashLevels
The number of directory levels for hash-based division of files.
Definition FileRepo.php:109
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.
getLocalCacheKey()
Get a key for this repo in the local cache domain.
const OVERWRITE_SAME
Definition FileRepo.php:42
resolveVirtualUrl( $url)
Get the backend storage path corresponding to a virtual URL.
Definition FileRepo.php:332
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.
Definition FileRepo.php:505
getThumbProxyUrl()
Get the URL thumb.php requests are being proxied to.
Definition FileRepo.php:628
getZoneLocation( $zone)
The the storage container and base path of a zone.
Definition FileRepo.php:358
string $favicon
The URL of the repo's favicon, if any.
Definition FileRepo.php:121
fileExists( $file)
Checks existence of a file.
getFileSha1( $virtualUrl)
Get the sha1 (base 36) of a file with a given virtual URL/storage path.
bool $supportsSha1URLs
Definition FileRepo.php:59
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.
Definition FileRepo.php:677
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.
Definition FileRepo.php:610
getHashLevels()
Get the number of hash directory levels.
Definition FileRepo.php:729
string $thumbProxySecret
Secret key to pass as an X-Swift-Secret header to the proxied thumb service.
Definition FileRepo.php:140
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.
Definition FileRepo.php:738
store( $srcPath, $dstZone, $dstRel, $flags=0)
Store a file to a given destination.
Definition FileRepo.php:855
findFile( $title, $options=[])
Find an instance of the named file created at the specified time Returns false if the file does not e...
Definition FileRepo.php:429
callable false $oldFileFactoryKey
Override these in the base class.
Definition FileRepo.php:133
getVirtualUrl( $suffix=false)
Get a URL referring to this repository, with the private mwrepo protocol.
Definition FileRepo.php:275
const NAME_AND_TIME_ONLY
Definition FileRepo.php:45
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)
Definition FileRepo.php:710
array $zones
Map of zones to config.
Definition FileRepo.php:65
callable false $fileFactoryKey
Override these in the base class.
Definition FileRepo.php:131
getUploadStash(User $user=null)
Get an UploadStash associated with this repo.
getDisplayName()
Get the human-readable name of the repo.
getSharedCacheKey()
Get a key on the primary cache for this repository.
storeBatch(array $triplets, $flags=0)
Store a batch of files.
Definition FileRepo.php:880
enumFiles( $callback)
Call a callback function for every public regular file in the repository.
hasSha1Storage()
Returns whether or not storage is SHA-1 based.
cleanupBatch(array $files, $flags=0)
Deletes a batch of files.
Definition FileRepo.php:950
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.
Definition FileRepo.php:118
makeUrl( $query='', $entry='index')
Make an url to this repo.
Definition FileRepo.php:749
findBySha1s(array $hashes)
Get an array of arrays or iterators of file objects for files that have the given SHA-1 content hashe...
Definition FileRepo.php:590
string $thumbProxyUrl
URL of where to proxy thumb.php requests to.
Definition FileRepo.php:138
concatenate(array $srcPaths, $dstPath, $flags=0)
Concatenate a list of temporary files into a target file location.
FileBackend $backend
Definition FileRepo.php:62
fileExistsBatch(array $files)
Checks existence of an array of files.
int $descriptionCacheExpiry
Definition FileRepo.php:53
paranoidClean( $param)
Path disclosure protection function.
WANObjectCache $wanCache
Definition FileRepo.php:143
const SKIP_LOCKING
Definition FileRepo.php:43
initZones( $doZones=[])
Check if a single zone or list of zones is defined for usage.
Definition FileRepo.php:245
string $thumbUrl
The base thumbnail URL.
Definition FileRepo.php:106
getFileProps( $virtualUrl)
Get properties of a file with a given virtual URL/storage path.
const OVERWRITE
Definition FileRepo.php:41
isLocal()
Returns true if this the local file repository.
getZonePath( $zone)
Get the storage path corresponding to one of the zones.
Definition FileRepo.php:372
getDescriptionUrl( $name)
Get the URL of an image description page.
Definition FileRepo.php:769
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.
bool $hasSha1Storage
Definition FileRepo.php:56
const DELETE_SOURCE
Definition FileRepo.php:40
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.
Definition FileRepo.php:637
bool $fetchDescription
Whether to fetch commons image description pages and display them on the local wiki.
Definition FileRepo.php:50
string false $url
Public zone URL.
Definition FileRepo.php:103
callable $fileFactory
Override these in the base class.
Definition FileRepo.php:127
static isVirtualUrl( $url)
Determine if a string is an mwrepo:// URL.
Definition FileRepo.php:263
getDescriptionStylesheetUrl()
Get the URL of the stylesheet to apply to description pages.
Definition FileRepo.php:828
bool $transformVia404
Whether to skip media file transformation on parse and rely on a 404 handler instead.
Definition FileRepo.php:73
getFileTimestamp( $virtualUrl)
Get the timestamp of a file with a given virtual URL/storage path.
checkRedirect(Title $title)
Checks if there is a redirect named as $title.
bool $isPrivate
Whether all zones should be private (e.g.
Definition FileRepo.php:124
string $scriptDirUrl
URL of the MediaWiki installation, equivalent to $wgScriptPath, e.g.
Definition FileRepo.php:83
string $descBaseUrl
URL of image description pages, e.g.
Definition FileRepo.php:78
getZoneUrl( $zone, $ext=null)
Get the URL corresponding to one of the four basic zones.
Definition FileRepo.php:291
newFatal( $message)
Create a new fatal error.
getReadOnlyReason()
Get an explanatory message if this repo is read-only.
Definition FileRepo.php:234
newFile( $title, $time=false)
Create a new File object from the local repository.
Definition FileRepo.php:396
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.
Definition FileRepo.php:646
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...
Definition FileRepo.php:542
int $deletedHashLevels
The number of directory levels for hash-based division of deleted files.
Definition FileRepo.php:112
string $thumbScriptUrl
URL of thumb.php.
Definition FileRepo.php:68
backendSupportsUnicodePaths()
Definition FileRepo.php:320
__construct(array $info=null)
Definition FileRepo.php:155
string $name
Definition FileRepo.php:149
bool $initialCapital
Equivalent to $wgCapitalLinks (or $wgCapitalLinkOverrides[NS_FILE], determines whether filenames impl...
Definition FileRepo.php:93
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.
getErrorCleanupFunction()
Get a callback function to use for cleaning error message parameters.
getHashPath( $name)
Get a relative path including trailing slash, e.g.
Definition FileRepo.php:688
getNameFromTitle(Title $title)
Get the name of a file from its title object.
Definition FileRepo.php:656
callable false $oldFileFactory
Override these in the base class.
Definition FileRepo.php:129
invalidateImageRedirect(Title $title)
Invalidates image redirect cache related to that image Doesn't do anything for repositories that don'...
quickImport( $src, $dst, $options=null)
Import a file from the local file system into the repo.
Definition FileRepo.php:994
string $articleUrl
Equivalent to $wgArticlePath, e.g.
Definition FileRepo.php:86
getDescriptionRenderUrl( $name, $lang=null)
Get the URL of the content-only fragment of the description page.
Definition FileRepo.php:803
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.
Definition FileRepo.php:579
getBackend()
Get the file backend instance.
Definition FileRepo.php:224
getInfo()
Return information about the repository.
getThumbScriptUrl()
Get the URL of thumb.php.
Definition FileRepo.php:619
getLocalReference( $virtualUrl)
Get a local FS file with a given virtual URL/storage path.
MediaWiki exception.
MimeMagic helper wrapper.
MediaWikiServices is the service locator for the application scope of MediaWiki.
FileRepo for temporary files created via FileRepo::getTempRepo()
Represents a title within MediaWiki.
Definition Title.php:42
UploadStash is intended to accomplish a few things:
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:51
Multi-datacenter aware caching interface.
const NS_FILE
Definition Defines.php:75
$source
This class serves as a utility class for this extension.
return true
Definition router.php:94
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42
if(!is_readable( $file)) $ext
Definition router.php:48
if(!isset( $args[0])) $lang