Fixed passing of parameter array to wfMessage()
authorMax Semenik <maxsem@users.mediawiki.org>
Tue, 16 Nov 2010 20:40:20 +0000 (20:40 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Tue, 16 Nov 2010 20:40:20 +0000 (20:40 +0000)
includes/GlobalFunctions.php
maintenance/tests/phpunit/includes/MessageTest.php

index 78def7d..a7d91a2 100644 (file)
@@ -609,6 +609,9 @@ function wfUILang() {
 function wfMessage( $key /*...*/) {
        $params = func_get_args();
        array_shift( $params );
+       if ( isset( $params[0] ) && is_array( $params[0] ) ) {
+               $params = $params[0];
+       }
        return new Message( $key, $params );
 }
 
@@ -1234,23 +1237,28 @@ function wfNumLink( $offset, $limit, $title, $query = '' ) {
  * @return bool Whereas client accept gzip compression
  */
 function wfClientAcceptsGzip() {
-       if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
-               # FIXME: we may want to blacklist some broken browsers
-               $m = array();
-               if( preg_match(
-                       '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
-                       $_SERVER['HTTP_ACCEPT_ENCODING'],
-                       $m )
-               )
-               {
-                       if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) {
-                               return false;
+       static $result = null;
+       if ( $result === null ) {
+               $result = false;
+               if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
+                       # FIXME: we may want to blacklist some broken browsers
+                       $m = array();
+                       if( preg_match(
+                               '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
+                               $_SERVER['HTTP_ACCEPT_ENCODING'],
+                               $m )
+                       )
+                       {
+                               if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) {
+                                       $result = false;
+                                       return $result;
+                               }
+                               wfDebug( " accepts gzip\n" );
+                               $result = true;
                        }
-                       wfDebug( " accepts gzip\n" );
-                       return true;
                }
        }
-       return false;
+       return $result;
 }
 
 /**
index 65c368a..22d7363 100644 (file)
@@ -34,6 +34,13 @@ class MessageTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
        }
 
+       function testMessagePararms() {
+               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
+               $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
+               $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
+               $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
+       }
+
        /**
         * @expectedException MWException
         */