From 269c58210a5b678704f560a4275d8fbf0177d078 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Tue, 16 Nov 2010 20:40:20 +0000 Subject: [PATCH] Fixed passing of parameter array to wfMessage() --- includes/GlobalFunctions.php | 36 +++++++++++-------- .../tests/phpunit/includes/MessageTest.php | 7 ++++ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 78def7db01..a7d91a25c1 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; } /** diff --git a/maintenance/tests/phpunit/includes/MessageTest.php b/maintenance/tests/phpunit/includes/MessageTest.php index 65c368aa46..22d736369b 100644 --- a/maintenance/tests/phpunit/includes/MessageTest.php +++ b/maintenance/tests/phpunit/includes/MessageTest.php @@ -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 */ -- 2.20.1