35 'wgAllowUserJs' =>
false,
36 'wgDefaultLanguageVariant' =>
false,
37 'wgMetaNamespace' =>
'Project',
38 'wgLocalInterwikis' => [
'localtestiw' ],
39 'wgCapitalLinks' =>
true,
44 'InterwikiLoadPrefix' => [
45 function ( $prefix, &$data ) {
46 if ( $prefix ===
'localtestiw' ) {
47 $data = [
'iw_url' =>
'localtestiw' ];
48 } elseif ( $prefix ===
'remotetestiw' ) {
49 $data = [
'iw_url' =>
'remotetestiw' ];
67 $genderCache = $this->getMockBuilder( GenderCache::class )
68 ->disableOriginalConstructor()
71 $genderCache->expects( $this->
any() )
72 ->method(
'getGenderOf' )
73 ->will( $this->returnCallback(
function ( $userName ) {
74 return preg_match(
'/^[^- _]+a( |_|$)/u', $userName ) ?
'female' :
'male';
84 $lang->resetNamespaces();
90 [
NS_MAIN,
'Foo_Bar',
'',
'',
'en',
'Foo Bar' ],
91 [
NS_USER,
'Hansi_Maier',
'stuff_and_so_on',
'',
'en',
'User:Hansi Maier#stuff and so on' ],
92 [
false,
'Hansi_Maier',
'',
'',
'en',
'Hansi Maier' ],
99 'User talk:hansi maier',
100 'User talk:Hansi maier'
105 [
NS_USER,
'Lisa_Müller',
'',
'',
'de',
'Benutzerin:Lisa Müller' ],
106 [
NS_MAIN,
'FooBar',
'',
'remotetestiw',
'en',
'remotetestiw:FooBar' ],
113 public function testFormat( $namespace, $text, $fragment, $interwiki,
$lang, $expected,
116 if ( $normalized ===
null ) {
117 $normalized = $expected;
121 $actual = $codec->formatTitle( $namespace, $text, $fragment, $interwiki );
123 $this->assertEquals( $expected, $actual,
'formatted' );
126 $parsed = $codec->parseTitle( $actual,
NS_MAIN );
127 $actual2 = $codec->formatTitle(
128 $parsed->getNamespace(),
130 $parsed->getFragment(),
131 $parsed->getInterwiki()
134 $this->assertEquals( $normalized, $actual2,
'normalized after round trip' );
139 [
NS_MAIN,
'Foo_Bar',
'',
'en',
'Foo Bar' ],
140 [
NS_USER,
'Hansi_Maier',
'stuff_and_so_on',
'en',
'Hansi Maier' ],
149 $title =
new TitleValue( $namespace, $dbkey, $fragment );
151 $actual = $codec->getText( $title );
153 $this->assertEquals( $expected, $actual );
158 [
NS_MAIN,
'Foo_Bar',
'',
'en',
'Foo Bar' ],
159 [
NS_USER,
'Hansi_Maier',
'stuff_and_so_on',
'en',
'User:Hansi Maier' ],
162 [
NS_USER_TALK,
'hansi__maier',
'',
'en',
'User talk:hansi maier' ],
166 [
NS_USER,
'Lisa_Müller',
'',
'de',
'Benutzerin:Lisa Müller' ],
167 [ 1000000,
'Invalid_namespace',
'',
'en',
':Invalid namespace' ],
176 $title =
new TitleValue( $namespace, $dbkey, $fragment );
178 $actual = $codec->getPrefixedText( $title );
180 $this->assertEquals( $expected, $actual );
185 [
NS_MAIN,
'Foo_Bar',
'',
'',
'en',
'Foo_Bar' ],
186 [
NS_USER,
'Hansi_Maier',
'stuff_and_so_on',
'',
'en',
'User:Hansi_Maier' ],
189 [
NS_USER_TALK,
'hansi__maier',
'',
'',
'en',
'User_talk:hansi__maier' ],
193 [
NS_USER,
'Lisa_Müller',
'',
'',
'de',
'Benutzerin:Lisa_Müller' ],
195 [
NS_MAIN,
'Remote_page',
'',
'remotetestiw',
'en',
'remotetestiw:Remote_page' ],
198 [ 10000000,
'Foobar',
'',
'',
'en',
':Foobar' ],
206 $interwiki,
$lang, $expected
209 $title =
new TitleValue( $namespace, $dbkey, $fragment, $interwiki );
211 $actual = $codec->getPrefixedDBkey( $title );
213 $this->assertEquals( $expected, $actual );
218 [
NS_MAIN,
'Foo_Bar',
'',
'en',
'Foo Bar' ],
219 [
NS_USER,
'Hansi_Maier',
'stuff_and_so_on',
'en',
'User:Hansi Maier#stuff and so on' ],
222 [
NS_USER_TALK,
'hansi__maier',
'',
'en',
'User talk:hansi maier' ],
231 $title =
new TitleValue( $namespace, $dbkey, $fragment );
233 $actual = $codec->getFullText( $title );
235 $this->assertEquals( $expected, $actual );
243 [
' : Hansi_Maier _ ',
NS_MAIN,
'en',
246 new TitleValue( NS_USER,
'0:0:0:0:0:0:0:1',
'' ) ],
247 [
' lisa Müller',
NS_USER,
'de',
248 new TitleValue( NS_USER,
'Lisa_Müller',
'' ) ],
249 [
'benutzerin:lisa Müller#stuff',
NS_MAIN,
'de',
250 new TitleValue( NS_USER,
'Lisa_Müller',
'stuff' ) ],
252 [
':Category:Quux',
NS_MAIN,
'en',
254 [
'Category:Quux',
NS_MAIN,
'en',
270 [
' _ Foo __ Bar_ _',
NS_MAIN,
'en',
282 [
'Talk:Sandbox',
NS_MAIN,
'en',
284 [
'Talk:Foo:Sandbox',
NS_MAIN,
'en',
286 [
'File:Example.svg',
NS_MAIN,
'en',
288 [
'File_talk:Example.svg',
NS_MAIN,
'en',
290 [
'Foo/.../Sandbox',
NS_MAIN,
'en',
292 [
'Sandbox/...',
NS_MAIN,
'en',
297 [
'Category:' . str_repeat(
'x', 248 ),
NS_MAIN,
'en',
299 'X' . str_repeat(
'x', 247 ) ) ],
300 [ str_repeat(
'x', 252 ),
NS_MAIN,
'en',
301 'X' . str_repeat(
'x', 251 ) ]
309 if ( $title ===
null ) {
310 $title = str_replace(
' ',
'_', trim( $text ) );
313 if ( is_string( $title ) ) {
318 $actual = $codec->parseTitle( $text, $ns );
320 $this->assertEquals( $title, $actual );
333 [
'Talk:File:Foo.jpg' ],
334 [
'Talk:localtestiw:Foo' ],
362 [
'Talk:File:Example.svg' ],
369 [
'Foo/../Sandbox' ],
374 [
'A ~~~~ Signature' ],
375 [
'A ~~~~~ Timestamp' ],
376 [ str_repeat(
'x', 256 ) ],
388 $this->setExpectedException( MalformedTitleException::class );
391 $codec->parseTitle( $text,
NS_MAIN );
397 [
NS_USER,
'Foo',
'en',
'User' ],
398 [
NS_USER,
'Hansi Maier',
'de',
'Benutzer' ],
402 [
NS_USER,
'Lisa Müller',
'de',
'Benutzerin' ],
411 $name = $codec->getNamespaceName( $namespace, $text );
413 $this->assertEquals( $expected, $name );
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Represents a page (or page fragment) title within MediaWiki.
if(!isset( $args[0])) $lang