Go to the documentation of this file.
12 public function testUserLink( $expected, $userId, $userName, $altUserName =
false, $msg =
'' ) {
14 'wgArticlePath' =>
'/wiki/$1',
24 public static function provideCasesForUserLink() {
29 # - optional altUserName
33 # ## ANONYMOUS USER ########################################
35 '<a href="/wiki/Special:Contributions/JohnDoe" '
36 .
'class="mw-userlink mw-anonuserlink" '
37 .
'title="Special:Contributions/JohnDoe"><bdi>JohnDoe</bdi></a>',
41 '<a href="/wiki/Special:Contributions/::1" '
42 .
'class="mw-userlink mw-anonuserlink" '
43 .
'title="Special:Contributions/::1"><bdi>::1</bdi></a>',
45 'Anonymous with pretty IPv6'
48 '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" '
49 .
'class="mw-userlink mw-anonuserlink" '
50 .
'title="Special:Contributions/0:0:0:0:0:0:0:1"><bdi>::1</bdi></a>',
51 0,
'0:0:0:0:0:0:0:1',
false,
52 'Anonymous with almost pretty IPv6'
55 '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" '
56 .
'class="mw-userlink mw-anonuserlink" '
57 .
'title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001"><bdi>::1</bdi></a>',
58 0,
'0000:0000:0000:0000:0000:0000:0000:0001',
false,
59 'Anonymous with full IPv6'
62 '<a href="/wiki/Special:Contributions/::1" '
63 .
'class="mw-userlink mw-anonuserlink" '
64 .
'title="Special:Contributions/::1"><bdi>AlternativeUsername</bdi></a>',
65 0,
'::1',
'AlternativeUsername',
66 'Anonymous with pretty IPv6 and an alternative username'
71 '<a href="/wiki/Special:Contributions/127.0.0.1" '
72 .
'class="mw-userlink mw-anonuserlink" '
73 .
'title="Special:Contributions/127.0.0.1"><bdi>127.0.0.1</bdi></a>',
74 0,
'127.0.0.1',
false,
78 '<a href="/wiki/Special:Contributions/127.0.0.1" '
79 .
'class="mw-userlink mw-anonuserlink" '
80 .
'title="Special:Contributions/127.0.0.1"><bdi>AlternativeUsername</bdi></a>',
81 0,
'127.0.0.1',
'AlternativeUsername',
82 'Anonymous with IPv4 and an alternative username'
85 # ## Regular user ##########################################
96 public function testFormatComment(
97 $expected, $comment,
$title =
false, $local =
false, $wikiId =
null
102 'enwiki' =>
'//en.example.org',
103 'dewiki' =>
'//de.example.org',
110 $conf->suffixes = [
'wiki' ];
113 'wgScript' =>
'/wiki/index.php',
114 'wgArticlePath' =>
'/wiki/$1',
115 'wgCapitalLinks' =>
true,
130 public function provideCasesForFormatComment() {
145 "'''not bolded'''",
149 "try <script>evil</scipt> things",
150 "try <script>evil</scipt> things",
154 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a></span></span>',
158 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#linkie.3F" title="Special:BlankPage">→[[linkie?]]</a></span></span>',
162 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a>: </span> post</span>',
163 "/* autocomment */ post",
166 'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a></span></span>',
167 "pre /* autocomment */",
170 'pre <span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a>: </span> post</span>',
171 "pre /* autocomment */ post",
174 '<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>',
175 "/* autocomment */ multiple? /* autocomment2 */",
178 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.2F.2A" title="Special:BlankPage">→autocomment containing /*</a>: </span> T70361</span>',
179 "/* autocomment containing /* */ T70361"
182 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.22quotes.22" title="Special:BlankPage">→autocomment containing "quotes"</a></span></span>',
183 "/* autocomment containing \"quotes\" */"
186 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment_containing_.3Cscript.3Etags.3C.2Fscript.3E" title="Special:BlankPage">→autocomment containing <script>tags</script></a></span></span>',
187 "/* autocomment containing <script>tags</script> */"
190 '<span dir="auto"><span class="autocomment"><a href="#autocomment">→autocomment</a></span></span>',
195 '<span dir="auto"><span class="autocomment">autocomment</span></span>',
200 '<span dir="auto"><span class="autocomment"><a href="/wiki/Special:BlankPage#autocomment" title="Special:BlankPage">→autocomment</a></span></span>',
205 '<span dir="auto"><span class="autocomment"><a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage#autocomment">→autocomment</a></span></span>',
207 false,
false, $wikiId
211 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
215 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">text</a> def',
216 "abc [[link|text]] def",
219 'abc <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a> def',
220 "abc [[Special:BlankPage|]] def",
223 'abc <a href="/wiki/index.php?title=%C4%84%C5%9B%C5%BC&action=edit&redlink=1" class="new" title="Ąśż (page does not exist)">ąśż</a> def',
224 "abc [[%C4%85%C5%9B%C5%BC]] def",
227 'abc <a href="/wiki/Special:BlankPage#section" title="Special:BlankPage">#section</a> def',
228 "abc [[#section]] def",
231 'abc <a href="/wiki/index.php?title=/subpage&action=edit&redlink=1" class="new" title="/subpage (page does not exist)">/subpage</a> def',
232 "abc [[/subpage]] def",
235 'abc <a href="/wiki/index.php?title=%22evil!%22&action=edit&redlink=1" class="new" title=""evil!" (page does not exist)">"evil!"</a> def',
236 "abc [[\"evil!\"]] def",
239 'abc [[<script>very evil</script>]] def',
240 "abc [[<script>very evil</script>]] def",
247 'abc <a href="/wiki/index.php?title=Link&action=edit&redlink=1" class="new" title="Link (page does not exist)">link</a> def',
252 'abc <a class="external" rel="nofollow" href="//en.example.org/w/Link">link</a> def',
254 false,
false, $wikiId
264 public function testFormatLinksInComment( $expected,
$input, $wiki ) {
268 'enwiki' =>
'//en.example.org'
274 $conf->suffixes = [
'wiki' ];
276 'wgScript' =>
'/wiki/index.php',
277 'wgArticlePath' =>
'/wiki/$1',
278 'wgCapitalLinks' =>
true,
292 public function testGenerateRollback( $rollbackEnabled, $expectedModules ) {
297 $user->setOption(
'showrollbackconfirmation', $rollbackEnabled );
299 $pageData = $this->
insertPage(
'Rollback_Test_Page' );
312 $this->assertEquals( $expectedModules,
$modules );
313 $this->assertContains(
'rollback 1 edit', $rollbackOutput );
316 public static function provideCasesForRollbackGeneration() {
320 [
'mediawiki.page.rollback.confirmation' ]
330 public static function provideCasesForFormatLinksInComment() {
334 'foo bar <a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
335 'foo bar [[Special:BlankPage]]',
339 '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>',
340 '[[ :Special:BlankPage]]',
344 '<a class="external" rel="nofollow" href="//en.example.org/w/Foo%27bar">Foo\'bar</a>',
349 'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/Special:BlankPage">Special:BlankPage</a>',
350 'foo bar [[Special:BlankPage]]',
354 'foo bar <a class="external" rel="nofollow" href="//en.example.org/w/File:Example">Image:Example</a>',
355 'foo bar [[Image:Example]]',
362 public static function provideLinkBeginHook() {
370 '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
377 '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
384 '<a href="/w/index.php?title=Special:BlankPage&bar=baz" title="Special:BlankPage">Special:BlankPage</a>'
391 '<a href="http://example.org/wiki/Special:BlankPage" title="Special:BlankPage">Special:BlankPage</a>'
399 '<a href="/wiki/Special:BlankPage?foo=bar" title="Special:BlankPage">Special:BlankPage</a>'
417 public function testLinkBeginHook( $callback, $expected ) {
418 $this->
hideDeprecated(
'LinkBegin hook (used in hook-LinkBegin-closure)' );
420 'wgArticlePath' =>
'/wiki/$1',
421 'wgServer' =>
'//example.org',
422 'wgCanonicalServer' =>
'http://example.org',
423 'wgScriptPath' =>
'/w',
424 'wgScript' =>
'/w/index.php',
427 $this->
setMwGlobals(
'wgHooks', [
'LinkBegin' => [ $callback ] ] );
430 $this->assertEquals( $expected,
$out );
433 public static function provideLinkEndHook() {
440 '<a href="/wiki/Special:BlankPage" title="Special:BlankPage">foobar</a>'
447 '<a href="/wiki/Special:BlankPage" title="Special:BlankPage" bar="baz">Special:BlankPage</a>'
452 $ret =
'blahblahblah';
465 public function testLinkEndHook( $callback, $expected ) {
466 $this->
hideDeprecated(
'LinkEnd hook (used in hook-LinkEnd-closure)' );
468 'wgArticlePath' =>
'/wiki/$1',
471 $this->
setMwGlobals(
'wgHooks', [
'LinkEnd' => [ $callback ] ] );
475 $this->assertEquals( $expected,
$out );
return true to allow those checks to and false if checking is done & $user
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
static formatLinksInComment( $comment, $title=null, $local=false, $wikiId=null)
Formats wiki links and media links in text; all other wiki formatting is ignored.
processing should stop and the error should be shown to the user * false
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
This is a class for holding configuration settings, particularly for multi-wiki sites.
static userLink( $userId, $userName, $altUserName=false)
Make user link (or user contributions for unregistered users)
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
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
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
null for the 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
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
namespace and then decline to actually register it file or subcat img or subcat $title
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
static generateRollback( $rev, IContextSource $context=null, $options=[ 'verify'])
Generate a rollback link for a given revision.
if(is_array( $mode)) switch( $mode) $input
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
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
static link( $target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
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
static getMain()
Get the RequestContext object associated with the main request.
Content object implementation for representing flat text.
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...
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
$page->newPageUpdater($user) $updater
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