MediaWiki  1.23.8
ExternalStore.php
Go to the documentation of this file.
1 <?php
54  public static function getStoreObject( $proto, array $params = array() ) {
55  global $wgExternalStores;
56 
57  if ( !$wgExternalStores || !in_array( $proto, $wgExternalStores ) ) {
58  return false; // protocol not enabled
59  }
60 
61  $class = 'ExternalStore' . ucfirst( $proto );
62 
63  // Any custom modules should be added to $wgAutoLoadClasses for on-demand loading
64  return class_exists( $class ) ? new $class( $params ) : false;
65  }
66 
75  public static function fetchFromURL( $url, array $params = array() ) {
76  $parts = explode( '://', $url, 2 );
77  if ( count( $parts ) != 2 ) {
78  return false; // invalid URL
79  }
80 
81  list( $proto, $path ) = $parts;
82  if ( $path == '' ) { // bad URL
83  return false;
84  }
85 
86  $store = self::getStoreObject( $proto, $params );
87  if ( $store === false ) {
88  return false;
89  }
90 
91  return $store->fetchFromURL( $url );
92  }
93 
101  public static function batchFetchFromURLs( array $urls ) {
102  $batches = array();
103  foreach ( $urls as $url ) {
104  $scheme = parse_url( $url, PHP_URL_SCHEME );
105  if ( $scheme ) {
106  $batches[$scheme][] = $url;
107  }
108  }
109  $retval = array();
110  foreach ( $batches as $proto => $batchedUrls ) {
111  $store = self::getStoreObject( $proto );
112  if ( $store === false ) {
113  continue;
114  }
115  $retval += $store->batchFetchFromURLs( $batchedUrls );
116  }
117  // invalid, not found, db dead, etc.
118  $missing = array_diff( $urls, array_keys( $retval ) );
119  if ( $missing ) {
120  foreach ( $missing as $url ) {
121  $retval[$url] = false;
122  }
123  }
124 
125  return $retval;
126  }
127 
139  public static function insert( $url, $data, array $params = array() ) {
140  $parts = explode( '://', $url, 2 );
141  if ( count( $parts ) != 2 ) {
142  return false; // invalid URL
143  }
144 
145  list( $proto, $path ) = $parts;
146  if ( $path == '' ) { // bad URL
147  return false;
148  }
149 
150  $store = self::getStoreObject( $proto, $params );
151  if ( $store === false ) {
152  return false;
153  } else {
154  return $store->store( $path, $data );
155  }
156  }
157 
169  public static function insertToDefault( $data, array $params = array() ) {
170  global $wgDefaultExternalStore;
171 
172  return self::insertWithFallback( (array)$wgDefaultExternalStore, $data, $params );
173  }
174 
187  public static function insertWithFallback( array $tryStores, $data, array $params = array() ) {
188  $error = false;
189  while ( count( $tryStores ) > 0 ) {
190  $index = mt_rand( 0, count( $tryStores ) - 1 );
191  $storeUrl = $tryStores[$index];
192  wfDebug( __METHOD__ . ": trying $storeUrl\n" );
193  list( $proto, $path ) = explode( '://', $storeUrl, 2 );
194  $store = self::getStoreObject( $proto, $params );
195  if ( $store === false ) {
196  throw new MWException( "Invalid external storage protocol - $storeUrl" );
197  }
198  try {
199  $url = $store->store( $path, $data ); // Try to save the object
200  } catch ( MWException $error ) {
201  $url = false;
202  }
203  if ( strlen( $url ) ) {
204  return $url; // Done!
205  } else {
206  unset( $tryStores[$index] ); // Don't try this one again!
207  $tryStores = array_values( $tryStores ); // Must have consecutive keys
208  wfDebugLog( 'ExternalStorage',
209  "Unable to store text to external storage $storeUrl" );
210  }
211  }
212  // All stores failed
213  if ( $error ) {
214  throw $error; // rethrow the last error
215  } else {
216  throw new MWException( "Unable to store text to external storage" );
217  }
218  }
219 
226  public static function insertToForeignDefault( $data, $wiki ) {
227  return self::insertToDefault( $data, array( 'wiki' => $wiki ) );
228  }
229 }
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
wfDebugLog
wfDebugLog( $logGroup, $text, $dest='all')
Send a line to a supplementary debug log file, if configured, or main debug log if not.
Definition: GlobalFunctions.php:1040
ExternalStore\insertWithFallback
static insertWithFallback(array $tryStores, $data, array $params=array())
Like insert() above, but does more of the work for us.
Definition: ExternalStore.php:187
$params
$params
Definition: styleTest.css.php:40
ExternalStore\insert
static insert( $url, $data, array $params=array())
Store a data item to an external store, identified by a partial URL The protocol part is used to iden...
Definition: ExternalStore.php:139
MWException
MediaWiki exception.
Definition: MWException.php:26
ExternalStore\insertToDefault
static insertToDefault( $data, array $params=array())
Like insert() above, but does more of the work for us.
Definition: ExternalStore.php:169
ExternalStore
Constructor class for key/value blob data kept in external repositories.
Definition: ExternalStore.php:46
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
list
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
ExternalStore\getStoreObject
static getStoreObject( $proto, array $params=array())
Get an external store object of the given type, with the given parameters.
Definition: ExternalStore.php:54
wfDebug
wfDebug( $text, $dest='all')
Sends a line to the debug log if enabled or, optionally, to a comment in output.
Definition: GlobalFunctions.php:933
ExternalStore\fetchFromURL
static fetchFromURL( $url, array $params=array())
Fetch data from given URL.
Definition: ExternalStore.php:75
$path
$path
Definition: NoLocalSettings.php:35
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
$error
usually copyright or history_copyright This message must be in HTML not wikitext $subpages will be ignored and the rest of subPageSubtitle() will run. 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink' whether MediaWiki currently thinks this is a CSS JS page Hooks may change this value to override the return value of Title::isCssOrJsPage(). 'TitleIsAlwaysKnown' whether MediaWiki currently thinks this page is known isMovable() always returns false. $title whether MediaWiki currently thinks this page is movable Hooks may change this value to override the return value of Title::isMovable(). 'TitleIsWikitextPage' whether MediaWiki currently thinks this is a wikitext page Hooks may change this value to override the return value of Title::isWikitextPage() 'TitleMove' use UploadVerification and UploadVerifyFile instead where the first element is the message key and the remaining elements are used as parameters to the message based on mime etc Preferred in most cases over UploadVerification object with all info about the upload string as detected by MediaWiki Handlers will typically only apply for specific mime types object & $error
Definition: hooks.txt:2573
ExternalStore\batchFetchFromURLs
static batchFetchFromURLs(array $urls)
Fetch data from multiple URLs with a minimum of round trips.
Definition: ExternalStore.php:101
ExternalStore\insertToForeignDefault
static insertToForeignDefault( $data, $wiki)
Definition: ExternalStore.php:226
$retval
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account incomplete not yet checked for validity & $retval
Definition: hooks.txt:237