5 protected function setUp() {
9 'wgForceUIMsgAsContentMsg' => [],
21 $this->assertEquals( $key, $message->getKey() );
22 $this->assertEquals(
$params, $message->getParams() );
23 $this->assertEquals( $expectedLang, $message->getLanguage() );
25 $messageSpecifier = $this->getMockForAbstractClass(
'MessageSpecifier' );
26 $messageSpecifier->expects( $this->any() )
27 ->method(
'getKey' )->will( $this->returnValue( $key ) );
28 $messageSpecifier->expects( $this->any() )
29 ->method(
'getParams' )->will( $this->returnValue(
$params ) );
30 $message =
new Message( $messageSpecifier, [], $language );
32 $this->assertEquals( $key, $message->getKey() );
33 $this->assertEquals(
$params, $message->getParams() );
34 $this->assertEquals( $expectedLang, $message->getLanguage() );
42 [ $langDe,
'foo', [], $langDe ],
43 [ $langDe,
'foo', [
'bar' ], $langDe ],
44 [ $langEn,
'foo', [
'bar' ], null ]
72 [ [
'baz',
'foo' ],
'hhh' ],
76 [ [
'baz',
'foo' ],
'hhh', [
'ahahahahha' ] ],
80 [ [
'baz',
'foo' ], [
'ahahahahha' ] ],
84 [ [
'baz' ], [
'ahahahahha' ] ],
95 $msg =
new Message(
'imasomething' );
97 $returned = call_user_func_array( [ $msg,
'params' ],
$args );
99 $this->assertSame( $msg, $returned );
100 $this->assertEquals( $expected, $msg->getParams() );
105 [
'foo', [
'bar' ],
'en' ],
106 [
'foo', [
'bar' ],
'de' ]
119 $this->assertEquals( $language, $message->getLanguage() );
126 'expected' => [
'mainpage' ],
129 'key' => [
'mainpage' ],
130 'expected' => [
'mainpage' ],
133 'key' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
134 'expected' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
139 'exception' =>
'InvalidArgumentException',
144 'exception' =>
'InvalidArgumentException',
149 'exception' =>
'InvalidArgumentException',
161 public function testKeys( $key, $expected, $exception = null ) {
163 $this->setExpectedException( $exception );
167 $this->assertContains( $msg->getKey(), $expected );
168 $this->assertEquals( $expected, $msg->getKeysToTry() );
169 $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() );
176 $this->assertInstanceOf(
'Message',
wfMessage(
'mainpage' ) );
177 $this->assertInstanceOf(
'Message',
wfMessage(
'i-dont-exist-evar' ) );
193 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto' )->
text() );
194 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto', [] )->
text() );
196 'You have foo (bar).',
200 'You have foo (bar).',
209 $this->assertTrue(
wfMessage(
'mainpage' )->exists() );
210 $this->assertTrue(
wfMessage(
'mainpage' )->params( [] )->exists() );
211 $this->assertTrue(
wfMessage(
'mainpage' )->rawParams(
'foo', 123 )->exists() );
212 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->exists() );
213 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->params( [] )->exists() );
214 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->rawParams(
'foo', 123 )->exists() );
225 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->
text() );
226 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->
text() );
227 $this->assertEquals(
'⧼i<dont>exist-evar⧽',
wfMessage(
'i<dont>exist-evar' )->
text() );
228 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->plain() );
229 $this->assertEquals(
'⧼i<dont>exist-evar⧽',
wfMessage(
'i<dont>exist-evar' )->plain() );
230 $this->assertEquals(
'⧼i-dont-exist-evar⧽',
wfMessage(
'i-dont-exist-evar' )->escaped() );
232 '⧼i<dont>exist-evar⧽',
233 wfMessage(
'i<dont>exist-evar' )->escaped()
239 [
'mainpage',
'Main Page' ],
240 [
'i-dont-exist-evar',
'⧼i-dont-exist-evar⧽' ],
241 [
'i-dont-exist-evar',
'⧼i-dont-exist-evar⧽',
'escaped' ],
242 [
'script>alert(1)</script',
'⧼script>alert(1)</script⧽',
'escaped' ],
243 [
'script>alert(1)</script',
'⧼script>alert(1)</script⧽' ],
255 $this->assertEquals( $expect, $msg->toString() );
256 $this->assertEquals( $expect, $msg->__toString() );
263 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->inLanguage(
'en' )->
text() );
264 $this->assertEquals(
'Заглавная страница',
269 $this->assertEquals(
'Main Page', $msg->inLanguage(
Language::factory(
'en' ) )->text() );
271 'Заглавная страница',
282 '(Заглавная страница)',
283 wfMessage(
'parentheses',
'Заглавная страница' )->plain()
286 '(Заглавная страница $1)',
287 wfMessage(
'parentheses',
'Заглавная страница $1' )->plain()
290 '(Заглавная страница)',
291 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница' )->plain()
294 '(Заглавная страница $1)',
295 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница $1' )->plain()
305 $this->assertEquals(
'example &', $msg->plain() );
306 $this->assertEquals(
'example &', $msg->escaped() );
315 $msg =
new RawMessage(
'$1$2$3$4$5$6$7$8$9$10$11$12' );
317 $params = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k' ];
320 $msg->params(
$params )->plain(),
321 'Params > 9 are replaced correctly'
325 $params = [
'ab',
'bc',
'cd' ];
327 'Params: ab, bc, cd',
328 $msg->params(
$params )->text()
341 $lang->formatNum( 123456.789 ),
342 $msg->inLanguage(
$lang )->numParams( 123456.789 )->plain(),
343 'numParams is handled correctly'
356 $lang->formatDuration( 1234 ),
357 $msg->inLanguage(
$lang )->durationParams( 1234 )->plain(),
358 'durationParams is handled correctly'
375 'expiryParams is handled correctly'
388 $lang->formatTimePeriod( 1234 ),
389 $msg->inLanguage(
$lang )->timeperiodParams( 1234 )->plain(),
390 'timeperiodParams is handled correctly'
403 $lang->formatSize( 123456 ),
404 $msg->inLanguage(
$lang )->sizeParams( 123456 )->plain(),
405 'sizeParams is handled correctly'
418 $lang->formatBitrate( 123456 ),
419 $msg->inLanguage(
$lang )->bitrateParams( 123456 )->plain(),
420 'bitrateParams is handled correctly'
427 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
433 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
438 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
443 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
448 "<p>one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;\n</p>",
469 '<div>foo</div> [[Bar]] {{Baz}} <',
473 $msg->inLanguage(
$lang )->plaintextParams(
$params )->$format(),
474 "Fail formatting for $format"
481 "''&'' <x><!-- x -->",
486 "''&'' <x><!-- x -->",
490 '<i>&</i> <x>',
495 "<p><i>&</i> <x>\n</p>",
511 $msg =
new RawMessage(
"''&'' <x><!-- x -->" );
514 $msg->inLanguage(
'en' )->$format()
526 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
527 $this->assertEquals(
'Main Page', $msg->inContentLanguage()->plain(),
"inContentLanguage()" );
528 $this->assertEquals(
'Accueil', $msg->inLanguage(
'fr' )->plain(),
"inLanguage( 'fr' )" );
536 'wgForceUIMsgAsContentMsg' => [
'mainpage' ],
545 $msg->inContentLanguage()->plain(),
546 'inContentLanguage() with ForceUIMsg override enabled'
548 $this->assertEquals(
'Main Page', $msg->inLanguage(
'en' )->plain(),
"inLanguage( 'en' )" );
551 $msg->inContentLanguage()->plain(),
552 'inContentLanguage() with ForceUIMsg override enabled'
554 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
570 $msg =
new Message(
'parentheses' );
571 $msg->rawParams(
'<a>foo</a>' );
573 $this->assertEquals(
'(<a>foo</a>)', $msg->parse(),
'Sanity check' );
575 $this->assertEquals(
'(<a>foo</a>)', $msg->parse() );
577 $this->assertInstanceOf(
'Title', $title );
578 $this->assertEquals(
'Testing', $title->getFullText() );
580 $msg =
new Message(
'mainpage' );
581 $msg->inLanguage(
'de' );
582 $this->assertEquals(
'Hauptseite', $msg->plain(),
'Sanity check' );
584 $this->assertEquals(
'Hauptseite', $msg->plain() );
595 $this->assertInstanceOf( get_class(
$value ), $message );
596 $this->assertEquals(
$value, $message );
598 $this->assertSame( $expectedText, $message->text() );
603 $messageSpecifier->expects( $this->any() )->method(
'getKey' )->willReturn(
'mainpage' );
604 $messageSpecifier->expects( $this->any() )->method(
'getParams' )->willReturn( [] );
607 'string' => [
'mainpage',
'Main Page' ],
608 'array' => [ [
'youhavenewmessages',
'foo',
'bar' ],
'You have foo (bar).' ],
609 'Message' => [
new Message(
'youhavenewmessages', [
'foo',
'bar' ] ),
'You have foo (bar).' ],
610 'RawMessage' => [
new RawMessage(
'foo ($1)', [
'bar' ] ),
'foo (bar)' ],
611 'ApiMessage' => [
new ApiMessage( [
'mainpage' ],
'code', [
'data' ] ),
'Main Page' ],
612 'MessageSpecifier' => [ $messageSpecifier,
'Main Page' ],
613 'nested RawMessage' => [ [
new RawMessage(
'foo ($1)', [
'bar' ] ) ],
'foo (bar)' ],
testSerialization()
Message::serialize Message::unserialize.
testExists()
Message::exists.
The Message class provides methods which fulfil two basic services:
testDurationParams()
Message::durationParam Message::durationParams.
if(!isset($args[0])) $lang
testNewFromKey()
Message::newFromKey.
testToStringKey()
Message::__construct Message::text Message::plain Message::escaped Message::toString.
testConstructorParams($expected, $args)
Message::__construct Message::getParams provideConstructorParams.
testInContentLanguage()
Message::inContentLanguage.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
testInLanguage()
Message::inLanguage.
testInLanguageThrows()
MWException Message::inLanguage.
testNewFromSpecifier($value, $expectedText)
Message::newFromSpecifier provideNewFromSpecifier.
testSizeParams()
Message::sizeParam Message::sizeParams.
testRawMessage()
RawMessage::__construct RawMessage::fetchMessage.
static provideConstructorLanguage()
testPlaintextParams($expect, $format)
Message::plaintextParam Message::plaintextParams Message::formatPlaintext Message::toString Message::...
testToString($key, $expect, $format= 'plain')
Message::toString Message::__toString provideToString.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static provideConstructor()
Extension of Message implementing IApiMessage.
provideNewFromSpecifier()
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned after processing after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock()-offset Set to overwrite offset parameter in $wgRequest set to ''to unsetoffset-wrap String Wrap the message in html(usually something like"<
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $title
testParser($expect, $format)
Message::text Message::parse Message::parseAsBlock Message::toString Message::transformText Message::...
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
testNumParams()
Message::numParam Message::numParams.
static newFromKey($key)
Factory function that is just wrapper for the real constructor.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
testTimeperiodParams()
Message::timeperiodParam Message::timeperiodParams.
testReplaceManyParams()
Message::params Message::toString Message::replaceParameters.
testConstructor($expectedLang, $key, $params, $language)
Message::__construct provideConstructor.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
testRawParams()
Message::rawParam Message::rawParams.
Variant of the Message class.
testBitrateParams()
Message::bitrateParam Message::bitrateParams.
testKeys($key, $expected, $exception=null)
Message::__construct Message::getKey Message::isMultiKey Message::getKeysToTry provideKeys.
static providePlaintextParams()
static provideConstructorParams()
testExpiryParams()
FIXME: This should not need database, but Language::formatExpiry does (bug 55912) Database Message::e...
static newFromObject($object)
Return the same object, without access restrictions.
static factory($code)
Get a cached or new language object for a given language code.
testInContentLanguageOverride()
Message::inContentLanguage.
testConstructorLanguage($key, $params, $languageCode)
Message::__construct Message::getLanguage provideConstructorLanguage.
testWfMessageParams()
wfMessage Message::__construct
static newFromSpecifier($value)
Transform a MessageSpecifier or a primitive value used interchangeably with specifiers (a message key...