From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/externalstore/ExternalStore.php | 57 +++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'includes/externalstore/ExternalStore.php') diff --git a/includes/externalstore/ExternalStore.php b/includes/externalstore/ExternalStore.php index 4ca193d4..462b0b90 100644 --- a/includes/externalstore/ExternalStore.php +++ b/includes/externalstore/ExternalStore.php @@ -60,7 +60,7 @@ class ExternalStore { $class = 'ExternalStore' . ucfirst( $proto ); // Any custom modules should be added to $wgAutoLoadClasses for on-demand loading - return MWInit::classExists( $class ) ? new $class( $params ) : false; + return class_exists( $class ) ? new $class( $params ) : false; } /** @@ -90,6 +90,39 @@ class ExternalStore { return $store->fetchFromURL( $url ); } + /** + * Fetch data from multiple URLs with a minimum of round trips + * + * @param array $urls The URLs of the text to get + * @return array Map from url to its data. Data is either string when found + * or false on failure. + */ + public static function batchFetchFromURLs( array $urls ) { + $batches = array(); + foreach ( $urls as $url ) { + $scheme = parse_url( $url, PHP_URL_SCHEME ); + if ( $scheme ) { + $batches[$scheme][] = $url; + } + } + $retval = array(); + foreach ( $batches as $proto => $batchedUrls ) { + $store = self::getStoreObject( $proto ); + if ( $store === false ) { + continue; + } + $retval += $store->batchFetchFromURLs( $batchedUrls ); + } + // invalid, not found, db dead, etc. + $missing = array_diff( $urls, array_keys( $retval ) ); + if ( $missing ) { + foreach ( $missing as $url ) { + $retval[$url] = false; + } + } + return $retval; + } + /** * Store a data item to an external store, identified by a partial URL * The protocol part is used to identify the class, the rest is passed to the @@ -123,9 +156,10 @@ class ExternalStore { /** * Like insert() above, but does more of the work for us. * This function does not need a url param, it builds it by - * itself. It also fails-over to the next possible clusters. + * itself. It also fails-over to the next possible clusters + * provided by $wgDefaultExternalStore. * - * @param $data string + * @param string $data * @param array $params Associative array of ExternalStoreMedium parameters * @return string|bool The URL of the stored data item, or false on error * @throws MWException @@ -133,8 +167,23 @@ class ExternalStore { public static function insertToDefault( $data, array $params = array() ) { global $wgDefaultExternalStore; + return self::insertWithFallback( (array)$wgDefaultExternalStore, $data, $params ); + } + + /** + * Like insert() above, but does more of the work for us. + * This function does not need a url param, it builds it by + * itself. It also fails-over to the next possible clusters + * as provided in the first parameter. + * + * @param array $tryStores refer to $wgDefaultExternalStore + * @param string $data + * @param array $params Associative array of ExternalStoreMedium parameters + * @return string|bool The URL of the stored data item, or false on error + * @throws MWException + */ + public static function insertWithFallback( array $tryStores, $data, array $params = array() ) { $error = false; - $tryStores = (array)$wgDefaultExternalStore; while ( count( $tryStores ) > 0 ) { $index = mt_rand( 0, count( $tryStores ) - 1 ); $storeUrl = $tryStores[$index]; -- cgit v1.2.3-54-g00ecf