6 protected function setUp() {
10 'wgForceUIMsgAsContentMsg' => [],
22 $this->assertEquals(
$key, $message->getKey() );
23 $this->assertEquals(
$params, $message->getParams() );
24 $this->assertEquals( $expectedLang, $message->getLanguage() );
26 $messageSpecifier = $this->getMockForAbstractClass(
'MessageSpecifier' );
27 $messageSpecifier->expects( $this->any() )
28 ->method(
'getKey' )->will( $this->returnValue(
$key ) );
29 $messageSpecifier->expects( $this->any() )
30 ->method(
'getParams' )->will( $this->returnValue(
$params ) );
31 $message =
new Message( $messageSpecifier, [], $language );
33 $this->assertEquals(
$key, $message->getKey() );
34 $this->assertEquals(
$params, $message->getParams() );
35 $this->assertEquals( $expectedLang, $message->getLanguage() );
43 [ $langDe,
'foo', [], $langDe ],
44 [ $langDe,
'foo', [
'bar' ], $langDe ],
45 [ $langEn,
'foo', [
'bar' ], null ]
73 [ [
'baz',
'foo' ],
'hhh' ],
77 [ [
'baz',
'foo' ],
'hhh', [
'ahahahahha' ] ],
81 [ [
'baz',
'foo' ], [
'ahahahahha' ] ],
85 [ [
'baz' ], [
'ahahahahha' ] ],
96 $msg =
new Message(
'imasomething' );
98 $returned = call_user_func_array( [ $msg,
'params' ],
$args );
100 $this->assertSame( $msg, $returned );
101 $this->assertEquals( $expected, $msg->getParams() );
106 [
'foo', [
'bar' ],
'en' ],
107 [
'foo', [
'bar' ],
'de' ]
120 $this->assertEquals( $language, $message->getLanguage() );
127 'expected' => [
'mainpage' ],
130 'key' => [
'mainpage' ],
131 'expected' => [
'mainpage' ],
134 'key' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
135 'expected' => [
'mainpage-foo',
'mainpage-bar',
'mainpage' ],
140 'exception' =>
'InvalidArgumentException',
145 'exception' =>
'InvalidArgumentException',
150 'exception' =>
'InvalidArgumentException',
164 $this->setExpectedException( $exception );
168 $this->assertContains( $msg->getKey(), $expected );
169 $this->assertEquals( $expected, $msg->getKeysToTry() );
170 $this->assertEquals( count( $expected ) > 1, $msg->isMultiKey() );
177 $this->assertInstanceOf(
'Message',
wfMessage(
'mainpage' ) );
178 $this->assertInstanceOf(
'Message',
wfMessage(
'i-dont-exist-evar' ) );
194 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto' )->
text() );
195 $this->assertEquals(
'Return to $1.',
wfMessage(
'returnto', [] )->
text() );
197 'You have foo (bar).',
201 'You have foo (bar).',
210 $this->assertTrue(
wfMessage(
'mainpage' )->exists() );
211 $this->assertTrue(
wfMessage(
'mainpage' )->params( [] )->exists() );
212 $this->assertTrue(
wfMessage(
'mainpage' )->rawParams(
'foo', 123 )->exists() );
213 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->exists() );
214 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->params( [] )->exists() );
215 $this->assertFalse(
wfMessage(
'i-dont-exist-evar' )->rawParams(
'foo', 123 )->exists() );
226 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->
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' )->
text() );
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' )->plain() );
231 $this->assertEquals(
'<i-dont-exist-evar>',
wfMessage(
'i-dont-exist-evar' )->escaped() );
233 '<i<dont>exist-evar>',
234 wfMessage(
'i<dont>exist-evar' )->escaped()
240 [
'mainpage',
'Main Page' ],
241 [
'i-dont-exist-evar',
'<i-dont-exist-evar>' ],
242 [
'i-dont-exist-evar',
'<i-dont-exist-evar>',
'escaped' ],
254 $this->assertEquals( $expect, $msg->toString() );
255 $this->assertEquals( $expect, $msg->__toString() );
262 $this->assertEquals(
'Main Page',
wfMessage(
'mainpage' )->inLanguage(
'en' )->
text() );
263 $this->assertEquals(
'Заглавная страница',
268 $this->assertEquals(
'Main Page', $msg->inLanguage(
Language::factory(
'en' ) )->text() );
270 'Заглавная страница',
281 '(Заглавная страница)',
282 wfMessage(
'parentheses',
'Заглавная страница' )->plain()
285 '(Заглавная страница $1)',
286 wfMessage(
'parentheses',
'Заглавная страница $1' )->plain()
289 '(Заглавная страница)',
290 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница' )->plain()
293 '(Заглавная страница $1)',
294 wfMessage(
'parentheses' )->rawParams(
'Заглавная страница $1' )->plain()
304 $this->assertEquals(
'example &', $msg->plain() );
305 $this->assertEquals(
'example &', $msg->escaped() );
318 $msg =
new RawMessage(
'<html><script>alert("xss")</script></html>' );
319 $txt =
'<span class="error"><html> tags cannot be' .
320 ' used outside of normal pages.</span>';
321 $this->assertSame( $txt, $msg->parse() );
330 $msg =
new RawMessage(
'$1$2$3$4$5$6$7$8$9$10$11$12' );
332 $params = [
'a',
'b',
'c',
'd',
'e',
'f',
'g',
'h',
'i',
'j',
'k' ];
335 $msg->params(
$params )->plain(),
336 'Params > 9 are replaced correctly'
340 $params = [
'ab',
'bc',
'cd' ];
342 'Params: ab, bc, cd',
343 $msg->params(
$params )->text()
356 $lang->formatNum( 123456.789 ),
357 $msg->inLanguage(
$lang )->numParams( 123456.789 )->plain(),
358 'numParams is handled correctly'
371 $lang->formatDuration( 1234 ),
372 $msg->inLanguage(
$lang )->durationParams( 1234 )->plain(),
373 'durationParams is handled correctly'
390 'expiryParams is handled correctly'
403 $lang->formatTimePeriod( 1234 ),
404 $msg->inLanguage(
$lang )->timeperiodParams( 1234 )->plain(),
405 'timeperiodParams is handled correctly'
418 $lang->formatSize( 123456 ),
419 $msg->inLanguage(
$lang )->sizeParams( 123456 )->plain(),
420 'sizeParams is handled correctly'
433 $lang->formatBitrate( 123456 ),
434 $msg->inLanguage(
$lang )->bitrateParams( 123456 )->plain(),
435 'bitrateParams is handled correctly'
442 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
448 'one $2 <div>foo</div> [[Bar]] {{Baz}} <',
453 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
458 'one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;',
463 "<p>one $2 <div>foo</div> [[Bar]] {{Baz}} &lt;\n</p>",
484 '<div>foo</div> [[Bar]] {{Baz}} <',
488 $msg->inLanguage(
$lang )->plaintextParams(
$params )->$format(),
489 "Fail formatting for $format"
496 "''&'' <x><!-- x -->",
501 "''&'' <x><!-- x -->",
505 '<i>&</i> <x>',
510 "<p><i>&</i> <x>\n</p>",
526 $msg =
new RawMessage(
"''&'' <x><!-- x -->" );
529 $msg->inLanguage(
'en' )->$format()
541 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
542 $this->assertEquals(
'Main Page', $msg->inContentLanguage()->plain(),
"inContentLanguage()" );
543 $this->assertEquals(
'Accueil', $msg->inLanguage(
'fr' )->plain(),
"inLanguage( 'fr' )" );
551 'wgForceUIMsgAsContentMsg' => [
'mainpage' ],
560 $msg->inContentLanguage()->plain(),
561 'inContentLanguage() with ForceUIMsg override enabled'
563 $this->assertEquals(
'Main Page', $msg->inLanguage(
'en' )->plain(),
"inLanguage( 'en' )" );
566 $msg->inContentLanguage()->plain(),
567 'inContentLanguage() with ForceUIMsg override enabled'
569 $this->assertEquals(
'Hauptseite', $msg->inLanguage(
'de' )->plain(),
"inLanguage( 'de' )" );
585 $msg =
new Message(
'parentheses' );
586 $msg->rawParams(
'<a>foo</a>' );
588 $this->assertEquals(
'(<a>foo</a>)', $msg->parse(),
'Sanity check' );
590 $this->assertEquals(
'(<a>foo</a>)', $msg->parse() );
592 $this->assertInstanceOf(
'Title', $title );
593 $this->assertEquals(
'Testing', $title->getFullText() );
595 $msg =
new Message(
'mainpage' );
596 $msg->inLanguage(
'de' );
597 $this->assertEquals(
'Hauptseite', $msg->plain(),
'Sanity check' );
599 $this->assertEquals(
'Hauptseite', $msg->plain() );
609 $this->assertSame( $expectedText, $message->text() );
614 $messageSpecifier->expects( $this->any() )->method(
'getKey' )->willReturn(
'mainpage' );
615 $messageSpecifier->expects( $this->any() )->method(
'getParams' )->willReturn( [] );
618 'string' => [
'mainpage',
'Main Page' ],
619 'array' => [ [
'youhavenewmessages',
'foo',
'bar' ],
'You have foo (bar).' ],
620 'Message' => [
new Message(
'youhavenewmessages', [
'foo',
'bar' ] ),
'You have foo (bar).' ],
621 'RawMessage' => [
new RawMessage(
'foo ($1)', [
'bar' ] ),
'foo (bar)' ],
622 'MessageSpecifier' => [ $messageSpecifier,
'Main Page' ],
623 'nested RawMessage' => [ [
new RawMessage(
'foo ($1)', [
'bar' ] ) ],
'foo (bar)' ],
testSerialization()
Message::serialize Message::unserialize.
magic word the default is to use $key to get the and $key value or $key value text $key value html to format the value $key
testExists()
Message::exists.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
testDurationParams()
Message::durationParam Message::durationParams.
if(!isset($args[0])) $lang
static destroyInstance()
Destroy the singleton instance.
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.
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 MediaWikiServices
static constructClassInstance($clazz, $args)
Construct an instance of the given class using the given arguments.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
when a variable name is used in a it is silently declared as a new local masking the global
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.
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 noclasses 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 and may include noclasses 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"<
static provideConstructor()
provideNewFromSpecifier()
namespace and then decline to actually register it file or subcat img or subcat $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...