Follow up r86447. Support the $wiki parameter
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index c88c89a..8460c8a 100644 (file)
@@ -590,8 +590,11 @@ function wfMsgNoDB( $key ) {
 
 /**
  * Get a message from the language file, for the content
+ *
+ * @deprecated in 1.18; use wfMessage()
  */
 function wfMsgNoDBForContent( $key ) {
+       wfDeprecated( __FUNCTION__ );
        global $wgForceUIMsgAsContentMsg;
        $args = func_get_args();
        array_shift( $args );
@@ -629,6 +632,7 @@ function wfMsgReal( $key, $args, $useDB = true, $forContent = false, $transform
  * @param $key String
  */
 function wfMsgWeirdKey( $key ) {
+       wfDeprecated( __FUNCTION__ );
        $source = wfMsgGetKey( $key, false, true, false );
        if ( wfEmptyMsg( $key ) ) {
                return '';
@@ -1777,6 +1781,10 @@ function wfSuppressWarnings( $end = false ) {
                }
        } else {
                if ( !$suppressCount ) {
+                       // E_DEPRECATED is undefined in PHP 5.2
+                       if( !defined( 'E_DEPRECATED' ) ){
+                               define( 'E_DEPRECATED', 8192 );
+                       }
                        $originalLevel = error_reporting( E_ALL & ~( E_WARNING | E_NOTICE | E_USER_WARNING | E_USER_NOTICE | E_DEPRECATED ) );
                }
                ++$suppressCount;
@@ -3138,34 +3146,24 @@ function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
 }
 
 /**
- * Sleep until the worst slave's replication lag is less than or equal to
- * $maxLag, in seconds.  Use this when updating very large numbers of rows, as
+ * Modern version of wfWaitForSlaves(). Instead of looking at replication lag
+ * and waiting for it to go down, this waits for the slaves to catch up to the
+ * master position. Use this when updating very large numbers of rows, as
  * in maintenance scripts, to avoid causing too much lag.  Of course, this is
  * a no-op if there are no slaves.
- *
- * Every time the function has to wait for a slave, it will print a message to
- * that effect (and then sleep for a little while), so it's probably not best
- * to use this outside maintenance scripts in its present form.
- *
- * @param $maxLag Integer
+ * 
+ * @param $maxLag Integer (deprecated)
  * @param $wiki mixed Wiki identifier accepted by wfGetLB
  * @return null
  */
-function wfWaitForSlaves( $maxLag, $wiki = false ) {
-       if( $maxLag ) {
-               $lb = wfGetLB( $wiki );
-               list( $host, $lag ) = $lb->getMaxLag( $wiki );
-               while( $lag > $maxLag ) {
-                       wfSuppressWarnings();
-                       $name = gethostbyaddr( $host );
-                       wfRestoreWarnings();
-                       if( $name !== false ) {
-                               $host = $name;
-                       }
-                       print "Waiting for $host (lagged $lag seconds)...\n";
-                       sleep( $maxLag );
-                       list( $host, $lag ) = $lb->getMaxLag();
-               }
+function wfWaitForSlaves( $maxLag = false, $wiki = false ) {
+       $lb = wfGetLB( $wiki );
+       // bug 27975 - Don't try to wait for slaves if there are none
+       // Prevents permission error when getting master position
+       if ( $lb->getServerCount() > 1 ) {
+               $dbw = $lb->getConnection( DB_MASTER );
+               $pos = $dbw->getMasterPos();
+               $lb->waitForAll( $pos );
        }
 }