MediaWiki  master
TitleTest.php
Go to the documentation of this file.
1 <?php
2 
7 class TitleTest extends MediaWikiTestCase {
8  protected function setUp() {
9  parent::setUp();
10 
11  $this->setMwGlobals( [
12  'wgAllowUserJs' => false,
13  'wgDefaultLanguageVariant' => false,
14  'wgMetaNamespace' => 'Project',
15  ] );
16  $this->setUserLang( 'en' );
17  $this->setContentLang( 'en' );
18  }
19 
23  public function testLegalChars() {
24  $titlechars = Title::legalChars();
25 
26  foreach ( range( 1, 255 ) as $num ) {
27  $chr = chr( $num );
28  if ( strpos( "#[]{}<>|", $chr ) !== false || preg_match( "/[\\x00-\\x1f\\x7f]/", $chr ) ) {
29  $this->assertFalse(
30  (bool)preg_match( "/[$titlechars]/", $chr ),
31  "chr($num) = $chr is not a valid titlechar"
32  );
33  } else {
34  $this->assertTrue(
35  (bool)preg_match( "/[$titlechars]/", $chr ),
36  "chr($num) = $chr is a valid titlechar"
37  );
38  }
39  }
40  }
41 
42  public static function provideValidSecureAndSplit() {
43  return [
44  [ 'Sandbox' ],
45  [ 'A "B"' ],
46  [ 'A \'B\'' ],
47  [ '.com' ],
48  [ '~' ],
49  [ '#' ],
50  [ '"' ],
51  [ '\'' ],
52  [ 'Talk:Sandbox' ],
53  [ 'Talk:Foo:Sandbox' ],
54  [ 'File:Example.svg' ],
55  [ 'File_talk:Example.svg' ],
56  [ 'Foo/.../Sandbox' ],
57  [ 'Sandbox/...' ],
58  [ 'A~~' ],
59  [ ':A' ],
60  // Length is 256 total, but only title part matters
61  [ 'Category:' . str_repeat( 'x', 248 ) ],
62  [ str_repeat( 'x', 252 ) ],
63  // interwiki prefix
64  [ 'localtestiw: #anchor' ],
65  [ 'localtestiw:' ],
66  [ 'localtestiw:foo' ],
67  [ 'localtestiw: foo # anchor' ],
68  [ 'localtestiw: Talk: Sandbox # anchor' ],
69  [ 'remotetestiw:' ],
70  [ 'remotetestiw: Talk: # anchor' ],
71  [ 'remotetestiw: #bar' ],
72  [ 'remotetestiw: Talk:' ],
73  [ 'remotetestiw: Talk: Foo' ],
74  [ 'localtestiw:remotetestiw:' ],
75  [ 'localtestiw:remotetestiw:foo' ]
76  ];
77  }
78 
79  public static function provideInvalidSecureAndSplit() {
80  return [
81  [ '', 'title-invalid-empty' ],
82  [ ':', 'title-invalid-empty' ],
83  [ '__ __', 'title-invalid-empty' ],
84  [ ' __ ', 'title-invalid-empty' ],
85  // Bad characters forbidden regardless of wgLegalTitleChars
86  [ 'A [ B', 'title-invalid-characters' ],
87  [ 'A ] B', 'title-invalid-characters' ],
88  [ 'A { B', 'title-invalid-characters' ],
89  [ 'A } B', 'title-invalid-characters' ],
90  [ 'A < B', 'title-invalid-characters' ],
91  [ 'A > B', 'title-invalid-characters' ],
92  [ 'A | B', 'title-invalid-characters' ],
93  // URL encoding
94  [ 'A%20B', 'title-invalid-characters' ],
95  [ 'A%23B', 'title-invalid-characters' ],
96  [ 'A%2523B', 'title-invalid-characters' ],
97  // XML/HTML character entity references
98  // Note: Commented out because they are not marked invalid by the PHP test as
99  // Title::newFromText runs Sanitizer::decodeCharReferencesAndNormalize first.
100  // 'A &eacute; B',
101  // 'A &#233; B',
102  // 'A &#x00E9; B',
103  // Subject of NS_TALK does not roundtrip to NS_MAIN
104  [ 'Talk:File:Example.svg', 'title-invalid-talk-namespace' ],
105  // Directory navigation
106  [ '.', 'title-invalid-relative' ],
107  [ '..', 'title-invalid-relative' ],
108  [ './Sandbox', 'title-invalid-relative' ],
109  [ '../Sandbox', 'title-invalid-relative' ],
110  [ 'Foo/./Sandbox', 'title-invalid-relative' ],
111  [ 'Foo/../Sandbox', 'title-invalid-relative' ],
112  [ 'Sandbox/.', 'title-invalid-relative' ],
113  [ 'Sandbox/..', 'title-invalid-relative' ],
114  // Tilde
115  [ 'A ~~~ Name', 'title-invalid-magic-tilde' ],
116  [ 'A ~~~~ Signature', 'title-invalid-magic-tilde' ],
117  [ 'A ~~~~~ Timestamp', 'title-invalid-magic-tilde' ],
118  // Length
119  [ str_repeat( 'x', 256 ), 'title-invalid-too-long' ],
120  // Namespace prefix without actual title
121  [ 'Talk:', 'title-invalid-empty' ],
122  [ 'Talk:#', 'title-invalid-empty' ],
123  [ 'Category: ', 'title-invalid-empty' ],
124  [ 'Category: #bar', 'title-invalid-empty' ],
125  // interwiki prefix
126  [ 'localtestiw: Talk: # anchor', 'title-invalid-empty' ],
127  [ 'localtestiw: Talk:', 'title-invalid-empty' ]
128  ];
129  }
130 
131  private function secureAndSplitGlobals() {
132  $this->setMwGlobals( [
133  'wgLocalInterwikis' => [ 'localtestiw' ],
134  'wgHooks' => [
135  'InterwikiLoadPrefix' => [
136  function ( $prefix, &$data ) {
137  if ( $prefix === 'localtestiw' ) {
138  $data = [ 'iw_url' => 'localtestiw' ];
139  } elseif ( $prefix === 'remotetestiw' ) {
140  $data = [ 'iw_url' => 'remotetestiw' ];
141  }
142  return false;
143  }
144  ]
145  ]
146  ] );
147 
148  // Reset TitleParser since we modified $wgLocalInterwikis
149  $this->setService( 'TitleParser', new MediaWikiTitleCodec(
150  Language::factory( 'en' ),
151  new GenderCache(),
152  [ 'localtestiw' ]
153  ) );
154  }
155 
162  public function testSecureAndSplitValid( $text ) {
163  $this->secureAndSplitGlobals();
164  $this->assertInstanceOf( 'Title', Title::newFromText( $text ), "Valid: $text" );
165  }
166 
173  public function testSecureAndSplitInvalid( $text, $expectedErrorMessage ) {
174  $this->secureAndSplitGlobals();
175  try {
176  Title::newFromTextThrow( $text ); // should throw
177  $this->assertTrue( false, "Invalid: $text" );
178  } catch ( MalformedTitleException $ex ) {
179  $this->assertEquals( $expectedErrorMessage, $ex->getErrorMessage(), "Invalid: $text" );
180  }
181  }
182 
183  public static function provideConvertByteClassToUnicodeClass() {
184  return [
185  [
186  ' %!"$&\'()*,\\-.\\/0-9:;=?@A-Z\\\\^_`a-z~\\x80-\\xFF+',
187  ' %!"$&\'()*,\\-./0-9:;=?@A-Z\\\\\\^_`a-z~+\\u0080-\\uFFFF',
188  ],
189  [
190  'QWERTYf-\\xFF+',
191  'QWERTYf-\\x7F+\\u0080-\\uFFFF',
192  ],
193  [
194  'QWERTY\\x66-\\xFD+',
195  'QWERTYf-\\x7F+\\u0080-\\uFFFF',
196  ],
197  [
198  'QWERTYf-y+',
199  'QWERTYf-y+',
200  ],
201  [
202  'QWERTYf-\\x80+',
203  'QWERTYf-\\x7F+\\u0080-\\uFFFF',
204  ],
205  [
206  'QWERTY\\x66-\\x80+\\x23',
207  'QWERTYf-\\x7F+#\\u0080-\\uFFFF',
208  ],
209  [
210  'QWERTY\\x66-\\x80+\\xD3',
211  'QWERTYf-\\x7F+\\u0080-\\uFFFF',
212  ],
213  [
214  '\\\\\\x99',
215  '\\\\\\u0080-\\uFFFF',
216  ],
217  [
218  '-\\x99',
219  '\\-\\u0080-\\uFFFF',
220  ],
221  [
222  'QWERTY\\-\\x99',
223  'QWERTY\\-\\u0080-\\uFFFF',
224  ],
225  [
226  '\\\\x99',
227  '\\\\x99',
228  ],
229  [
230  'A-\\x9F',
231  'A-\\x7F\\u0080-\\uFFFF',
232  ],
233  [
234  '\\x66-\\x77QWERTY\\x88-\\x91FXZ',
235  'f-wQWERTYFXZ\\u0080-\\uFFFF',
236  ],
237  [
238  '\\x66-\\x99QWERTY\\xAA-\\xEEFXZ',
239  'f-\\x7FQWERTYFXZ\\u0080-\\uFFFF',
240  ],
241  ];
242  }
243 
248  public function testConvertByteClassToUnicodeClass( $byteClass, $unicodeClass ) {
249  $this->assertEquals( $unicodeClass, Title::convertByteClassToUnicodeClass( $byteClass ) );
250  }
251 
256  public function testFixSpecialNameRetainsParameter( $text, $expectedParam ) {
257  $title = Title::newFromText( $text );
258  $fixed = $title->fixSpecialName();
259  $stuff = explode( '/', $fixed->getDBkey(), 2 );
260  if ( count( $stuff ) == 2 ) {
261  $par = $stuff[1];
262  } else {
263  $par = null;
264  }
265  $this->assertEquals(
266  $expectedParam,
267  $par,
268  "Bug 31100 regression check: Title->fixSpecialName() should preserve parameter"
269  );
270  }
271 
273  return [
274  [ 'Special:Version', null ],
275  [ 'Special:Version/', '' ],
276  [ 'Special:Version/param', 'param' ],
277  ];
278  }
279 
291  public function testIsValidMoveOperation( $source, $target, $expected ) {
292  $this->setMwGlobals( 'wgContentHandlerUseDB', false );
294  $nt = Title::newFromText( $target );
295  $errors = $title->isValidMoveOperation( $nt, false );
296  if ( $expected === true ) {
297  $this->assertTrue( $errors );
298  } else {
299  $errors = $this->flattenErrorsArray( $errors );
300  foreach ( (array)$expected as $error ) {
301  $this->assertContains( $error, $errors );
302  }
303  }
304  }
305 
306  public static function provideTestIsValidMoveOperation() {
307  return [
308  // for Title::isValidMoveOperation
309  [ 'Some page', '', 'badtitletext' ],
310  [ 'Test', 'Test', 'selfmove' ],
311  [ 'Special:FooBar', 'Test', 'immobile-source-namespace' ],
312  [ 'Test', 'Special:FooBar', 'immobile-target-namespace' ],
313  [ 'MediaWiki:Common.js', 'Help:Some wikitext page', 'bad-target-model' ],
314  [ 'Page', 'File:Test.jpg', 'nonfile-cannot-move-to-file' ],
315  // for Title::validateFileMoveOperation
316  [ 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ],
317  ];
318  }
319 
331  public function testWgWhitelistReadRegexp( $whitelistRegexp, $source, $action, $expected ) {
332  // $wgWhitelistReadRegexp must be an array. Since the provided test cases
333  // usually have only one regex, it is more concise to write the lonely regex
334  // as a string. Thus we cast to an array() to honor $wgWhitelistReadRegexp
335  // type requisite.
336  if ( is_string( $whitelistRegexp ) ) {
337  $whitelistRegexp = [ $whitelistRegexp ];
338  }
339 
340  $this->setMwGlobals( [
341  // So User::isEveryoneAllowed( 'read' ) === false
342  'wgGroupPermissions' => [ '*' => [ 'read' => false ] ],
343  'wgWhitelistRead' => [ 'some random non sense title' ],
344  'wgWhitelistReadRegexp' => $whitelistRegexp,
345  ] );
346 
348 
349  // New anonymous user with no rights
350  $user = new User;
351  $user->mRights = [];
352  $errors = $title->userCan( $action, $user );
353 
354  if ( is_bool( $expected ) ) {
355  # Forge the assertion message depending on the assertion expectation
356  $allowableness = $expected
357  ? " should be allowed"
358  : " should NOT be allowed";
359  $this->assertEquals(
360  $expected,
361  $errors,
362  "User action '$action' on [[$source]] $allowableness."
363  );
364  } else {
365  $errors = $this->flattenErrorsArray( $errors );
366  foreach ( (array)$expected as $error ) {
367  $this->assertContains( $error, $errors );
368  }
369  }
370  }
371 
375  public function dataWgWhitelistReadRegexp() {
376  $ALLOWED = true;
377  $DISALLOWED = false;
378 
379  return [
380  // Everything, if this doesn't work, we're really in trouble
381  [ '/.*/', 'Main_Page', 'read', $ALLOWED ],
382  [ '/.*/', 'Main_Page', 'edit', $DISALLOWED ],
383 
384  // We validate against the title name, not the db key
385  [ '/^Main_Page$/', 'Main_Page', 'read', $DISALLOWED ],
386  // Main page
387  [ '/^Main/', 'Main_Page', 'read', $ALLOWED ],
388  [ '/^Main.*/', 'Main_Page', 'read', $ALLOWED ],
389  // With spaces
390  [ '/Mic\sCheck/', 'Mic Check', 'read', $ALLOWED ],
391  // Unicode multibyte
392  // ...without unicode modifier
393  [ '/Unicode Test . Yes/', 'Unicode Test Ñ Yes', 'read', $DISALLOWED ],
394  // ...with unicode modifier
395  [ '/Unicode Test . Yes/u', 'Unicode Test Ñ Yes', 'read', $ALLOWED ],
396  // Case insensitive
397  [ '/MiC ChEcK/', 'mic check', 'read', $DISALLOWED ],
398  [ '/MiC ChEcK/i', 'mic check', 'read', $ALLOWED ],
399 
400  // From DefaultSettings.php:
401  [ "@^UsEr.*@i", 'User is banned', 'read', $ALLOWED ],
402  [ "@^UsEr.*@i", 'User:John Doe', 'read', $ALLOWED ],
403 
404  // With namespaces:
405  [ '/^Special:NewPages$/', 'Special:NewPages', 'read', $ALLOWED ],
406  [ null, 'Special:Newpages', 'read', $DISALLOWED ],
407 
408  ];
409  }
410 
411  public function flattenErrorsArray( $errors ) {
412  $result = [];
413  foreach ( $errors as $error ) {
414  $result[] = $error[0];
415  }
416 
417  return $result;
418  }
419 
424  public function testGetPageViewLanguage( $expected, $titleText, $contLang,
425  $lang, $variant, $msg = ''
426  ) {
427  // Setup environnement for this test
428  $this->setMwGlobals( [
429  'wgDefaultLanguageVariant' => $variant,
430  'wgAllowUserJs' => true,
431  ] );
432  $this->setUserLang( $lang );
433  $this->setContentLang( $contLang );
434 
435  $title = Title::newFromText( $titleText );
436  $this->assertInstanceOf( 'Title', $title,
437  "Test must be passed a valid title text, you gave '$titleText'"
438  );
439  $this->assertEquals( $expected,
440  $title->getPageViewLanguage()->getCode(),
441  $msg
442  );
443  }
444 
445  public static function provideGetPageViewLanguage() {
446  # Format:
447  # - expected
448  # - Title name
449  # - wgContLang (expected in most case)
450  # - wgLang (on some specific pages)
451  # - wgDefaultLanguageVariant
452  # - Optional message
453  return [
454  [ 'fr', 'Help:I_need_somebody', 'fr', 'fr', false ],
455  [ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ],
456  [ 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ],
457 
458  [ 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ],
459  [ 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ],
460  [ 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ],
461  [ 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ],
462  [ 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ],
463  [ 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ],
464  [ 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ],
465  [ 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ],
466 
467  [ 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ],
468  [ 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ],
469  [ 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ],
470  [ 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ],
471  [ 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ],
472  [ 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ],
473  [ 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ],
474  [ 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ],
475  [ 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ],
476  [ 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ],
477 
478  [ 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ],
479  [ 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ],
480 
481  ];
482  }
483 
488  public function testGetBaseText( $title, $expected, $msg = '' ) {
490  $this->assertEquals( $expected,
491  $title->getBaseText(),
492  $msg
493  );
494  }
495 
496  public static function provideBaseTitleCases() {
497  return [
498  # Title, expected base, optional message
499  [ 'User:John_Doe/subOne/subTwo', 'John Doe/subOne' ],
500  [ 'User:Foo/Bar/Baz', 'Foo/Bar' ],
501  ];
502  }
503 
508  public function testGetRootText( $title, $expected, $msg = '' ) {
510  $this->assertEquals( $expected,
511  $title->getRootText(),
512  $msg
513  );
514  }
515 
516  public static function provideRootTitleCases() {
517  return [
518  # Title, expected base, optional message
519  [ 'User:John_Doe/subOne/subTwo', 'John Doe' ],
520  [ 'User:Foo/Bar/Baz', 'Foo' ],
521  ];
522  }
523 
529  public function testGetSubpageText( $title, $expected, $msg = '' ) {
531  $this->assertEquals( $expected,
532  $title->getSubpageText(),
533  $msg
534  );
535  }
536 
537  public static function provideSubpageTitleCases() {
538  return [
539  # Title, expected base, optional message
540  [ 'User:John_Doe/subOne/subTwo', 'subTwo' ],
541  [ 'User:John_Doe/subOne', 'subOne' ],
542  ];
543  }
544 
545  public static function provideNewFromTitleValue() {
546  return [
547  [ new TitleValue( NS_MAIN, 'Foo' ) ],
548  [ new TitleValue( NS_MAIN, 'Foo', 'bar' ) ],
549  [ new TitleValue( NS_USER, 'Hansi_Maier' ) ],
550  ];
551  }
552 
557  $title = Title::newFromTitleValue( $value );
558 
559  $dbkey = str_replace( ' ', '_', $value->getText() );
560  $this->assertEquals( $dbkey, $title->getDBkey() );
561  $this->assertEquals( $value->getNamespace(), $title->getNamespace() );
562  $this->assertEquals( $value->getFragment(), $title->getFragment() );
563  }
564 
565  public static function provideGetTitleValue() {
566  return [
567  [ 'Foo' ],
568  [ 'Foo#bar' ],
569  [ 'User:Hansi_Maier' ],
570  ];
571  }
572 
576  public function testGetTitleValue( $text ) {
577  $title = Title::newFromText( $text );
578  $value = $title->getTitleValue();
579 
580  $dbkey = str_replace( ' ', '_', $value->getText() );
581  $this->assertEquals( $title->getDBkey(), $dbkey );
582  $this->assertEquals( $title->getNamespace(), $value->getNamespace() );
583  $this->assertEquals( $title->getFragment(), $value->getFragment() );
584  }
585 
586  public static function provideGetFragment() {
587  return [
588  [ 'Foo', '' ],
589  [ 'Foo#bar', 'bar' ],
590  [ 'Foo#bär', 'bär' ],
591 
592  // Inner whitespace is normalized
593  [ 'Foo#bar_bar', 'bar bar' ],
594  [ 'Foo#bar bar', 'bar bar' ],
595  [ 'Foo#bar bar', 'bar bar' ],
596 
597  // Leading whitespace is kept, trailing whitespace is trimmed.
598  // XXX: Is this really want we want?
599  [ 'Foo#_bar_bar_', ' bar bar' ],
600  [ 'Foo# bar bar ', ' bar bar' ],
601  ];
602  }
603 
610  public function testGetFragment( $full, $fragment ) {
611  $title = Title::newFromText( $full );
612  $this->assertEquals( $fragment, $title->getFragment() );
613  }
614 
621  public function testIsAlwaysKnown( $page, $isKnown ) {
623  $this->assertEquals( $isKnown, $title->isAlwaysKnown() );
624  }
625 
626  public static function provideIsAlwaysKnown() {
627  return [
628  [ 'Some nonexistent page', false ],
629  [ 'UTPage', false ],
630  [ '#test', true ],
631  [ 'Special:BlankPage', true ],
632  [ 'Special:SomeNonexistentSpecialPage', false ],
633  [ 'MediaWiki:Parentheses', true ],
634  [ 'MediaWiki:Some nonexistent message', false ],
635  ];
636  }
637 
641  public function testIsAlwaysKnownOnInterwiki() {
642  $title = Title::makeTitle( NS_MAIN, 'Interwiki link', '', 'externalwiki' );
643  $this->assertTrue( $title->isAlwaysKnown() );
644  }
645 
649  public function testExists() {
650  $title = Title::makeTitle( NS_PROJECT, 'New page' );
651  $linkCache = LinkCache::singleton();
652 
653  $article = new Article( $title );
654  $page = $article->getPage();
655  $page->doEditContent( new WikitextContent( 'Some [[link]]' ), 'summary' );
656 
657  // Tell Title it doesn't know whether it exists
658  $title->mArticleID = -1;
659 
660  // Tell the link cache it doesn't exists when it really does
661  $linkCache->clearLink( $title );
662  $linkCache->addBadLinkObj( $title );
663 
664  $this->assertEquals(
665  false,
666  $title->exists(),
667  'exists() should rely on link cache unless GAID_FOR_UPDATE is used'
668  );
669  $this->assertEquals(
670  true,
671  $title->exists( Title::GAID_FOR_UPDATE ),
672  'exists() should re-query database when GAID_FOR_UPDATE is used'
673  );
674  }
675 
676  public function provideCreateFragmentTitle() {
677  return [
678  [ Title::makeTitle( NS_MAIN, 'Test' ), 'foo' ],
679  [ Title::makeTitle( NS_TALK, 'Test', 'foo' ), '' ],
680  [ Title::makeTitle( NS_CATEGORY, 'Test', 'foo' ), 'bar' ],
681  [ Title::makeTitle( NS_MAIN, 'Test1', '', 'interwiki' ), 'baz' ]
682  ];
683  }
684 
689  public function testCreateFragmentTitle( Title $title, $fragment ) {
690  $this->mergeMwGlobalArrayValue( 'wgHooks', [
691  'InterwikiLoadPrefix' => [
692  function ( $prefix, &$iwdata ) {
693  if ( $prefix === 'interwiki' ) {
694  $iwdata = [
695  'iw_url' => 'http://example.com/',
696  'iw_local' => 0,
697  'iw_trans' => 0,
698  ];
699  return false;
700  }
701  },
702  ],
703  ] );
704 
705  $fragmentTitle = $title->createFragmentTarget( $fragment );
706 
707  $this->assertEquals( $title->getNamespace(), $fragmentTitle->getNamespace() );
708  $this->assertEquals( $title->getText(), $fragmentTitle->getText() );
709  $this->assertEquals( $title->getInterwiki(), $fragmentTitle->getInterwiki() );
710  $this->assertEquals( $fragment, $fragmentTitle->getFragment() );
711  }
712 
713  public function provideGetPrefixedText() {
714  return [
715  // ns = 0
716  [
717  Title::makeTitle( NS_MAIN, 'Foobar' ),
718  'Foobar'
719  ],
720  // ns = 2
721  [
722  Title::makeTitle( NS_USER, 'Foobar' ),
723  'User:Foobar'
724  ],
725  // fragment not included
726  [
727  Title::makeTitle( NS_MAIN, 'Foobar', 'fragment' ),
728  'Foobar'
729  ],
730  // ns = -2
731  [
732  Title::makeTitle( NS_MEDIA, 'Foobar' ),
733  'Media:Foobar'
734  ],
735  // non-existent namespace
736  [
737  Title::makeTitle( 100000, 'Foobar' ),
738  ':Foobar'
739  ],
740  ];
741  }
742 
747  public function testGetPrefixedText( Title $title, $expected ) {
748  $this->assertEquals( $expected, $title->getPrefixedText() );
749  }
750 }
getText()
Returns the title in text form, without namespace prefix or fragment.
Definition: TitleValue.php:142
mergeMwGlobalArrayValue($name, $values)
Merges the given values into a MW global array variable.
A codec for MediaWiki page titles.
testIsAlwaysKnownOnInterwiki()
Title::isAlwaysKnown.
Definition: TitleTest.php:641
the array() calling protocol came about after MediaWiki 1.4rc1.
static provideGetPageViewLanguage()
Definition: TitleTest.php:445
MalformedTitleException is thrown when a TitleParser is unable to parse a title string.
static provideValidSecureAndSplit()
Definition: TitleTest.php:42
const NS_MAIN
Definition: Defines.php:69
getText()
Get the text form (spaces not underscores) of the main part.
Definition: Title.php:872
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
static provideSpecialNamesWithAndWithoutParameter()
Definition: TitleTest.php:272
static provideGetFragment()
Definition: TitleTest.php:586
if(!isset($args[0])) $lang
testGetTitleValue($text)
provideGetTitleValue
Definition: TitleTest.php:576
Class for viewing MediaWiki article and history.
Definition: Article.php:34
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36
Using a hook running we can avoid having all this option specific stuff in our mainline code Using the function array $article
Definition: hooks.txt:78
$source
$value
static provideConvertByteClassToUnicodeClass()
Definition: TitleTest.php:183
testGetRootText($title, $expected, $msg= '')
provideRootTitleCases Title::getRootText
Definition: TitleTest.php:508
getPrefixedText()
Get the prefixed title with spaces.
Definition: Title.php:1430
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:256
Represents a title within MediaWiki.
Definition: Title.php:36
secureAndSplitGlobals()
Definition: TitleTest.php:131
static provideRootTitleCases()
Definition: TitleTest.php:516
static provideSubpageTitleCases()
Definition: TitleTest.php:537
static provideNewFromTitleValue()
Definition: TitleTest.php:545
static provideBaseTitleCases()
Definition: TitleTest.php:496
testFixSpecialNameRetainsParameter($text, $expectedParam)
provideSpecialNamesWithAndWithoutParameter Title::fixSpecialName
Definition: TitleTest.php:256
setService($name, $object)
Sets a service, maintaining a stashed version of the previous service to be restored in tearDown...
static provideTestIsValidMoveOperation()
Definition: TitleTest.php:306
provideGetPrefixedText()
Definition: TitleTest.php:713
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
Definition: hooks.txt:1814
testGetFragment($full, $fragment)
provideGetFragment
Definition: TitleTest.php:610
testExists()
Title::exists.
Definition: TitleTest.php:649
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 true
Definition: hooks.txt:1816
createFragmentTarget($fragment)
Creates a new Title for a different fragment of the same page.
Definition: Title.php:1383
Database Title.
Definition: TitleTest.php:7
const NS_PROJECT
Definition: Defines.php:73
static singleton()
Get an instance of this class.
Definition: LinkCache.php:65
testGetBaseText($title, $expected, $msg= '')
provideBaseTitleCases Title::getBaseText
Definition: TitleTest.php:488
const NS_MEDIA
Definition: Defines.php:57
static newFromDBkey($key)
Create a new Title from a prefixed DB key.
Definition: Title.php:200
testConvertByteClassToUnicodeClass($byteClass, $unicodeClass)
provideConvertByteClassToUnicodeClass Title::convertByteClassToUnicodeClass
Definition: TitleTest.php:248
testGetSubpageText($title, $expected, $msg= '')
Definition: TitleTest.php:529
const GAID_FOR_UPDATE
Used to be GAID_FOR_UPDATE define.
Definition: Title.php:51
const NS_CATEGORY
Definition: Defines.php:83
testSecureAndSplitInvalid($text, $expectedErrorMessage)
See also mediawiki.Title.test.js Title::secureAndSplit provideInvalidSecureAndSplit.
Definition: TitleTest.php:173
dataWgWhitelistReadRegexp()
Provides test parameter values for testWgWhitelistReadRegexp()
Definition: TitleTest.php:375
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
Definition: hooks.txt:312
testIsValidMoveOperation($source, $target, $expected)
Auth-less test of Title::isValidMoveOperation.
Definition: TitleTest.php:291
getNamespace()
Get the namespace index, i.e.
Definition: Title.php:913
provideCreateFragmentTitle()
Definition: TitleTest.php:676
testLegalChars()
Title::legalChars.
Definition: TitleTest.php:23
Content object for wiki text pages.
getInterwiki()
Get the interwiki prefix.
Definition: Title.php:800
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
static provideInvalidSecureAndSplit()
Definition: TitleTest.php:79
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:242
static newFromTitleValue(TitleValue $titleValue)
Create a new Title from a TitleValue.
Definition: Title.php:219
static provideIsAlwaysKnown()
Definition: TitleTest.php:626
testGetPrefixedText(Title $title, $expected)
Title::getPrefixedText provideGetPrefixedText.
Definition: TitleTest.php:747
testCreateFragmentTitle(Title $title, $fragment)
Title::createFragmentTarget provideCreateFragmentTitle.
Definition: TitleTest.php:689
static newFromTextThrow($text, $defaultNamespace=NS_MAIN)
Like Title::newFromText(), but throws MalformedTitleException when the title is invalid, rather than returning null.
Definition: Title.php:286
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
Definition: injection.txt:35
static convertByteClassToUnicodeClass($byteClass)
Utility method for converting a character sequence from bytes to Unicode.
Definition: Title.php:613
Caches user genders when needed to use correct namespace aliases.
Definition: GenderCache.php:31
flattenErrorsArray($errors)
Definition: TitleTest.php:411
testWgWhitelistReadRegexp($whitelistRegexp, $source, $action, $expected)
Auth-less test of Title::userCan.
Definition: TitleTest.php:331
static provideGetTitleValue()
Definition: TitleTest.php:565
testIsAlwaysKnown($page, $isKnown)
Title::isAlwaysKnown provideIsAlwaysKnown.
Definition: TitleTest.php:621
static legalChars()
Get a regex character class describing the legal characters in a link.
Definition: Title.php:585
const NS_TALK
Definition: Defines.php:70
static factory($code)
Get a cached or new language object for a given language code.
Definition: Language.php:179
setMwGlobals($pairs, $value=null)
testGetPageViewLanguage($expected, $titleText, $contLang, $lang, $variant, $msg= '')
provideGetPageViewLanguage Title::getPageViewLanguage
Definition: TitleTest.php:424
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:503
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2376
testNewFromTitleValue(TitleValue $value)
provideNewFromTitleValue
Definition: TitleTest.php:556
testSecureAndSplitValid($text)
See also mediawiki.Title.test.js Title::secureAndSplit provideValidSecureAndSplit.
Definition: TitleTest.php:162