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() );
39 $langDe = Language::factory(
'de' );
40 $langEn = Language::factory(
'en' );
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' ]
117 $language = Language::factory( $languageCode );
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',
162 public function testKeys( $key, $expected, $exception =
null ) {
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' ) );
185 $this->assertInstanceOf(
'Message', Message::newFromKey(
'mainpage' ) );
186 $this->assertInstanceOf(
'Message', Message::newFromKey(
'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 'Заглавная страница',
271 $msg->inLanguage( Language::factory(
'ru' ) )->text()
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()
352 $lang = Language::factory(
'en' );
356 $lang->formatNum( 123456.789 ),
357 $msg->inLanguage(
$lang )->numParams( 123456.789 )->plain(),
358 'numParams is handled correctly'
367 $lang = Language::factory(
'en' );
371 $lang->formatDuration( 1234 ),
372 $msg->inLanguage(
$lang )->durationParams( 1234 )->plain(),
373 'durationParams is handled correctly'
384 $lang = Language::factory(
'en' );
390 'expiryParams is handled correctly'
399 $lang = Language::factory(
'en' );
403 $lang->formatTimePeriod( 1234 ),
404 $msg->inLanguage(
$lang )->timeperiodParams( 1234 )->plain(),
405 'timeperiodParams is handled correctly'
414 $lang = Language::factory(
'en' );
418 $lang->formatSize( 123456 ),
419 $msg->inLanguage(
$lang )->sizeParams( 123456 )->plain(),
420 'sizeParams is handled correctly'
429 $lang = Language::factory(
'en' );
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>",
479 $lang = Language::factory(
'en' );
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() );
591 $title = TestingAccessWrapper::newFromObject( $msg )->title;
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() );
607 $message = Message::newFromSpecifier(
$value );
608 $this->assertInstanceOf( Message::class, $message );
609 $this->assertSame( $expectedText, $message->text() );
613 $messageSpecifier = $this->getMockForAbstractClass( MessageSpecifier::class );
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)' ],
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
unserialize( $serialized)
$wgParserConf
Parser configuration.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
static destroyInstance()
Destroy the singleton instance.
testExpiryParams()
FIXME: This should not need database, but Language::formatExpiry does (bug 55912) Database Message::e...
testConstructorParams( $expected, $args)
Message::__construct Message::getParams provideConstructorParams.
static provideConstructorParams()
testParser( $expect, $format)
Message::text Message::parse Message::parseAsBlock Message::toString Message::transformText Message::...
testInLanguageThrows()
MWException Message::inLanguage.
testInLanguage()
Message::inLanguage.
testInContentLanguage()
Message::inContentLanguage.
static provideConstructorLanguage()
testSizeParams()
Message::sizeParam Message::sizeParams.
testRawParams()
Message::rawParam Message::rawParams.
testDurationParams()
Message::durationParam Message::durationParams.
testNumParams()
Message::numParam Message::numParams.
testNewFromSpecifier( $value, $expectedText)
Message::newFromSpecifier provideNewFromSpecifier.
testReplaceManyParams()
Message::params Message::toString Message::replaceParameters.
testToString( $key, $expect, $format='plain')
Message::toString Message::__toString provideToString.
testExists()
Message::exists.
static provideConstructor()
testWfMessageParams()
wfMessage Message::__construct
testTimeperiodParams()
Message::timeperiodParam Message::timeperiodParams.
testBitrateParams()
Message::bitrateParam Message::bitrateParams.
testConstructorLanguage( $key, $params, $languageCode)
Message::__construct Message::getLanguage provideConstructorLanguage.
provideNewFromSpecifier()
testKeys( $key, $expected, $exception=null)
Message::__construct Message::getKey Message::isMultiKey Message::getKeysToTry provideKeys.
testConstructor( $expectedLang, $key, $params, $language)
Message::__construct provideConstructor.
testNewFromKey()
Message::newFromKey.
testPlaintextParams( $expect, $format)
Message::plaintextParam Message::plaintextParams Message::formatPlaintext Message::toString Message::...
testInContentLanguageOverride()
Message::inContentLanguage.
static providePlaintextParams()
testToStringKey()
Message::__construct Message::text Message::plain Message::escaped Message::toString.
testSerialization()
Message::serialize Message::unserialize.
testRawMessage()
RawMessage::__construct RawMessage::fetchMessage.
The Message class provides methods which fulfil two basic services:
Variant of the Message class.
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
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
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 unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
namespace and then decline to actually register it file or subcat img or subcat $title
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
if(!isset( $args[0])) $lang