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 );
}
* @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;
}
/**
$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
*/