MediaWiki  master
LinkerTest.php
Go to the documentation of this file.
1 <?php
2 
7 
12  public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
13  $this->setMwGlobals( [
14  'wgArticlePath' => '/wiki/$1',
15  ] );
16 
17  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
18  if ( $userName === '' ) {
19  Wikimedia\suppressWarnings();
20  }
21  $actual = Linker::userLink( $userId, $userName, $altUserName );
22  if ( $userName === '' ) {
23  Wikimedia\restoreWarnings();
24  }
25 
26  $this->assertEquals( $expected, $actual, $msg );
27  }
28 
29  public static function provideCasesForUserLink() {
30  # Format:
31  # - expected
32  # - userid
33  # - username
34  # - optional altUserName
35  # - optional message
36  return [
37  # Empty name (T222529)
38  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
39  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
40 
41  # ## ANONYMOUS USER ########################################
42  [
43  '<a href="/wiki/Special:Contributions/JohnDoe" '
44  . 'class="mw-userlink mw-anonuserlink" '
45  . 'title="Special:Contributions/JohnDoe"><bdi>JohnDoe</bdi></a>',
46  0, 'JohnDoe', false,
47  ],
48  [
49  '<a href="/wiki/Special:Contributions/::1" '
50  . 'class="mw-userlink mw-anonuserlink" '
51  . 'title="Special:Contributions/::1"><bdi>::1</bdi></a>',
52  0, '::1', false,
53  'Anonymous with pretty IPv6'
54  ],
55  [
56  '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
57  . 'class="mw-userlink mw-anonuserlink" '
58  . 'title="Special:Contributions/0:0:0:0:0:0:0:1"><bdi>::1</bdi></a>',
59  0, '0:0:0:0:0:0:0:1', false,
60  'Anonymous with almost pretty IPv6'
61  ],
62  [
63  '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
64  . 'class="mw-userlink mw-anonuserlink" '
65  . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001"><bdi>::1</bdi></a>',
66  0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
67  'Anonymous with full IPv6'
68  ],
69  [
70  '<a href="/wiki/Special:Contributions/::1" '
71  . 'class="mw-userlink mw-anonuserlink" '
72  . 'title="Special:Contributions/::1"><bdi>AlternativeUsername</bdi></a>',
73  0, '::1', 'AlternativeUsername',
74  'Anonymous with pretty IPv6 and an alternative username'
75  ],
76 
77  # IPV4
78  [
79  '<a href="/wiki/Special:Contributions/127.0.0.1" '
80  . 'class="mw-userlink mw-anonuserlink" '
81  . 'title="Special:Contributions/127.0.0.1"><bdi>127.0.0.1</bdi></a>',
82  0, '127.0.0.1', false,
83  'Anonymous with IPv4'
84  ],
85  [
86  '<a href="/wiki/Special:Contributions/127.0.0.1" '
87  . 'class="mw-userlink mw-anonuserlink" '
88  . 'title="Special:Contributions/127.0.0.1"><bdi>AlternativeUsername</bdi></a>',
89  0, '127.0.0.1', 'AlternativeUsername',
90  'Anonymous with IPv4 and an alternative username'
91  ],
92 
93  # ## Regular user ##########################################
94  # TODO!
95  ];
96  }
97 
105  public function testUserToolLinks( $expected, $userId, $userText ) {
106  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
107  if ( $userText === '' ) {
108  Wikimedia\suppressWarnings();
109  }
110  $actual = Linker::userToolLinks( $userId, $userText );
111  if ( $userText === '' ) {
112  Wikimedia\restoreWarnings();
113  }
114 
115  $this->assertSame( $expected, $actual );
116  }
117 
118  public static function provideUserToolLinks() {
119  return [
120  // Empty name (T222529)
121  'Empty username, userid 0' => [ ' (no username available)', 0, '' ],
122  'Empty username, userid > 0' => [ ' (no username available)', 73, '' ],
123  ];
124  }
125 
133  public function testUserTalkLink( $expected, $userId, $userText ) {
134  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
135  if ( $userText === '' ) {
136  Wikimedia\suppressWarnings();
137  }
138  $actual = Linker::userTalkLink( $userId, $userText );
139  if ( $userText === '' ) {
140  Wikimedia\restoreWarnings();
141  }
142 
143  $this->assertSame( $expected, $actual );
144  }
145 
146  public static function provideUserTalkLink() {
147  return [
148  // Empty name (T222529)
149  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
150  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
151  ];
152  }
153 
161  public function testBlockLink( $expected, $userId, $userText ) {
162  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
163  if ( $userText === '' ) {
164  Wikimedia\suppressWarnings();
165  }
166  $actual = Linker::blockLink( $userId, $userText );
167  if ( $userText === '' ) {
168  Wikimedia\restoreWarnings();
169  }
170 
171  $this->assertSame( $expected, $actual );
172  }
173 
174  public static function provideBlockLink() {
175  return [
176  // Empty name (T222529)
177  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
178  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
179  ];
180  }
181 
189  public function testEmailLink( $expected, $userId, $userText ) {
190  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
191  if ( $userText === '' ) {
192  Wikimedia\suppressWarnings();
193  }
194  $actual = Linker::emailLink( $userId, $userText );
195  if ( $userText === '' ) {
196  Wikimedia\restoreWarnings();
197  }
198 
199  $this->assertSame( $expected, $actual );
200  }
201 
202  public static function provideEmailLink() {
203  return [
204  // Empty name (T222529)
205  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
206  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
207  ];
208  }
209 
216  public function testFormatComment(
217  $expected, $comment, $title = false, $local = false, $wikiId = null
218  ) {
219  $conf = new SiteConfiguration();
220  $conf->settings = [
221  'wgServer' => [
222  'enwiki' => '//en.example.org',
223  'dewiki' => '//de.example.org',
224  ],
225  'wgArticlePath' => [
226  'enwiki' => '/w/$1',
227  'dewiki' => '/w/$1',
228  ],
229  ];
230  $conf->suffixes = [ 'wiki' ];
231 
232  $this->setMwGlobals( [
233  'wgScript' => '/wiki/index.php',
234  'wgArticlePath' => '/wiki/$1',
235  'wgCapitalLinks' => true,
236  'wgConf' => $conf,
237  ] );
238 
239  if ( $title === false ) {
240  // We need a page title that exists
241  $title = Title::newFromText( 'Special:BlankPage' );
242  }
243 
244  $this->assertEquals(
245  $expected,
246  Linker::formatComment( $comment, $title, $local, $wikiId )
247  );
248  }
249 
250  public function provideCasesForFormatComment() {
251  $wikiId = 'enwiki'; // $wgConf has a fake entry for this
252 
253  // phpcs:disable Generic.Files.LineLength
254  return [
255  // Linker::formatComment
256  [
257  'a&lt;script&gt;b',
258  'a<script>b',
259  ],
260  [
261  'a—b',
262  'a&mdash;b',
263  ],
264  [
265  "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
266  "'''not bolded'''",
267  ],
268  [
269  "try &lt;script&gt;evil&lt;/scipt&gt; things",
270  "try <script>evil</scipt> things",
271  ],
272  // Linker::formatAutocomments
273  [
274  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
275  "/* autocomment */",
276  ],
277  [
278  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→‎&#91;[linkie?]]</a></span></span>',
279  "/* [[linkie?]] */",
280  ],
281  [
282  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage" title="Special:BlankPage">→‎</a>: </span> // Edit via via</span>',
283  // Regression test for T222857
284  "/* */ // Edit via via",
285  ],
286  [
287  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> post</span>',
288  "/* autocomment */ post",
289  ],
290  [
291  'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
292  "pre /* autocomment */",
293  ],
294  [
295  'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> post</span>',
296  "pre /* autocomment */ post",
297  ],
298  [
299  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> multiple? <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment2" title="Special:BlankPage">→‎autocomment2</a></span></span></span>',
300  "/* autocomment */ multiple? /* autocomment2 */",
301  ],
302  [
303  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→‎autocomment containing /*</a>: </span> T70361</span>',
304  "/* autocomment containing /* */ T70361"
305  ],
306  [
307  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.22quotes.22" title="Special:BlankPage">→‎autocomment containing &quot;quotes&quot;</a></span></span>',
308  "/* autocomment containing \"quotes\" */"
309  ],
310  [
311  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.3Cscript.3Etags.3C.2Fscript.3E" title="Special:BlankPage">→‎autocomment containing &lt;script&gt;tags&lt;/script&gt;</a></span></span>',
312  "/* autocomment containing <script>tags</script> */"
313  ],
314  [
315  '<span dir="auto"><span class="autocomment"><a href="#autocomment">→‎autocomment</a></span></span>',
316  "/* autocomment */",
317  false, true
318  ],
319  [
320  '<span dir="auto"><span class="autocomment">autocomment</span></span>',
321  "/* autocomment */",
322  null
323  ],
324  [
325  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
326  "/* autocomment */",
327  false, false
328  ],
329  [
330  '<span dir="auto"><span class="autocomment"><a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→‎autocomment</a></span></span>',
331  "/* autocomment */",
332  false, false, $wikiId
333  ],
334  // Linker::formatLinksInComment
335  [
336  'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">link</a> def',
337  "abc [[link]] def",
338  ],
339  [
340  'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">text</a> def',
341  "abc [[link|text]] def",
342  ],
343  [
344  'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
345  "abc [[Special:BlankPage|]] def",
346  ],
347  [
348  'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&amp;action=edit&amp;redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def',
349  "abc [[%C4%85%C5%9B%C5%BC]] def",
350  ],
351  [
352  'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
353  "abc [[#section]] def",
354  ],
355  [
356  'abc <a href="/wiki/index.php?title=/subpage&amp;action=edit&amp;redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
357  "abc [[/subpage]] def",
358  ],
359  [
360  'abc <a href="/wiki/index.php?title=%22evil!%22&amp;action=edit&amp;redlink=1" class="new" title="&quot;evil!&quot; (page does not exist)">&quot;evil!&quot;</a> def',
361  "abc [[\"evil!\"]] def",
362  ],
363  [
364  'abc [[&lt;script&gt;very evil&lt;/script&gt;]] def',
365  "abc [[<script>very evil</script>]] def",
366  ],
367  [
368  'abc [[|]] def',
369  "abc [[|]] def",
370  ],
371  [
372  'abc <a href="/wiki/index.php?title=Link&amp;action=edit&amp;redlink=1" class="new" title="Link (page does not exist)">link</a> def',
373  "abc [[link]] def",
374  false, false
375  ],
376  [
377  'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def',
378  "abc [[link]] def",
379  false, false, $wikiId
380  ],
381  ];
382  // phpcs:enable
383  }
384 
389  public function testFormatLinksInComment( $expected, $input, $wiki ) {
390  $conf = new SiteConfiguration();
391  $conf->settings = [
392  'wgServer' => [
393  'enwiki' => '//en.example.org'
394  ],
395  'wgArticlePath' => [
396  'enwiki' => '/w/$1',
397  ],
398  ];
399  $conf->suffixes = [ 'wiki' ];
400  $this->setMwGlobals( [
401  'wgScript' => '/wiki/index.php',
402  'wgArticlePath' => '/wiki/$1',
403  'wgCapitalLinks' => true,
404  'wgConf' => $conf,
405  ] );
406 
407  $this->assertEquals(
408  $expected,
409  Linker::formatLinksInComment( $input, Title::newFromText( 'Special:BlankPage' ), false, $wiki )
410  );
411  }
412 
417  public function testGenerateRollback( $rollbackEnabled, $expectedModules ) {
418  $this->markTestSkippedIfDbType( 'postgres' );
419 
421  $user = $context->getUser();
422  $user->setOption( 'showrollbackconfirmation', $rollbackEnabled );
423 
424  $pageData = $this->insertPage( 'Rollback_Test_Page' );
425  $page = WikiPage::factory( $pageData['title'] );
426 
427  $updater = $page->newPageUpdater( $user );
428  $updater->setContent( \MediaWiki\Revision\SlotRecord::MAIN,
429  new TextContent( 'Technical Wishes 123!' )
430  );
431  $summary = CommentStoreComment::newUnsavedComment( 'Some comment!' );
432  $updater->saveRevision( $summary );
433 
434  $rollbackOutput = Linker::generateRollback( $page->getRevision(), $context );
435  $modules = $context->getOutput()->getModules();
436 
437  $this->assertEquals( $expectedModules, $modules );
438  $this->assertContains( 'rollback 1 edit', $rollbackOutput );
439  }
440 
441  public static function provideCasesForRollbackGeneration() {
442  return [
443  [
444  true,
445  [ 'mediawiki.page.rollback.confirmation' ]
446 
447  ],
448  [
449  false,
450  []
451  ]
452  ];
453  }
454 
455  public static function provideCasesForFormatLinksInComment() {
456  // phpcs:disable Generic.Files.LineLength
457  return [
458  [
459  'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
460  'foo bar [[Special:BlankPage]]',
461  null,
462  ],
463  [
464  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
465  '[[ :Special:BlankPage]]',
466  null,
467  ],
468  [
469  '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
470  "[[Foo'bar]]",
471  'enwiki',
472  ],
473  [
474  'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>',
475  'foo bar [[Special:BlankPage]]',
476  'enwiki',
477  ],
478  [
479  'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>',
480  'foo bar [[Image:Example]]',
481  'enwiki',
482  ],
483  ];
484  // phpcs:enable
485  }
486 
487  public static function provideLinkBeginHook() {
488  // phpcs:disable Generic.Files.LineLength
489  return [
490  // Modify $html
491  [
492  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
493  $html = 'foobar';
494  },
495  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
496  ],
497  // Modify $attribs
498  [
499  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
500  $attribs['bar'] = 'baz';
501  },
502  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
503  ],
504  // Modify $query
505  [
506  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
507  $query['bar'] = 'baz';
508  },
509  '<a href="/w/index.php?title=Special:BlankPage&amp;bar=baz" title="Special:BlankPage">Special:BlankPage</a>'
510  ],
511  // Force HTTP $options
512  [
513  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
514  $options = [ 'http' ];
515  },
516  '<a href="http://example.org/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>'
517  ],
518  // Force 'forcearticlepath' in $options
519  [
520  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
521  $options = [ 'forcearticlepath' ];
522  $query['foo'] = 'bar';
523  },
524  '<a href="/wiki/Special:BlankPage?foo=bar" title="Special:BlankPage">Special:BlankPage</a>'
525  ],
526  // Abort early
527  [
528  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
529  $ret = 'foobar';
530  return false;
531  },
532  'foobar'
533  ],
534  ];
535  // phpcs:enable
536  }
537 
542  public function testLinkBeginHook( $callback, $expected ) {
543  $this->hideDeprecated( 'LinkBegin hook (used in hook-LinkBegin-closure)' );
544  $this->setMwGlobals( [
545  'wgArticlePath' => '/wiki/$1',
546  'wgServer' => '//example.org',
547  'wgCanonicalServer' => 'http://example.org',
548  'wgScriptPath' => '/w',
549  'wgScript' => '/w/index.php',
550  ] );
551 
552  $this->setMwGlobals( 'wgHooks', [ 'LinkBegin' => [ $callback ] ] );
553  $title = SpecialPage::getTitleFor( 'Blankpage' );
554  $out = Linker::link( $title );
555  $this->assertEquals( $expected, $out );
556  }
557 
558  public static function provideLinkEndHook() {
559  return [
560  // Override $html
561  [
562  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
563  $html = 'foobar';
564  },
565  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
566  ],
567  // Modify $attribs
568  [
569  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
570  $attribs['bar'] = 'baz';
571  },
572  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
573  ],
574  // Fully override return value and abort hook
575  [
576  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
577  $ret = 'blahblahblah';
578  return false;
579  },
580  'blahblahblah'
581  ],
582 
583  ];
584  }
585 
590  public function testLinkEndHook( $callback, $expected ) {
591  $this->hideDeprecated( 'LinkEnd hook (used in hook-LinkEnd-closure)' );
592  $this->setMwGlobals( [
593  'wgArticlePath' => '/wiki/$1',
594  ] );
595 
596  $this->setMwGlobals( 'wgHooks', [ 'LinkEnd' => [ $callback ] ] );
597 
598  $title = SpecialPage::getTitleFor( 'Blankpage' );
599  $out = Linker::link( $title );
600  $this->assertEquals( $expected, $out );
601  }
602 }
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:138
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 & $html
Definition: hooks.txt:1982
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1585
static provideEmailLink()
Definition: LinkerTest.php:202
static provideUserToolLinks()
Definition: LinkerTest.php:118
if(is_array( $mode)) switch( $mode) $input
static provideCasesForRollbackGeneration()
Definition: LinkerTest.php:441
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
static provideBlockLink()
Definition: LinkerTest.php:174
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 & $ret
Definition: hooks.txt:1982
testFormatComment( $expected, $comment, $title=false, $local=false, $wikiId=null)
provideCasesForFormatComment Linker::formatComment Linker::formatAutocomments Linker::formatLinksInCo...
Definition: LinkerTest.php:216
testBlockLink( $expected, $userId, $userText)
provideBlockLink Linker::blockLink
Definition: LinkerTest.php:161
markTestSkippedIfDbType( $type)
Skip the test if using the specified database type.
A helper class for throttling authentication attempts.
static emailLink( $userId, $userText)
Definition: Linker.php:1075
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1809
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
testUserTalkLink( $expected, $userId, $userText)
provideUserTalkLink Linker::userTalkLink
Definition: LinkerTest.php:133
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:780
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:1982
testGenerateRollback( $rollbackEnabled, $expectedModules)
Linker::generateRollback provideCasesForRollbackGeneration.
Definition: LinkerTest.php:417
static formatLinksInComment( $comment, $title=null, $local=false, $wikiId=null)
Formats wiki links and media links in text; all other wiki formatting is ignored. ...
Definition: Linker.php:1295
$modules
static getMain()
Get the RequestContext object associated with the main request.
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
Definition: Linker.php:1156
insertPage( $pageName, $text='Sample page for unit test.', $namespace=null, User $user=null)
Insert a new page.
static provideCasesForFormatLinksInComment()
Definition: LinkerTest.php:455
static userToolLinks( $userId, $userText, $redContribsWhenNoEdits=false, $flags=0, $edits=null, $useParentheses=true)
Generate standard user tool links (talk, contributions, block link, etc.)
Definition: Linker.php:941
static provideUserTalkLink()
Definition: LinkerTest.php:146
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 & $options
Definition: hooks.txt:1982
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 & $attribs
Definition: hooks.txt:1982
static provideCasesForUserLink()
Definition: LinkerTest.php:29
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
testFormatLinksInComment( $expected, $input, $wiki)
Linker::formatLinksInComment provideCasesForFormatLinksInComment.
Definition: LinkerTest.php:389
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don&#39;t need a full Title object...
Definition: SpecialPage.php:82
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown...
testLinkBeginHook( $callback, $expected)
MediaWiki\Linker\LinkRenderer::runLegacyBeginHook provideLinkBeginHook.
Definition: LinkerTest.php:542
hideDeprecated( $function)
Don&#39;t throw a warning if $function is deprecated and called later.
provideCasesForFormatComment()
Definition: LinkerTest.php:250
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:896
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
Database.
Definition: LinkerTest.php:6
static userTalkLink( $userId, $userText)
Definition: Linker.php:1032
static provideLinkEndHook()
Definition: LinkerTest.php:558
static provideLinkBeginHook()
Definition: LinkerTest.php:487
$page->newPageUpdater($user) $updater
Definition: pageupdater.txt:63
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext $context
Definition: hooks.txt:2633
testUserToolLinks( $expected, $userId, $userText)
provideUserToolLinks Linker::userToolLinks
Definition: LinkerTest.php:105
testEmailLink( $expected, $userId, $userText)
provideEmailLink Linker::emailLink
Definition: LinkerTest.php:189
This is a class for holding configuration settings, particularly for multi-wiki sites.
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:84
testLinkEndHook( $callback, $expected)
MediaWiki\Linker\LinkRenderer::buildAElement provideLinkEndHook.
Definition: LinkerTest.php:590
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1473
static blockLink( $userId, $userText)
Definition: Linker.php:1054
testUserLink( $expected, $userId, $userName, $altUserName=false, $msg='')
provideCasesForUserLink Linker::userLink
Definition: LinkerTest.php:12
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:319