MediaWiki  1.33.0
ExternalStoreMwstore.php
Go to the documentation of this file.
1 <?php
41  public function fetchFromURL( $url ) {
42  $be = FileBackendGroup::singleton()->backendFromPath( $url );
43  if ( $be instanceof FileBackend ) {
44  // We don't need "latest" since objects are immutable and
45  // backends should at least have "read-after-create" consistency.
46  return $be->getFileContents( [ 'src' => $url ] );
47  }
48 
49  return false;
50  }
51 
59  public function batchFetchFromURLs( array $urls ) {
60  $pathsByBackend = [];
61  foreach ( $urls as $url ) {
62  $be = FileBackendGroup::singleton()->backendFromPath( $url );
63  if ( $be instanceof FileBackend ) {
64  $pathsByBackend[$be->getName()][] = $url;
65  }
66  }
67  $blobs = [];
68  foreach ( $pathsByBackend as $backendName => $paths ) {
69  $be = FileBackendGroup::singleton()->get( $backendName );
70  $blobs += $be->getFileContentsMulti( [ 'srcs' => $paths ] );
71  }
72 
73  return $blobs;
74  }
75 
76  public function store( $backend, $data ) {
77  $be = FileBackendGroup::singleton()->get( $backend );
78  if ( $be instanceof FileBackend ) {
79  // Get three random base 36 characters to act as shard directories
80  $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 );
81  // Make sure ID is roughly lexicographically increasing for performance
82  $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
83  // Segregate items by wiki ID for the sake of bookkeeping
84  // @FIXME: this does not include the domain for b/c but it ideally should
85  $wiki = $this->params['wiki'] ?? wfWikiID();
86 
87  $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki );
88  $url .= ( $be instanceof FSFileBackend )
89  ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small
90  : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels
91 
92  $be->prepare( [ 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ] );
93  if ( $be->create( [ 'dst' => $url, 'content' => $data ] )->isOK() ) {
94  return $url;
95  }
96  }
97 
98  return false;
99  }
100 
101  public function isReadOnly( $backend ) {
102  $be = FileBackendGroup::singleton()->get( $backend );
103 
104  return $be ? $be->isReadOnly() : false;
105  }
106 }
ExternalStoreMedium
Accessable external objects in a particular storage medium.
Definition: ExternalStoreMedium.php:30
UIDGenerator\newTimestampedUID128
static newTimestampedUID128( $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
Definition: UIDGenerator.php:170
FileBackend
Base class for all file backend classes (including multi-write backends).
Definition: FileBackend.php:92
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
FileBackendGroup\singleton
static singleton()
Definition: FileBackendGroup.php:46
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
ExternalStoreMwstore\fetchFromURL
fetchFromURL( $url)
The URL returned is of the form of the form mwstore://backend/container/wiki/id.
Definition: ExternalStoreMwstore.php:41
array
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2602
ExternalStoreMwstore
File backend accessible external objects.
Definition: ExternalStoreMwstore.php:33
ExternalStoreMwstore\isReadOnly
isReadOnly( $backend)
Check if a given location is read-only.
Definition: ExternalStoreMwstore.php:101
ExternalStoreMwstore\batchFetchFromURLs
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
Definition: ExternalStoreMwstore.php:59
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
ExternalStoreMwstore\store
store( $backend, $data)
Insert a data item into a given location.
Definition: ExternalStoreMwstore.php:76