MediaWiki REL1_33
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}
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
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.
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
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))