MediaWiki  1.30.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 = $blobs + $be->getFileContentsMulti( [ 'srcs' => $paths ] );
71  }
72 
73  return $blobs;
74  }
75 
83  public function store( $backend, $data ) {
84  $be = FileBackendGroup::singleton()->get( $backend );
85  if ( $be instanceof FileBackend ) {
86  // Get three random base 36 characters to act as shard directories
87  $rand = Wikimedia\base_convert( mt_rand( 0, 46655 ), 10, 36, 3 );
88  // Make sure ID is roughly lexicographically increasing for performance
89  $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
90  // Segregate items by wiki ID for the sake of bookkeeping
91  $wiki = isset( $this->params['wiki'] ) ? $this->params['wiki'] : wfWikiID();
92 
93  $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki );
94  $url .= ( $be instanceof FSFileBackend )
95  ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small
96  : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels
97 
98  $be->prepare( [ 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ] );
99  if ( $be->create( [ 'dst' => $url, 'content' => $data ] )->isOK() ) {
100  return $url;
101  }
102  }
103 
104  return 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:166
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:45
ExternalStoreMwstore\fetchFromURL
fetchFromURL( $url)
The URL returned is of the form of the form mwstore://backend/container/wiki/id.
Definition: ExternalStoreMwstore.php:41
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:2807
ExternalStoreMwstore
File backend accessable external objects.
Definition: ExternalStoreMwstore.php:33
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)
Definition: ExternalStoreMwstore.php:83
array
the array() calling protocol came about after MediaWiki 1.4rc1.