r76833 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r76832‎ | r76833 | r76834 >
Date:20:40, 16 November 2010
Author:maxsem
Status:ok (Comments)
Tags:
Comment:
Fixed passing of parameter array to wfMessage()
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/maintenance/tests/phpunit/includes/MessageTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/tests/phpunit/includes/MessageTest.php
@@ -34,6 +34,13 @@
3535 $this->assertEquals( 'Заглавная страница', wfMessage( 'mainpage' )->inLanguage( Language::factory( 'ru' ) )->text() );
3636 }
3737
 38+ function testMessagePararms() {
 39+ $this->assertEquals( 'Return to $1.', wfMessage( 'returnto' )->text() );
 40+ $this->assertEquals( 'Return to $1.', wfMessage( 'returnto', array() )->text() );
 41+ $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', 'foo', 'bar' )->text() );
 42+ $this->assertEquals( 'You have foo (bar).', wfMessage( 'youhavenewmessages', array( 'foo', 'bar' ) )->text() );
 43+ }
 44+
3845 /**
3946 * @expectedException MWException
4047 */
Index: trunk/phase3/includes/GlobalFunctions.php
@@ -609,6 +609,9 @@
610610 function wfMessage( $key /*...*/) {
611611 $params = func_get_args();
612612 array_shift( $params );
 613+ if ( isset( $params[0] ) && is_array( $params[0] ) ) {
 614+ $params = $params[0];
 615+ }
613616 return new Message( $key, $params );
614617 }
615618
@@ -1234,23 +1237,28 @@
12351238 * @return bool Whereas client accept gzip compression
12361239 */
12371240 function wfClientAcceptsGzip() {
1238 - if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
1239 - # FIXME: we may want to blacklist some broken browsers
1240 - $m = array();
1241 - if( preg_match(
1242 - '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
1243 - $_SERVER['HTTP_ACCEPT_ENCODING'],
1244 - $m )
1245 - )
1246 - {
1247 - if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) {
1248 - return false;
 1241+ static $result = null;
 1242+ if ( $result === null ) {
 1243+ $result = false;
 1244+ if( isset( $_SERVER['HTTP_ACCEPT_ENCODING'] ) ) {
 1245+ # FIXME: we may want to blacklist some broken browsers
 1246+ $m = array();
 1247+ if( preg_match(
 1248+ '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
 1249+ $_SERVER['HTTP_ACCEPT_ENCODING'],
 1250+ $m )
 1251+ )
 1252+ {
 1253+ if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) {
 1254+ $result = false;
 1255+ return $result;
 1256+ }
 1257+ wfDebug( " accepts gzip\n" );
 1258+ $result = true;
12491259 }
1250 - wfDebug( " accepts gzip\n" );
1251 - return true;
12521260 }
12531261 }
1254 - return false;
 1262+ return $result;
12551263 }
12561264
12571265 /**

Comments

#Comment by Nikerabbit (talk | contribs)   09:06, 17 November 2010

Shouldn't wfMessage also check that only one param is passed, in addition of it being an array?

What's the thing with wfClientAcceptsGzip?

#Comment by MaxSem (talk | contribs)   14:29, 17 November 2010

Whoops, didn't mean to commit the latter, but this change was ready for commit and tested. It cached the result of that function. Although the preformance gain is minimal, it prevents several "accepts gzip" lines from appearing in debug log.

Status & tagging log