(bug 6040) Run pre-save transform before calculating the diff. when doing a "show...
[mediawiki.git] / includes / ExternalStore.php
blob79f1a5289e099861194ed64591504355ab230f28
1 <?php
2 /**
4 * @package MediaWiki
6 * Constructor class for data kept in external repositories
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)
14 class ExternalStore {
15 /* Fetch data from given URL */
16 function fetchFromURL($url) {
17 global $wgExternalStores;
19 if (!$wgExternalStores)
20 return false;
22 @list($proto,$path)=explode('://',$url,2);
23 /* Bad URL */
24 if ($path=="")
25 return false;
27 $store =& ExternalStore::getStoreObject( $proto );
28 if ( $store === false )
29 return false;
30 return $store->fetchFromURL($url);
33 /**
34 * Get an external store object of the given type
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;
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;
50 $store=new $class();
51 return $store;
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
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 );