Minor logic error on removing blocks on range when tweaking an IP.
[mediawiki.git] / includes / ExternalStore.php
blob457f00aa9b55d8976e265d866004c84c1a58f961
1 <?php
2 /**
3 * @defgroup ExternalStorage ExternalStorage
4 */
6 /**
7 * Constructor class for data kept in external repositories
9 * External repositories might be populated by maintenance/async
10 * scripts, thus partial moving of data may be possible, as well
11 * as possibility to have any storage format (i.e. for archives)
13 * @ingroup ExternalStorage
15 class ExternalStore {
16 /* Fetch data from given URL */
17 static function fetchFromURL($url) {
18 global $wgExternalStores;
20 if (!$wgExternalStores)
21 return false;
23 @list($proto,$path)=explode('://',$url,2);
24 /* Bad URL */
25 if ($path=="")
26 return false;
28 $store =& ExternalStore::getStoreObject( $proto );
29 if ( $store === false )
30 return false;
31 return $store->fetchFromURL($url);
34 /**
35 * Get an external store object of the given type
37 static function &getStoreObject( $proto ) {
38 global $wgExternalStores;
39 if (!$wgExternalStores)
40 return false;
41 /* Protocol not enabled */
42 if (!in_array( $proto, $wgExternalStores ))
43 return false;
45 $class='ExternalStore'.ucfirst($proto);
46 /* Any custom modules should be added to $wgAutoLoadClasses for on-demand loading */
47 if (!class_exists($class)) {
48 return false;
50 $store=new $class();
51 return $store;
54 /**
55 * Store a data item to an external store, identified by a partial URL
56 * The protocol part is used to identify the class, the rest is passed to the
57 * class itself as a parameter.
58 * Returns the URL of the stored data item, or false on error
60 static function insert( $url, $data ) {
61 list( $proto, $params ) = explode( '://', $url, 2 );
62 $store =& ExternalStore::getStoreObject( $proto );
63 if ( $store === false ) {
64 return false;
65 } else {
66 return $store->store( $params, $data );