<?php
/**
- * Quickie page name dump script for SisterSites usage.
- * http://www.eekim.com/cgi-bin/wiki.pl?SisterSites
- *
- * Copyright (C) 2006 Brion Vibber <brion@pobox.com>
- * http://www.mediawiki.org/
+ * Reports the hostname of a replica DB server.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
+ * @file
* @ingroup Maintenance
*/
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
-class DumpSisterSites extends Maintenance {
+/**
+ * Maintenance script that reports the hostname of a replica DB server.
+ *
+ * @ingroup Maintenance
+ */
+class GetSlaveServer extends Maintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Quickie page name dump script for SisterSites usage";
+ $this->addOption( "group", "Query group to check specifically" );
+ $this->addDescription( 'Report the hostname of a replica DB server' );
}
public function execute() {
- $dbr = wfGetDB( DB_SLAVE );
- $dbr->bufferResults( false );
- $result = $dbr->select( 'page',
- array( 'page_namespace', 'page_title' ),
- array( 'page_namespace' => NS_MAIN,
- 'page_is_redirect' => 0,
- ),
- __METHOD__ );
-
- foreach ( $result as $row ) {
- $title = Title::makeTitle( $row->page_namespace, $row->page_title );
- $url = $title->getFullUrl();
- $text = $title->getPrefixedText();
- $this->output( "$url $text\n" );
+ global $wgAllDBsAreLocalhost;
+ if ( $wgAllDBsAreLocalhost ) {
+ $host = 'localhost';
+ } elseif ( $this->hasOption( 'group' ) ) {
+ $db = $this->getDB( DB_REPLICA, $this->getOption( 'group' ) );
+ $host = $db->getServer();
+ } else {
+ $lb = wfGetLB();
+ $i = $lb->getReaderIndex();
+ $host = $lb->getServerName( $i );
}
+ $this->output( "$host\n" );
}
}
-$maintClass = "DumpSisterSites";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+$maintClass = "GetSlaveServer";
+require_once RUN_MAINTENANCE_IF_MAIN;