Further updates for r90643/r95647 in core and extensions. Fixed all callers of Databa...
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 29 Aug 2011 05:04:55 +0000 (05:04 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 29 Aug 2011 05:04:55 +0000 (05:04 +0000)
includes/db/Database.php
includes/db/LoadBalancer.php
includes/specials/SpecialContributions.php
includes/specials/SpecialDeletedContributions.php
includes/specials/SpecialWatchlist.php

index 6126b35..c5b58e5 100644 (file)
@@ -2980,8 +2980,12 @@ abstract class DatabaseBase implements DatabaseType {
        }
 
        /**
-        * Get slave lag.
-        * Currently supported only by MySQL
+        * Get slave lag. Currently supported only by MySQL.
+        *
+        * Note that this function will generate a fatal error on many 
+        * installations. Most callers should use LoadBalancer::safeGetLag() 
+        * instead.
+        *
         * @return Database replication lag in seconds
         */
        function getLag() {
index 55a6cee..da26417 100644 (file)
@@ -987,6 +987,25 @@ class LoadBalancer {
                return $this->mLagTimes;
        }
 
+       /**
+        * Get the lag in seconds for a given connection, or zero if this load 
+        * balancer does not have replication enabled. 
+        *
+        * This should be used in preference to Database::getLag() in cases where 
+        * replication may not be in use, since there is no way to determine if 
+        * replication is in use at the connection level without running 
+        * potentially restricted queries such as SHOW SLAVE STATUS. Using this
+        * function instead of Database::getLag() avoids a fatal error in this
+        * case on many installations.
+        */
+       function safeGetLag( $conn ) {
+               if ( $this->getServerCount() == 1 ) {
+                       return 0;
+               } else {
+                       return $conn->getLag();
+               }
+       }
+
        /**
         * Clear the cache for getLagTimes
         */
index d724cb4..497bd1c 100644 (file)
@@ -167,7 +167,8 @@ class SpecialContributions extends SpecialPage {
                                $wgOut->addWikiMsg( 'nocontribs', $target );
                        } else {
                                # Show a message about slave lag, if applicable
-                               if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
+                               $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+                               if( $lag > 0 )
                                        $wgOut->showLagWarning( $lag );
 
                                $wgOut->addHTML(
index e45e85f..265de42 100644 (file)
@@ -317,7 +317,8 @@ class DeletedContributionsPage extends SpecialPage {
                }
 
                # Show a message about slave lag, if applicable
-               if( ( $lag = $pager->getDatabase()->getLag() ) > 0 )
+               $lag = wfGetLB()->safeGetLag( $pager->getDatabase() );
+               if( $lag > 0 )
                        $wgOut->showLagWarning( $lag );
 
                $wgOut->addHTML(
index fb57baa..51086bb 100644 (file)
@@ -240,7 +240,7 @@ class SpecialWatchlist extends SpecialPage {
                }
 
                # Show a message about slave lag, if applicable
-               $lag = $dbr->getLag();
+               $lag = wfGetLB()->safeGetLag( $dbr );
                if( $lag > 0 ) {
                        $output->showLagWarning( $lag );
                }