* Added beginnings of WatchlistTicker extension. Works for most cases only,
[mediawiki.git] / includes / ExternalStore.php
blobfb66b6523927129d520280846b2677274da8056c
1 <?php
2 /**
5 * Constructor class for data kept in external repositories
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)
13 class ExternalStore {
14 /* Fetch data from given URL */
15 function fetchFromURL($url) {
16 global $wgExternalStores;
18 if (!$wgExternalStores)
19 return false;
21 @list($proto,$path)=explode('://',$url,2);
22 /* Bad URL */
23 if ($path=="")
24 return false;
26 $store =& ExternalStore::getStoreObject( $proto );
27 if ( $store === false )
28 return false;
29 return $store->fetchFromURL($url);
32 /**
33 * Get an external store object of the given type
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;
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;
49 $store=new $class();
50 return $store;
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
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 );