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