Index: trunk/phase3/includes/ExternalStore.php |
— | — | @@ -13,8 +13,14 @@ |
14 | 14 | * @ingroup ExternalStorage |
15 | 15 | */ |
16 | 16 | class ExternalStore { |
| 17 | + var $mParams; |
| 18 | + |
| 19 | + function __construct( $params = array() ) { |
| 20 | + $this->mParams = $params; |
| 21 | + } |
| 22 | + |
17 | 23 | /* Fetch data from given URL */ |
18 | | - static function fetchFromURL( $url ) { |
| 24 | + static function fetchFromURL( $url, $params = array() ) { |
19 | 25 | global $wgExternalStores; |
20 | 26 | |
21 | 27 | if( !$wgExternalStores ) |
— | — | @@ -25,16 +31,16 @@ |
26 | 32 | if( $path == '' ) |
27 | 33 | return false; |
28 | 34 | |
29 | | - $store = self::getStoreObject( $proto ); |
| 35 | + $store = self::getStoreObject( $proto, $params ); |
30 | 36 | if ( $store === false ) |
31 | 37 | return false; |
32 | 38 | return $store->fetchFromURL( $url ); |
33 | 39 | } |
34 | 40 | |
35 | 41 | /** |
36 | | - * Get an external store object of the given type |
| 42 | + * Get an external store object of the given type, with the given parameters |
37 | 43 | */ |
38 | | - static function getStoreObject( $proto ) { |
| 44 | + static function getStoreObject( $proto, $params = array() ) { |
39 | 45 | global $wgExternalStores; |
40 | 46 | if( !$wgExternalStores ) |
41 | 47 | return false; |
— | — | @@ -48,7 +54,7 @@ |
49 | 55 | return false; |
50 | 56 | } |
51 | 57 | |
52 | | - return new $class(); |
| 58 | + return new $class($params); |
53 | 59 | } |
54 | 60 | |
55 | 61 | /** |
— | — | @@ -57,9 +63,9 @@ |
58 | 64 | * class itself as a parameter. |
59 | 65 | * Returns the URL of the stored data item, or false on error |
60 | 66 | */ |
61 | | - static function insert( $url, $data ) { |
| 67 | + static function insert( $url, $data, $params = array() ) { |
62 | 68 | list( $proto, $params ) = explode( '://', $url, 2 ); |
63 | | - $store = self::getStoreObject( $proto ); |
| 69 | + $store = self::getStoreObject( $proto, $params ); |
64 | 70 | if ( $store === false ) { |
65 | 71 | return false; |
66 | 72 | } else { |
— | — | @@ -73,9 +79,10 @@ |
74 | 80 | * itself. It also fails-over to the next possible clusters. |
75 | 81 | * |
76 | 82 | * @param string $data |
| 83 | + * @param array $params Associative array of parameters for the ExternalStore object. |
77 | 84 | * Returns the URL of the stored data item, or false on error |
78 | 85 | */ |
79 | | - public static function insertToDefault( $data ) { |
| 86 | + public static function insertToDefault( $data, $storageParams = array() ) { |
80 | 87 | global $wgDefaultExternalStore; |
81 | 88 | $tryStores = (array)$wgDefaultExternalStore; |
82 | 89 | $error = false; |
— | — | @@ -84,7 +91,7 @@ |
85 | 92 | $storeUrl = $tryStores[$index]; |
86 | 93 | wfDebug( __METHOD__.": trying $storeUrl\n" ); |
87 | 94 | list( $proto, $params ) = explode( '://', $storeUrl, 2 ); |
88 | | - $store = self::getStoreObject( $proto ); |
| 95 | + $store = self::getStoreObject( $proto, $storageParams ); |
89 | 96 | if ( $store === false ) { |
90 | 97 | throw new MWException( "Invalid external storage protocol - $storeUrl" ); |
91 | 98 | } |
— | — | @@ -111,4 +118,9 @@ |
112 | 119 | throw new MWException( "Unable to store text to external storage" ); |
113 | 120 | } |
114 | 121 | } |
| 122 | + |
| 123 | + /** Like insertToDefault, but inserts on another wiki */ |
| 124 | + public static function insertToForeignDefault( $data, $wiki ) { |
| 125 | + return self::insertToDefault( $data, array( 'wiki' => $wiki ) ); |
| 126 | + } |
115 | 127 | } |
Index: trunk/phase3/includes/ExternalStoreDB.php |
— | — | @@ -26,21 +26,29 @@ |
27 | 27 | */ |
28 | 28 | class ExternalStoreDB { |
29 | 29 | |
| 30 | + function __construct( $params = array() ) { |
| 31 | + $this->mParams = $params; |
| 32 | + } |
| 33 | + |
30 | 34 | /** @todo Document.*/ |
31 | 35 | function &getLoadBalancer( $cluster ) { |
32 | | - return wfGetLBFactory()->getExternalLB( $cluster ); |
| 36 | + $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false; |
| 37 | + |
| 38 | + return wfGetLBFactory()->getExternalLB( $cluster, $wiki ); |
33 | 39 | } |
34 | 40 | |
35 | 41 | /** @todo Document.*/ |
36 | 42 | function &getSlave( $cluster ) { |
| 43 | + $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false; |
37 | 44 | $lb =& $this->getLoadBalancer( $cluster ); |
38 | | - return $lb->getConnection( DB_SLAVE ); |
| 45 | + return $lb->getConnection( DB_SLAVE, array(), $wiki ); |
39 | 46 | } |
40 | 47 | |
41 | 48 | /** @todo Document.*/ |
42 | 49 | function &getMaster( $cluster ) { |
| 50 | + $wiki = isset($this->mParams['wiki']) ? $this->mParams['wiki'] : false; |
43 | 51 | $lb =& $this->getLoadBalancer( $cluster ); |
44 | | - return $lb->getConnection( DB_MASTER ); |
| 52 | + return $lb->getConnection( DB_MASTER, array(), $wiki ); |
45 | 53 | } |
46 | 54 | |
47 | 55 | /** @todo Document.*/ |