+ // Figure out which server to use
+ if ( $this->hasOption( 'slave' ) ) {
+ $server = $this->getOption( 'slave' );
+ if ( $server === 'any' ) {
+ $index = DB_SLAVE;
+ } else {
+ $index = null;
+ for ( $i = 0; $i < $lb->getServerCount(); ++$i ) {
+ if ( $lb->getServerName( $i ) === $server ) {
+ $index = $i;
+ break;
+ }
+ }
+ if ( $index === null ) {
+ $this->error( "No slave server configured with the name '$server'.", 1 );
+ }
+ }
+ } else {
+ $index = DB_MASTER;
+ }
+ // Get a DB handle (with this wiki's DB selected) from the appropriate load balancer
+ $db = $lb->getConnection( $index, array(), $wiki );
+ if ( $this->hasOption( 'slave' ) && $db->getLBInfo( 'master' ) !== null ) {
+ $this->error( "The server selected ({$db->getServer()}) is not a slave.", 1 );
+ }
+