]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/getReplicaServer.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / maintenance / getReplicaServer.php
similarity index 50%
rename from maintenance/dumpSisterSites.php
rename to maintenance/getReplicaServer.php
index f5abcd1b812eea2d791704e4bc4a0d93135c9f28..6e0a1fec2d590a0b145ec44073b0911adab486ae 100644 (file)
@@ -1,10 +1,6 @@
 <?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;