MediaWiki  master
LinkerTest.php
Go to the documentation of this file.
1 <?php
2 
11  public function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg = '' ) {
12  $this->setMwGlobals( [
13  'wgArticlePath' => '/wiki/$1',
14  ] );
15 
16  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
17  if ( !$userName ) {
18  Wikimedia\suppressWarnings();
19  }
20  $actual = Linker::userLink( $userId, $userName, $altUserName );
21  if ( !$userName ) {
22  Wikimedia\restoreWarnings();
23  }
24 
25  $this->assertEquals( $expected, $actual, $msg );
26  }
27 
28  public static function provideCasesForUserLink() {
29  # Format:
30  # - expected
31  # - userid
32  # - username
33  # - optional altUserName
34  # - optional message
35  return [
36  # Empty name (T222529)
37  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
38  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
39 
40  'false instead of username' => [ '(no username available)', 73, false ],
41  'null instead of username' => [ '(no username available)', 0, null ],
42 
43  # ## ANONYMOUS USER ########################################
44  [
45  '<a href="/wiki/Special:Contributions/JohnDoe" '
46  . 'class="mw-userlink mw-anonuserlink" '
47  . 'title="Special:Contributions/JohnDoe"><bdi>JohnDoe</bdi></a>',
48  0, 'JohnDoe', false,
49  ],
50  [
51  '<a href="/wiki/Special:Contributions/::1" '
52  . 'class="mw-userlink mw-anonuserlink" '
53  . 'title="Special:Contributions/::1"><bdi>::1</bdi></a>',
54  0, '::1', false,
55  'Anonymous with pretty IPv6'
56  ],
57  [
58  '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
59  . 'class="mw-userlink mw-anonuserlink" '
60  . 'title="Special:Contributions/0:0:0:0:0:0:0:1"><bdi>::1</bdi></a>',
61  0, '0:0:0:0:0:0:0:1', false,
62  'Anonymous with almost pretty IPv6'
63  ],
64  [
65  '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
66  . 'class="mw-userlink mw-anonuserlink" '
67  . 'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001"><bdi>::1</bdi></a>',
68  0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
69  'Anonymous with full IPv6'
70  ],
71  [
72  '<a href="/wiki/Special:Contributions/::1" '
73  . 'class="mw-userlink mw-anonuserlink" '
74  . 'title="Special:Contributions/::1"><bdi>AlternativeUsername</bdi></a>',
75  0, '::1', 'AlternativeUsername',
76  'Anonymous with pretty IPv6 and an alternative username'
77  ],
78 
79  # IPV4
80  [
81  '<a href="/wiki/Special:Contributions/127.0.0.1" '
82  . 'class="mw-userlink mw-anonuserlink" '
83  . 'title="Special:Contributions/127.0.0.1"><bdi>127.0.0.1</bdi></a>',
84  0, '127.0.0.1', false,
85  'Anonymous with IPv4'
86  ],
87  [
88  '<a href="/wiki/Special:Contributions/127.0.0.1" '
89  . 'class="mw-userlink mw-anonuserlink" '
90  . 'title="Special:Contributions/127.0.0.1"><bdi>AlternativeUsername</bdi></a>',
91  0, '127.0.0.1', 'AlternativeUsername',
92  'Anonymous with IPv4 and an alternative username'
93  ],
94 
95  # ## Regular user ##########################################
96  # TODO!
97  ];
98  }
99 
107  public function testUserToolLinks( $expected, $userId, $userText ) {
108  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
109  if ( $userText === '' ) {
110  Wikimedia\suppressWarnings();
111  }
112  $actual = Linker::userToolLinks( $userId, $userText );
113  if ( $userText === '' ) {
114  Wikimedia\restoreWarnings();
115  }
116 
117  $this->assertSame( $expected, $actual );
118  }
119 
120  public static function provideUserToolLinks() {
121  return [
122  // Empty name (T222529)
123  'Empty username, userid 0' => [ ' (no username available)', 0, '' ],
124  'Empty username, userid > 0' => [ ' (no username available)', 73, '' ],
125  ];
126  }
127 
135  public function testUserTalkLink( $expected, $userId, $userText ) {
136  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
137  if ( $userText === '' ) {
138  Wikimedia\suppressWarnings();
139  }
140  $actual = Linker::userTalkLink( $userId, $userText );
141  if ( $userText === '' ) {
142  Wikimedia\restoreWarnings();
143  }
144 
145  $this->assertSame( $expected, $actual );
146  }
147 
148  public static function provideUserTalkLink() {
149  return [
150  // Empty name (T222529)
151  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
152  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
153  ];
154  }
155 
163  public function testBlockLink( $expected, $userId, $userText ) {
164  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
165  if ( $userText === '' ) {
166  Wikimedia\suppressWarnings();
167  }
168  $actual = Linker::blockLink( $userId, $userText );
169  if ( $userText === '' ) {
170  Wikimedia\restoreWarnings();
171  }
172 
173  $this->assertSame( $expected, $actual );
174  }
175 
176  public static function provideBlockLink() {
177  return [
178  // Empty name (T222529)
179  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
180  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
181  ];
182  }
183 
191  public function testEmailLink( $expected, $userId, $userText ) {
192  // We'd also test the warning, but injecting a mock logger into a static method is tricky.
193  if ( $userText === '' ) {
194  Wikimedia\suppressWarnings();
195  }
196  $actual = Linker::emailLink( $userId, $userText );
197  if ( $userText === '' ) {
198  Wikimedia\restoreWarnings();
199  }
200 
201  $this->assertSame( $expected, $actual );
202  }
203 
204  public static function provideEmailLink() {
205  return [
206  // Empty name (T222529)
207  'Empty username, userid 0' => [ '(no username available)', 0, '' ],
208  'Empty username, userid > 0' => [ '(no username available)', 73, '' ],
209  ];
210  }
211 
218  public function testFormatComment(
219  $expected, $comment, $title = false, $local = false, $wikiId = null
220  ) {
221  $conf = new SiteConfiguration();
222  $conf->settings = [
223  'wgServer' => [
224  'enwiki' => '//en.example.org',
225  'dewiki' => '//de.example.org',
226  ],
227  'wgArticlePath' => [
228  'enwiki' => '/w/$1',
229  'dewiki' => '/w/$1',
230  ],
231  ];
232  $conf->suffixes = [ 'wiki' ];
233 
234  $this->setMwGlobals( [
235  'wgScript' => '/wiki/index.php',
236  'wgArticlePath' => '/wiki/$1',
237  'wgCapitalLinks' => true,
238  'wgConf' => $conf,
239  ] );
240 
241  if ( $title === false ) {
242  // We need a page title that exists
243  $title = Title::newFromText( 'Special:BlankPage' );
244  }
245 
246  $this->assertEquals(
247  $expected,
248  Linker::formatComment( $comment, $title, $local, $wikiId )
249  );
250  }
251 
252  public function provideCasesForFormatComment() {
253  $wikiId = 'enwiki'; // $wgConf has a fake entry for this
254 
255  // phpcs:disable Generic.Files.LineLength
256  return [
257  // Linker::formatComment
258  [
259  'a&lt;script&gt;b',
260  'a<script>b',
261  ],
262  [
263  'a—b',
264  'a&mdash;b',
265  ],
266  [
267  "&#039;&#039;&#039;not bolded&#039;&#039;&#039;",
268  "'''not bolded'''",
269  ],
270  [
271  "try &lt;script&gt;evil&lt;/scipt&gt; things",
272  "try <script>evil</scipt> things",
273  ],
274  // Linker::formatAutocomments
275  [
276  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
277  "/* autocomment */",
278  ],
279  [
280  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→‎&#91;[linkie?]]</a></span></span>',
281  "/* [[linkie?]] */",
282  ],
283  [
284  '<span dir="auto"><span class="autocomment">: </span> // Edit via via</span>',
285  // Regression test for T222857
286  "/* */ // Edit via via",
287  ],
288  [
289  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> post</span>',
290  "/* autocomment */ post",
291  ],
292  [
293  'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
294  "pre /* autocomment */",
295  ],
296  [
297  'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a>: </span> post</span>',
298  "pre /* autocomment */ post",
299  ],
300  [
301  '<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>',
302  "/* autocomment */ multiple? /* autocomment2 */",
303  ],
304  [
305  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→‎autocomment containing /*</a>: </span> T70361</span>',
306  "/* autocomment containing /* */ T70361"
307  ],
308  [
309  '<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>',
310  "/* autocomment containing \"quotes\" */"
311  ],
312  [
313  '<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>',
314  "/* autocomment containing <script>tags</script> */"
315  ],
316  [
317  '<span dir="auto"><span class="autocomment"><a href="#autocomment">→‎autocomment</a></span></span>',
318  "/* autocomment */",
319  false, true
320  ],
321  [
322  '<span dir="auto"><span class="autocomment">autocomment</span></span>',
323  "/* autocomment */",
324  null
325  ],
326  [
327  '',
328  "/* */",
329  false, true
330  ],
331  [
332  '',
333  "/* */",
334  null
335  ],
336  [
337  '<span dir="auto"><span class="autocomment">[[</span></span>',
338  "/* [[ */",
339  false, true
340  ],
341  [
342  '<span dir="auto"><span class="autocomment">[[</span></span>',
343  "/* [[ */",
344  null
345  ],
346  [
347  "foo <span dir=\"auto\"><span class=\"autocomment\"><a href=\"#.23\">→‎&#91;[#_\t_]]</a></span></span>",
348  "foo /* [[#_\t_]] */",
349  false, true
350  ],
351  [
352  "foo <span dir=\"auto\"><span class=\"autocomment\"><a href=\"#_.09\">#_\t_</a></span></span>",
353  "foo /* [[#_\t_]] */",
354  null
355  ],
356  [
357  '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→‎autocomment</a></span></span>',
358  "/* autocomment */",
359  false, false
360  ],
361  [
362  '<span dir="auto"><span class="autocomment"><a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→‎autocomment</a></span></span>',
363  "/* autocomment */",
364  false, false, $wikiId
365  ],
366  // Linker::formatLinksInComment
367  [
368  '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',
369  "abc [[link]] 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)">text</a> def',
373  "abc [[link|text]] def",
374  ],
375  [
376  'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
377  "abc [[Special:BlankPage|]] def",
378  ],
379  [
380  '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',
381  "abc [[%C4%85%C5%9B%C5%BC]] def",
382  ],
383  [
384  'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
385  "abc [[#section]] def",
386  ],
387  [
388  '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',
389  "abc [[/subpage]] def",
390  ],
391  [
392  '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',
393  "abc [[\"evil!\"]] def",
394  ],
395  [
396  'abc [[&lt;script&gt;very evil&lt;/script&gt;]] def',
397  "abc [[<script>very evil</script>]] def",
398  ],
399  [
400  'abc [[|]] def',
401  "abc [[|]] def",
402  ],
403  [
404  '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',
405  "abc [[link]] def",
406  false, false
407  ],
408  [
409  'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def',
410  "abc [[link]] def",
411  false, false, $wikiId
412  ],
413  ];
414  // phpcs:enable
415  }
416 
421  public function testFormatLinksInComment( $expected, $input, $wiki ) {
422  $conf = new SiteConfiguration();
423  $conf->settings = [
424  'wgServer' => [
425  'enwiki' => '//en.example.org'
426  ],
427  'wgArticlePath' => [
428  'enwiki' => '/w/$1',
429  ],
430  ];
431  $conf->suffixes = [ 'wiki' ];
432  $this->setMwGlobals( [
433  'wgScript' => '/wiki/index.php',
434  'wgArticlePath' => '/wiki/$1',
435  'wgCapitalLinks' => true,
436  'wgConf' => $conf,
437  ] );
438 
439  $this->assertEquals(
440  $expected,
441  Linker::formatLinksInComment( $input, Title::newFromText( 'Special:BlankPage' ), false, $wiki )
442  );
443  }
444 
449  public function testGenerateRollback( $rollbackEnabled, $expectedModules, $title ) {
450  $this->markTestSkippedIfDbType( 'postgres' );
451 
453  $user = $context->getUser();
454  $user->setOption( 'showrollbackconfirmation', $rollbackEnabled );
455 
456  $this->assertEquals( 0, Title::newFromText( $title )->getArticleID() );
457  $pageData = $this->insertPage( $title );
458  $page = WikiPage::factory( $pageData['title'] );
459 
460  $updater = $page->newPageUpdater( $user );
461  $updater->setContent( \MediaWiki\Revision\SlotRecord::MAIN,
462  new TextContent( 'Technical Wishes 123!' )
463  );
464  $summary = CommentStoreComment::newUnsavedComment( 'Some comment!' );
465  $updater->saveRevision( $summary );
466 
467  $rollbackOutput = Linker::generateRollback( $page->getRevision(), $context );
468  $modules = $context->getOutput()->getModules();
469  $currentRev = $page->getRevision();
470  $oldestRev = $page->getOldestRevision();
471 
472  $this->assertEquals( $expectedModules, $modules );
473  $this->assertEquals( $user->getName(), $currentRev->getUserText() );
474  $this->assertEquals(
475  static::getTestSysop()->getUser(),
476  $oldestRev->getUserText()
477  );
478 
479  $ids = [];
480  $r = $oldestRev;
481  while ( $r ) {
482  $ids[] = $r->getId();
483  $r = $r->getNext();
484  }
485  $this->assertEquals( [ $oldestRev->getId(), $currentRev->getId() ], $ids );
486 
487  $this->assertContains( 'rollback 1 edit', $rollbackOutput );
488  }
489 
490  public static function provideCasesForRollbackGeneration() {
491  return [
492  [
493  true,
494  [ 'mediawiki.page.rollback.confirmation' ],
495  'Rollback_Test_Page'
496  ],
497  [
498  false,
499  [],
500  'Rollback_Test_Page2'
501  ]
502  ];
503  }
504 
505  public static function provideCasesForFormatLinksInComment() {
506  // phpcs:disable Generic.Files.LineLength
507  return [
508  [
509  'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
510  'foo bar [[Special:BlankPage]]',
511  null,
512  ],
513  [
514  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
515  '[[ :Special:BlankPage]]',
516  null,
517  ],
518  [
519  '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
520  "[[Foo'bar]]",
521  'enwiki',
522  ],
523  [
524  'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>',
525  'foo bar [[Special:BlankPage]]',
526  'enwiki',
527  ],
528  [
529  'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>',
530  'foo bar [[Image:Example]]',
531  'enwiki',
532  ],
533  ];
534  // phpcs:enable
535  }
536 
537  public static function provideLinkBeginHook() {
538  // phpcs:disable Generic.Files.LineLength
539  return [
540  // Modify $html
541  [
542  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
543  $html = 'foobar';
544  },
545  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
546  ],
547  // Modify $attribs
548  [
549  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
550  $attribs['bar'] = 'baz';
551  },
552  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
553  ],
554  // Modify $query
555  [
556  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
557  $query['bar'] = 'baz';
558  },
559  '<a href="/w/index.php?title=Special:BlankPage&amp;bar=baz" title="Special:BlankPage">Special:BlankPage</a>'
560  ],
561  // Force HTTP $options
562  [
563  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
564  $options = [ 'http' ];
565  },
566  '<a href="http://example.org/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>'
567  ],
568  // Force 'forcearticlepath' in $options
569  [
570  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
571  $options = [ 'forcearticlepath' ];
572  $query['foo'] = 'bar';
573  },
574  '<a href="/wiki/Special:BlankPage?foo=bar" title="Special:BlankPage">Special:BlankPage</a>'
575  ],
576  // Abort early
577  [
578  function ( $dummy, $title, &$html, &$attribs, &$query, &$options, &$ret ) {
579  $ret = 'foobar';
580  return false;
581  },
582  'foobar'
583  ],
584  ];
585  // phpcs:enable
586  }
587 
592  public function testLinkBeginHook( $callback, $expected ) {
593  $this->hideDeprecated( 'LinkBegin hook (used in hook-LinkBegin-closure)' );
594  $this->setMwGlobals( [
595  'wgArticlePath' => '/wiki/$1',
596  'wgServer' => '//example.org',
597  'wgCanonicalServer' => 'http://example.org',
598  'wgScriptPath' => '/w',
599  'wgScript' => '/w/index.php',
600  ] );
601 
602  $this->setMwGlobals( 'wgHooks', [ 'LinkBegin' => [ $callback ] ] );
603  $title = SpecialPage::getTitleFor( 'Blankpage' );
604  $out = Linker::link( $title );
605  $this->assertEquals( $expected, $out );
606  }
607 
608  public static function provideLinkEndHook() {
609  return [
610  // Override $html
611  [
612  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
613  $html = 'foobar';
614  },
615  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
616  ],
617  // Modify $attribs
618  [
619  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
620  $attribs['bar'] = 'baz';
621  },
622  '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
623  ],
624  // Fully override return value and abort hook
625  [
626  function ( $dummy, $title, $options, &$html, &$attribs, &$ret ) {
627  $ret = 'blahblahblah';
628  return false;
629  },
630  'blahblahblah'
631  ],
632 
633  ];
634  }
635 
640  public function testLinkEndHook( $callback, $expected ) {
641  $this->hideDeprecated( 'LinkEnd hook (used in hook-LinkEnd-closure)' );
642  $this->setMwGlobals( [
643  'wgArticlePath' => '/wiki/$1',
644  ] );
645 
646  $this->setMwGlobals( 'wgHooks', [ 'LinkEnd' => [ $callback ] ] );
647 
648  $title = SpecialPage::getTitleFor( 'Blankpage' );
649  $out = Linker::link( $title );
650  $this->assertEquals( $expected, $out );
651  }
652 }
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:1963
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:1566
static provideEmailLink()
Definition: LinkerTest.php:204
static provideUserToolLinks()
Definition: LinkerTest.php:120
if(is_array( $mode)) switch( $mode) $input
static provideCasesForRollbackGeneration()
Definition: LinkerTest.php:490
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
static provideBlockLink()
Definition: LinkerTest.php:176
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:1963
testFormatComment( $expected, $comment, $title=false, $local=false, $wikiId=null)
provideCasesForFormatComment Linker::formatComment Linker::formatAutocomments Linker::formatLinksInCo...
Definition: LinkerTest.php:218
testBlockLink( $expected, $userId, $userText)
provideBlockLink Linker::blockLink
Definition: LinkerTest.php:163
A helper class for throttling authentication attempts.
static emailLink( $userId, $userText)
Definition: Linker.php:1073
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
Definition: Linker.php:1811
static newUnsavedComment( $comment, array $data=null)
Create a new, unsaved CommentStoreComment.
testUserTalkLink( $expected, $userId, $userText)
provideUserTalkLink Linker::userTalkLink
Definition: LinkerTest.php:135
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:767
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:1963
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:1297
$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:1159
static provideCasesForFormatLinksInComment()
Definition: LinkerTest.php:505
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:939
static provideUserTalkLink()
Definition: LinkerTest.php:148
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:1963
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:1963
static provideCasesForUserLink()
Definition: LinkerTest.php:28
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:767
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:912
testFormatLinksInComment( $expected, $input, $wiki)
Linker::formatLinksInComment provideCasesForFormatLinksInComment.
Definition: LinkerTest.php:421
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:83
testLinkBeginHook( $callback, $expected)
MediaWiki\Linker\LinkRenderer::runLegacyBeginHook provideLinkBeginHook.
Definition: LinkerTest.php:592
provideCasesForFormatComment()
Definition: LinkerTest.php:252
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
Definition: Linker.php:894
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:1030
static provideLinkEndHook()
Definition: LinkerTest.php:608
static provideLinkBeginHook()
Definition: LinkerTest.php:537
$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:2614
testUserToolLinks( $expected, $userId, $userText)
provideUserToolLinks Linker::userToolLinks
Definition: LinkerTest.php:107
testEmailLink( $expected, $userId, $userText)
provideEmailLink Linker::emailLink
Definition: LinkerTest.php:191
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
testGenerateRollback( $rollbackEnabled, $expectedModules, $title)
Linker::generateRollback provideCasesForRollbackGeneration.
Definition: LinkerTest.php:449
testLinkEndHook( $callback, $expected)
MediaWiki\Linker\LinkRenderer::buildAElement provideLinkEndHook.
Definition: LinkerTest.php:640
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1454
static blockLink( $userId, $userText)
Definition: Linker.php:1052
testUserLink( $expected, $userId, $userName, $altUserName=false, $msg='')
provideCasesForUserLink Linker::userLink
Definition: LinkerTest.php:11
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:320