trailing whitespace removal
[lhc/web/wiklou.git] / includes / ExternalStore.php
1 <?php
2 /**
3 *
4 * @package MediaWiki
5 *
6 * Constructor class for data kept in external repositories
7 *
8 * External repositories might be populated by maintenance/async
9 * scripts, thus partial moving of data may be possible, as well
10 * as possibility to have any storage format (i.e. for archives)
11 *
12 */
13
14 class ExternalStore {
15 /* Fetch data from given URL */
16 function fetchFromURL($url) {
17 global $wgExternalStores;
18
19 if (!$wgExternalStores)
20 return false;
21
22 @list($proto,$path)=explode('://',$url,2);
23 /* Bad URL */
24 if ($path=="")
25 return false;
26
27 $store =& ExternalStore::getStoreObject( $proto );
28 if ( $store === false )
29 return false;
30 return $store->fetchFromURL($url);
31 }
32
33 /**
34 * Get an external store object of the given type
35 */
36 function &getStoreObject( $proto ) {
37 global $wgExternalStores;
38 if (!$wgExternalStores)
39 return false;
40 /* Protocol not enabled */
41 if (!in_array( $proto, $wgExternalStores ))
42 return false;
43
44 $class='ExternalStore'.ucfirst($proto);
45 /* Preloaded modules might exist, especially ones serving multiple protocols */
46 if (!class_exists($class)) {
47 if (!include_once($class.'.php'))
48 return false;
49 }
50 $store=new $class();
51 return $store;
52 }
53
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
59 */
60 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 );
67 }
68 }
69 }
70 ?>