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