MediaWiki REL1_32
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
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 $wiki = $this->params['wiki'] ?? wfWikiID();
85
86 $url = $be->getContainerStoragePath( 'data' ) . '/' . rawurlencode( $wiki );
87 $url .= ( $be instanceof FSFileBackend )
88 ? "/{$rand[0]}/{$rand[1]}/{$rand[2]}/{$id}" // keep directories small
89 : "/{$rand[0]}/{$rand[1]}/{$id}"; // container sharding is only 2-levels
90
91 $be->prepare( [ 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ] );
92 if ( $be->create( [ 'dst' => $url, 'content' => $data ] )->isOK() ) {
93 return $url;
94 }
95 }
96
97 return false;
98 }
99
100 public function isReadOnly( $backend ) {
101 $be = FileBackendGroup::singleton()->get( $backend );
102
103 return $be ? $be->isReadOnly() : false;
104 }
105}
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Accessable external objects in a particular storage medium.
File backend accessible external objects.
batchFetchFromURLs(array $urls)
Fetch data from given external store URLs.
isReadOnly( $backend)
Check if a given location is read-only.
store( $backend, $data)
Insert a data item into a given location.
fetchFromURL( $url)
The URL returned is of the form of the form mwstore://backend/container/wiki/id.
Class for a file system (FS) based file backend.
Base class for all file backend classes (including multi-write backends).
static newTimestampedUID128( $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
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
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:37
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))