Use Doxygen @addtogroup instead of phpdoc @package && @subpackage
[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 /* Preloaded modules might exist, especially ones serving multiple protocols */
45 if (!class_exists($class)) {
46 if (!include_once($class.'.php'))
47 return false;
48 }
49 $store=new $class();
50 return $store;
51 }
52
53 /**
54 * Store a data item to an external store, identified by a partial URL
55 * The protocol part is used to identify the class, the rest is passed to the
56 * class itself as a parameter.
57 * Returns the URL of the stored data item, or false on error
58 */
59 function insert( $url, $data ) {
60 list( $proto, $params ) = explode( '://', $url, 2 );
61 $store =& ExternalStore::getStoreObject( $proto );
62 if ( $store === false ) {
63 return false;
64 } else {
65 return $store->store( $params, $data );
66 }
67 }
68 }
69 ?>