Merge "Add Turoyo (tru) language to MediaWiki"
[lhc/web/wiklou.git] / includes / db / LBFactory_Multi.php
index 820aa2e..6008813 100644 (file)
@@ -1,5 +1,22 @@
 <?php
 /**
+ * Advanced generator of database load balancing objects for wiki farms.
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
  * @file
  * @ingroup Database
  */
@@ -51,13 +68,16 @@ class LBFactory_Multi extends LBFactory {
        var $conf, $mainLBs = array(), $extLBs = array();
        var $lastWiki, $lastSection;
 
+       /**
+        * @param $conf array
+        */
        function __construct( $conf ) {
                $this->chronProt = new ChronologyProtector;
                $this->conf = $conf;
                $required = array( 'sectionsByDB', 'sectionLoads', 'serverTemplate' );
                $optional = array( 'groupLoadsBySection', 'groupLoadsByDB', 'hostsByName',
                        'externalLoads', 'externalTemplateOverrides', 'templateOverridesByServer',
-                       'templateOverridesByCluster', 'masterTemplateOverrides', 
+                       'templateOverridesByCluster', 'masterTemplateOverrides',
                        'readOnlyBySection' );
 
                foreach ( $required as $key ) {
@@ -81,11 +101,15 @@ class LBFactory_Multi extends LBFactory {
                }
        }
 
+       /**
+        * @param $wiki bool|string
+        * @return string
+        */
        function getSectionForWiki( $wiki = false ) {
                if ( $this->lastWiki === $wiki ) {
                        return $this->lastSection;
                }
-               list( $dbName, $prefix ) = $this->getDBNameAndPrefix( $wiki );
+               list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
                if ( isset( $this->sectionsByDB[$dbName] ) ) {
                        $section = $this->sectionsByDB[$dbName];
                } else {
@@ -96,8 +120,12 @@ class LBFactory_Multi extends LBFactory {
                return $section;
        }
 
+       /**
+        * @param $wiki bool|string
+        * @return LoadBalancer
+        */
        function newMainLB( $wiki = false ) {
-               list( $dbName, $prefix ) = $this->getDBNameAndPrefix( $wiki );
+               list( $dbName, ) = $this->getDBNameAndPrefix( $wiki );
                $section = $this->getSectionForWiki( $wiki );
                $groupLoads = array();
                if ( isset( $this->groupLoadsByDB[$dbName] ) ) {
@@ -109,6 +137,10 @@ class LBFactory_Multi extends LBFactory {
                return $this->newLoadBalancer( $this->serverTemplate, $this->sectionLoads[$section], $groupLoads );
        }
 
+       /**
+        * @param $wiki bool|string
+        * @return LoadBalancer
+        */
        function getMainLB( $wiki = false ) {
                $section = $this->getSectionForWiki( $wiki );
                if ( !isset( $this->mainLBs[$section] ) ) {
@@ -120,6 +152,11 @@ class LBFactory_Multi extends LBFactory {
                return $this->mainLBs[$section];
        }
 
+       /**
+        * @param $cluster
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function newExternalLB( $cluster, $wiki = false ) {
                if ( !isset( $this->externalLoads[$cluster] ) ) {
                        throw new MWException( __METHOD__.": Unknown cluster \"$cluster\"" );
@@ -134,6 +171,11 @@ class LBFactory_Multi extends LBFactory {
                return $this->newLoadBalancer( $template, $this->externalLoads[$cluster], array() );
        }
 
+       /**
+        * @param $cluster
+        * @param $wiki
+        * @return LoadBalancer
+        */
        function &getExternalLB( $cluster, $wiki = false ) {
                if ( !isset( $this->extLBs[$cluster] ) ) {
                        $this->extLBs[$cluster] = $this->newExternalLB( $cluster, $wiki );
@@ -144,19 +186,29 @@ class LBFactory_Multi extends LBFactory {
 
        /**
         * Make a new load balancer object based on template and load array
+        *
+        * @param $template
+        * @param $loads array
+        * @param $groupLoads
+        * @return LoadBalancer
         */
        function newLoadBalancer( $template, $loads, $groupLoads ) {
                global $wgMasterWaitTimeout;
                $servers = $this->makeServerArray( $template, $loads, $groupLoads );
                $lb = new LoadBalancer( array(
                        'servers' => $servers,
-                       'masterWaitTimeout' => $wgMasterWaitTimeout 
+                       'masterWaitTimeout' => $wgMasterWaitTimeout
                ));
                return $lb;
        }
 
        /**
         * Make a server array as expected by LoadBalancer::__construct, using a template and load array
+        *
+        * @param $template
+        * @param $loads array
+        * @param $groupLoads
+        * @return array
         */
        function makeServerArray( $template, $loads, $groupLoads ) {
                $servers = array();
@@ -196,6 +248,8 @@ class LBFactory_Multi extends LBFactory {
 
        /**
         * Take a group load array indexed by group then server, and reindex it by server then group
+        * @param $groupLoads
+        * @return array
         */
        function reindexGroupLoads( $groupLoads ) {
                $reindexed = array();
@@ -209,6 +263,8 @@ class LBFactory_Multi extends LBFactory {
 
        /**
         * Get the database name and prefix based on the wiki ID
+        * @param $wiki bool
+        * @return array
         */
        function getDBNameAndPrefix( $wiki = false ) {
                if ( $wiki === false ) {
@@ -223,6 +279,8 @@ class LBFactory_Multi extends LBFactory {
         * Execute a function for each tracked load balancer
         * The callback is called with the load balancer as the first parameter,
         * and $params passed as the subsequent parameters.
+        * @param $callback
+        * @param $params array
         */
        function forEachLB( $callback, $params = array() ) {
                foreach ( $this->mainLBs as $lb ) {