MediaWiki  1.23.2
ExternalStoreMwstore.php
Go to the documentation of this file.
1 <?php
39  public function fetchFromURL( $url ) {
40  $be = FileBackendGroup::singleton()->backendFromPath( $url );
41  if ( $be instanceof FileBackend ) {
42  // We don't need "latest" since objects are immutable and
43  // backends should at least have "read-after-create" consistency.
44  return $be->getFileContents( array( 'src' => $url ) );
45  }
46 
47  return false;
48  }
49 
57  public function batchFetchFromURLs( array $urls ) {
58  $pathsByBackend = array();
59  foreach ( $urls as $url ) {
60  $be = FileBackendGroup::singleton()->backendFromPath( $url );
61  if ( $be instanceof FileBackend ) {
62  $pathsByBackend[$be->getName()][] = $url;
63  }
64  }
65  $blobs = array();
66  foreach ( $pathsByBackend as $backendName => $paths ) {
67  $be = FileBackendGroup::singleton()->get( $backendName );
68  $blobs = $blobs + $be->getFileContentsMulti( array( 'srcs' => $paths ) );
69  }
70 
71  return $blobs;
72  }
73 
77  public function store( $backend, $data ) {
78  $be = FileBackendGroup::singleton()->get( $backend );
79  if ( $be instanceof FileBackend ) {
80  // Get three random base 36 characters to act as shard directories
81  $rand = wfBaseConvert( mt_rand( 0, 46655 ), 10, 36, 3 );
82  // Make sure ID is roughly lexicographically increasing for performance
83  $id = str_pad( UIDGenerator::newTimestampedUID128( 32 ), 26, '0', STR_PAD_LEFT );
84  // Segregate items by wiki ID for the sake of bookkeeping
85  $wiki = isset( $this->params['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( array( 'dir' => dirname( $url ), 'noAccess' => 1, 'noListing' => 1 ) );
93  if ( $be->create( array( 'dst' => $url, 'content' => $data ) )->isOK() ) {
94  return $url;
95  }
96  }
97 
98  return false;
99  }
100 }
ExternalStoreMedium
Accessable external objects in a particular storage medium.
Definition: ExternalStoreMedium.php:31
UIDGenerator\newTimestampedUID128
static newTimestampedUID128( $base=10)
Get a statistically unique 128-bit unsigned integer ID string.
Definition: UIDGenerator.php:152
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
FileBackend
Base class for all file backend classes (including multi-write backends).
Definition: FileBackend.php:85
FileBackendGroup\singleton
static singleton()
Definition: FileBackendGroup.php:43
ExternalStoreMwstore\fetchFromURL
fetchFromURL( $url)
The URL returned is of the form of the form mwstore://backend/container/wiki/id.
Definition: ExternalStoreMwstore.php:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWikiID
wfWikiID()
Get an ASCII string identifying this wiki This is used as a prefix in memcached keys.
Definition: GlobalFunctions.php:3604
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:57
FSFileBackend
Class for a file system (FS) based file backend.
Definition: FSFileBackend.php:41
wfBaseConvert
wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true, $engine='auto')
Convert an arbitrarily-long digit string from one numeric base to another, optionally zero-padding to...
Definition: GlobalFunctions.php:3368
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:77