MediaWiki REL1_28
UserTest.php
Go to the documentation of this file.
1<?php
2
3define( 'NS_UNITTEST', 5600 );
4define( 'NS_UNITTEST_TALK', 5601 );
5
13 protected $user;
14
15 protected function setUp() {
16 parent::setUp();
17
18 $this->setMwGlobals( [
19 'wgGroupPermissions' => [],
20 'wgRevokePermissions' => [],
21 ] );
22
24
25 $this->user = new User;
26 $this->user->addGroup( 'unittesters' );
27 }
28
29 private function setUpPermissionGlobals() {
31
32 # Data for regular $wgGroupPermissions test
33 $wgGroupPermissions['unittesters'] = [
34 'test' => true,
35 'runtest' => true,
36 'writetest' => false,
37 'nukeworld' => false,
38 ];
39 $wgGroupPermissions['testwriters'] = [
40 'test' => true,
41 'writetest' => true,
42 'modifytest' => true,
43 ];
44
45 # Data for regular $wgRevokePermissions test
46 $wgRevokePermissions['formertesters'] = [
47 'runtest' => true,
48 ];
49
50 # For the options test
51 $wgGroupPermissions['*'] = [
52 'editmyoptions' => true,
53 ];
54 }
55
59 public function testGroupPermissions() {
60 $rights = User::getGroupPermissions( [ 'unittesters' ] );
61 $this->assertContains( 'runtest', $rights );
62 $this->assertNotContains( 'writetest', $rights );
63 $this->assertNotContains( 'modifytest', $rights );
64 $this->assertNotContains( 'nukeworld', $rights );
65
66 $rights = User::getGroupPermissions( [ 'unittesters', 'testwriters' ] );
67 $this->assertContains( 'runtest', $rights );
68 $this->assertContains( 'writetest', $rights );
69 $this->assertContains( 'modifytest', $rights );
70 $this->assertNotContains( 'nukeworld', $rights );
71 }
72
76 public function testRevokePermissions() {
77 $rights = User::getGroupPermissions( [ 'unittesters', 'formertesters' ] );
78 $this->assertNotContains( 'runtest', $rights );
79 $this->assertNotContains( 'writetest', $rights );
80 $this->assertNotContains( 'modifytest', $rights );
81 $this->assertNotContains( 'nukeworld', $rights );
82 }
83
87 public function testUserPermissions() {
88 $rights = $this->user->getRights();
89 $this->assertContains( 'runtest', $rights );
90 $this->assertNotContains( 'writetest', $rights );
91 $this->assertNotContains( 'modifytest', $rights );
92 $this->assertNotContains( 'nukeworld', $rights );
93 }
94
98 public function testUserGetRightsHooks() {
99 $user = new User;
100 $user->addGroup( 'unittesters' );
101 $user->addGroup( 'testwriters' );
102 $userWrapper = TestingAccessWrapper::newFromObject( $user );
103
104 $rights = $user->getRights();
105 $this->assertContains( 'test', $rights, 'sanity check' );
106 $this->assertContains( 'runtest', $rights, 'sanity check' );
107 $this->assertContains( 'writetest', $rights, 'sanity check' );
108 $this->assertNotContains( 'nukeworld', $rights, 'sanity check' );
109
110 // Add a hook manipluating the rights
111 $this->mergeMwGlobalArrayValue( 'wgHooks', [ 'UserGetRights' => [ function ( $user, &$rights ) {
112 $rights[] = 'nukeworld';
113 $rights = array_diff( $rights, [ 'writetest' ] );
114 } ] ] );
115
116 $userWrapper->mRights = null;
117 $rights = $user->getRights();
118 $this->assertContains( 'test', $rights );
119 $this->assertContains( 'runtest', $rights );
120 $this->assertNotContains( 'writetest', $rights );
121 $this->assertContains( 'nukeworld', $rights );
122
123 // Add a Session that limits rights
124 $mock = $this->getMockBuilder( stdclass::class )
125 ->setMethods( [ 'getAllowedUserRights', 'deregisterSession', 'getSessionId' ] )
126 ->getMock();
127 $mock->method( 'getAllowedUserRights' )->willReturn( [ 'test', 'writetest' ] );
128 $mock->method( 'getSessionId' )->willReturn(
129 new MediaWiki\Session\SessionId( str_repeat( 'X', 32 ) )
130 );
131 $session = MediaWiki\Session\TestUtils::getDummySession( $mock );
132 $mockRequest = $this->getMockBuilder( FauxRequest::class )
133 ->setMethods( [ 'getSession' ] )
134 ->getMock();
135 $mockRequest->method( 'getSession' )->willReturn( $session );
136 $userWrapper->mRequest = $mockRequest;
137
138 $userWrapper->mRights = null;
139 $rights = $user->getRights();
140 $this->assertContains( 'test', $rights );
141 $this->assertNotContains( 'runtest', $rights );
142 $this->assertNotContains( 'writetest', $rights );
143 $this->assertNotContains( 'nukeworld', $rights );
144 }
145
150 public function testGetGroupsWithPermission( $expected, $right ) {
151 $result = User::getGroupsWithPermission( $right );
152 sort( $result );
153 sort( $expected );
154
155 $this->assertEquals( $expected, $result, "Groups with permission $right" );
156 }
157
158 public static function provideGetGroupsWithPermission() {
159 return [
160 [
161 [ 'unittesters', 'testwriters' ],
162 'test'
163 ],
164 [
165 [ 'unittesters' ],
166 'runtest'
167 ],
168 [
169 [ 'testwriters' ],
170 'writetest'
171 ],
172 [
173 [ 'testwriters' ],
174 'modifytest'
175 ],
176 ];
177 }
178
183 public function testIsIP( $value, $result, $message ) {
184 $this->assertEquals( $this->user->isIP( $value ), $result, $message );
185 }
186
187 public static function provideIPs() {
188 return [
189 [ '', false, 'Empty string' ],
190 [ ' ', false, 'Blank space' ],
191 [ '10.0.0.0', true, 'IPv4 private 10/8' ],
192 [ '10.255.255.255', true, 'IPv4 private 10/8' ],
193 [ '192.168.1.1', true, 'IPv4 private 192.168/16' ],
194 [ '203.0.113.0', true, 'IPv4 example' ],
195 [ '2002:ffff:ffff:ffff:ffff:ffff:ffff:ffff', true, 'IPv6 example' ],
196 // Not valid IPs but classified as such by MediaWiki for negated asserting
197 // of whether this might be the identifier of a logged-out user or whether
198 // to allow usernames like it.
199 [ '300.300.300.300', true, 'Looks too much like an IPv4 address' ],
200 [ '203.0.113.xxx', true, 'Assigned by UseMod to cloaked logged-out users' ],
201 ];
202 }
203
208 public function testIsValidUserName( $username, $result, $message ) {
209 $this->assertEquals( $this->user->isValidUserName( $username ), $result, $message );
210 }
211
212 public static function provideUserNames() {
213 return [
214 [ '', false, 'Empty string' ],
215 [ ' ', false, 'Blank space' ],
216 [ 'abcd', false, 'Starts with small letter' ],
217 [ 'Ab/cd', false, 'Contains slash' ],
218 [ 'Ab cd', true, 'Whitespace' ],
219 [ '192.168.1.1', false, 'IP' ],
220 [ 'User:Abcd', false, 'Reserved Namespace' ],
221 [ '12abcd232', true, 'Starts with Numbers' ],
222 [ '?abcd', true, 'Start with ? mark' ],
223 [ '#abcd', false, 'Start with #' ],
224 [ 'Abcdകഖഗഘ', true, ' Mixed scripts' ],
225 [ 'ജോസ്‌തോമസ്', false, 'ZWNJ- Format control character' ],
226 [ 'Ab cd', false, ' Ideographic space' ],
227 [ '300.300.300.300', false, 'Looks too much like an IPv4 address' ],
228 [ '302.113.311.900', false, 'Looks too much like an IPv4 address' ],
229 [ '203.0.113.xxx', false, 'Reserved for usage by UseMod for cloaked logged-out users' ],
230 ];
231 }
232
238 public function testAllRightsWithMessage() {
239 // Getting all user rights, for core: User::$mCoreRights, for extensions: $wgAvailableRights
240 $allRights = User::getAllRights();
241 $allMessageKeys = Language::getMessageKeysFor( 'en' );
242
243 $rightsWithMessage = [];
244 foreach ( $allMessageKeys as $message ) {
245 // === 0: must be at beginning of string (position 0)
246 if ( strpos( $message, 'right-' ) === 0 ) {
247 $rightsWithMessage[] = substr( $message, strlen( 'right-' ) );
248 }
249 }
250
251 sort( $allRights );
252 sort( $rightsWithMessage );
253
254 $this->assertEquals(
255 $allRights,
256 $rightsWithMessage,
257 'Each user rights (core/extensions) has a corresponding right- message.'
258 );
259 }
260
266 public function testGetEditCount() {
267 $user = $this->getMutableTestUser()->getUser();
268
269 // let the user have a few (3) edits
270 $page = WikiPage::factory( Title::newFromText( 'Help:UserTest_EditCount' ) );
271 for ( $i = 0; $i < 3; $i++ ) {
272
273 $page->doEditContent(
274 ContentHandler::makeContent( (string)$i, $page->getTitle() ),
275 'test',
276 0,
277 false,
278 $user
279 );
280 }
281
282 $this->assertEquals(
283 3,
285 'After three edits, the user edit count should be 3'
286 );
287
288 // increase the edit count
290
291 $this->assertEquals(
292 4,
294 'After increasing the edit count manually, the user edit count should be 4'
295 );
296 }
297
303 public function testGetEditCountForAnons() {
304 $user = User::newFromName( 'Anonymous' );
305
306 $this->assertNull(
308 'Edit count starts null for anonymous users.'
309 );
310
312
313 $this->assertNull(
315 'Edit count remains null for anonymous users despite calls to increase it.'
316 );
317 }
318
324 public function testIncEditCount() {
325 $user = $this->getMutableTestUser()->getUser();
327
328 $reloadedUser = User::newFromId( $user->getId() );
329 $reloadedUser->incEditCount();
330
331 $this->assertEquals(
332 2,
333 $reloadedUser->getEditCount(),
334 'Increasing the edit count after a fresh load leaves the object up to date.'
335 );
336 }
337
343 public function testOptions() {
344 $user = $this->getMutableTestUser()->getUser();
345
346 $user->setOption( 'userjs-someoption', 'test' );
347 $user->setOption( 'cols', 200 );
349
350 $user = User::newFromName( $user->getName() );
351 $this->assertEquals( 'test', $user->getOption( 'userjs-someoption' ) );
352 $this->assertEquals( 200, $user->getOption( 'cols' ) );
353 }
354
360 public function testAnonOptions() {
362 $this->user->setOption( 'userjs-someoption', 'test' );
363 $this->assertEquals( $wgDefaultUserOptions['cols'], $this->user->getOption( 'cols' ) );
364 $this->assertEquals( 'test', $this->user->getOption( 'userjs-someoption' ) );
365 }
366
376 public function testCheckPasswordValidity() {
377 $this->setMwGlobals( [
378 'wgPasswordPolicy' => [
379 'policies' => [
380 'sysop' => [
381 'MinimalPasswordLength' => 8,
382 'MinimumPasswordLengthToLogin' => 1,
383 'PasswordCannotMatchUsername' => 1,
384 ],
385 'default' => [
386 'MinimalPasswordLength' => 6,
387 'PasswordCannotMatchUsername' => true,
388 'PasswordCannotMatchBlacklist' => true,
389 'MaximalPasswordLength' => 40,
390 ],
391 ],
392 'checks' => [
393 'MinimalPasswordLength' => 'PasswordPolicyChecks::checkMinimalPasswordLength',
394 'MinimumPasswordLengthToLogin' => 'PasswordPolicyChecks::checkMinimumPasswordLengthToLogin',
395 'PasswordCannotMatchUsername' => 'PasswordPolicyChecks::checkPasswordCannotMatchUsername',
396 'PasswordCannotMatchBlacklist' => 'PasswordPolicyChecks::checkPasswordCannotMatchBlacklist',
397 'MaximalPasswordLength' => 'PasswordPolicyChecks::checkMaximalPasswordLength',
398 ],
399 ],
400 ] );
401
402 $user = static::getTestUser()->getUser();
403
404 // Sanity
405 $this->assertTrue( $user->isValidPassword( 'Password1234' ) );
406
407 // Minimum length
408 $this->assertFalse( $user->isValidPassword( 'a' ) );
409 $this->assertFalse( $user->checkPasswordValidity( 'a' )->isGood() );
410 $this->assertTrue( $user->checkPasswordValidity( 'a' )->isOK() );
411 $this->assertEquals( 'passwordtooshort', $user->getPasswordValidity( 'a' ) );
412
413 // Maximum length
414 $longPass = str_repeat( 'a', 41 );
415 $this->assertFalse( $user->isValidPassword( $longPass ) );
416 $this->assertFalse( $user->checkPasswordValidity( $longPass )->isGood() );
417 $this->assertFalse( $user->checkPasswordValidity( $longPass )->isOK() );
418 $this->assertEquals( 'passwordtoolong', $user->getPasswordValidity( $longPass ) );
419
420 // Matches username
421 $this->assertFalse( $user->checkPasswordValidity( $user->getName() )->isGood() );
422 $this->assertTrue( $user->checkPasswordValidity( $user->getName() )->isOK() );
423 $this->assertEquals( 'password-name-match', $user->getPasswordValidity( $user->getName() ) );
424
425 // On the forbidden list
426 $user = User::newFromName( 'Useruser' );
427 $this->assertFalse( $user->checkPasswordValidity( 'Passpass' )->isGood() );
428 $this->assertEquals( 'password-login-forbidden', $user->getPasswordValidity( 'Passpass' ) );
429 }
430
435 public function testGetCanonicalName( $name, $expectedArray ) {
436 // fake interwiki map for the 'Interwiki prefix' testcase
437 $this->mergeMwGlobalArrayValue( 'wgHooks', [
438 'InterwikiLoadPrefix' => [
439 function ( $prefix, &$iwdata ) {
440 if ( $prefix === 'interwiki' ) {
441 $iwdata = [
442 'iw_url' => 'http://example.com/',
443 'iw_local' => 0,
444 'iw_trans' => 0,
445 ];
446 return false;
447 }
448 },
449 ],
450 ] );
451
452 foreach ( $expectedArray as $validate => $expected ) {
453 $this->assertEquals(
454 $expected,
455 User::getCanonicalName( $name, $validate === 'false' ? false : $validate ), $validate );
456 }
457 }
458
459 public static function provideGetCanonicalName() {
460 return [
461 'Leading space' => [ ' Leading space', [ 'creatable' => 'Leading space' ] ],
462 'Trailing space ' => [ 'Trailing space ', [ 'creatable' => 'Trailing space' ] ],
463 'Namespace prefix' => [ 'Talk:Username', [ 'creatable' => false, 'usable' => false,
464 'valid' => false, 'false' => 'Talk:Username' ] ],
465 'Interwiki prefix' => [ 'interwiki:Username', [ 'creatable' => false, 'usable' => false,
466 'valid' => false, 'false' => 'Interwiki:Username' ] ],
467 'With hash' => [ 'name with # hash', [ 'creatable' => false, 'usable' => false ] ],
468 'Multi spaces' => [ 'Multi spaces', [ 'creatable' => 'Multi spaces',
469 'usable' => 'Multi spaces' ] ],
470 'Lowercase' => [ 'lowercase', [ 'creatable' => 'Lowercase' ] ],
471 'Invalid character' => [ 'in[]valid', [ 'creatable' => false, 'usable' => false,
472 'valid' => false, 'false' => 'In[]valid' ] ],
473 'With slash' => [ 'with / slash', [ 'creatable' => false, 'usable' => false, 'valid' => false,
474 'false' => 'With / slash' ] ],
475 ];
476 }
477
481 public function testEquals() {
482 $first = $this->getMutableTestUser()->getUser();
483 $second = User::newFromName( $first->getName() );
484
485 $this->assertTrue( $first->equals( $first ) );
486 $this->assertTrue( $first->equals( $second ) );
487 $this->assertTrue( $second->equals( $first ) );
488
489 $third = $this->getMutableTestUser()->getUser();
490 $fourth = $this->getMutableTestUser()->getUser();
491
492 $this->assertFalse( $third->equals( $fourth ) );
493 $this->assertFalse( $fourth->equals( $third ) );
494
495 // Test users loaded from db with id
496 $user = $this->getMutableTestUser()->getUser();
497 $fifth = User::newFromId( $user->getId() );
498 $sixth = User::newFromName( $user->getName() );
499 $this->assertTrue( $fifth->equals( $sixth ) );
500 }
501
505 public function testGetId() {
506 $user = static::getTestUser()->getUser();
507 $this->assertTrue( $user->getId() > 0 );
508
509 }
510
515 public function testLoggedIn() {
516 $user = $this->getMutableTestUser()->getUser();
517 $this->assertTrue( $user->isLoggedIn() );
518 $this->assertFalse( $user->isAnon() );
519
520 // Non-existent users are perceived as anonymous
521 $user = User::newFromName( 'UTNonexistent' );
522 $this->assertFalse( $user->isLoggedIn() );
523 $this->assertTrue( $user->isAnon() );
524
525 $user = new User;
526 $this->assertFalse( $user->isLoggedIn() );
527 $this->assertTrue( $user->isAnon() );
528 }
529
533 public function testCheckAndSetTouched() {
534 $user = $this->getMutableTestUser()->getUser();
535 $user = TestingAccessWrapper::newFromObject( $user );
536 $this->assertTrue( $user->isLoggedIn() );
537
538 $touched = $user->getDBTouched();
539 $this->assertTrue(
540 $user->checkAndSetTouched(), "checkAndSetTouched() succeded" );
541 $this->assertGreaterThan(
542 $touched, $user->getDBTouched(), "user_touched increased with casOnTouched()" );
543
544 $touched = $user->getDBTouched();
545 $this->assertTrue(
546 $user->checkAndSetTouched(), "checkAndSetTouched() succeded #2" );
547 $this->assertGreaterThan(
548 $touched, $user->getDBTouched(), "user_touched increased with casOnTouched() #2" );
549 }
550
554 public function testFindUsersByGroup() {
555 $users = User::findUsersByGroup( [] );
556 $this->assertEquals( 0, iterator_count( $users ) );
557
558 $users = User::findUsersByGroup( 'foo' );
559 $this->assertEquals( 0, iterator_count( $users ) );
560
561 $user = $this->getMutableTestUser( [ 'foo' ] )->getUser();
562 $users = User::findUsersByGroup( 'foo' );
563 $this->assertEquals( 1, iterator_count( $users ) );
564 $users->rewind();
565 $this->assertTrue( $user->equals( $users->current() ) );
566
567 // arguments have OR relationship
568 $user2 = $this->getMutableTestUser( [ 'bar' ] )->getUser();
569 $users = User::findUsersByGroup( [ 'foo', 'bar' ] );
570 $this->assertEquals( 2, iterator_count( $users ) );
571 $users->rewind();
572 $this->assertTrue( $user->equals( $users->current() ) );
573 $users->next();
574 $this->assertTrue( $user2->equals( $users->current() ) );
575
576 // users are not duplicated
577 $user = $this->getMutableTestUser( [ 'baz', 'boom' ] )->getUser();
578 $users = User::findUsersByGroup( [ 'baz', 'boom' ] );
579 $this->assertEquals( 1, iterator_count( $users ) );
580 $users->rewind();
581 $this->assertTrue( $user->equals( $users->current() ) );
582 }
583}
$wgDefaultUserOptions
Settings added to this array will override the default globals for the user preferences used by anony...
$wgGroupPermissions
Permission keys given to users in each group.
$wgRevokePermissions
Permission keys revoked from users in each group.
static makeContent( $text, Title $title=null, $modelId=null, $format=null)
Convenience function for creating a Content object from a given textual representation.
static TestUser[] $users
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
setMwGlobals( $pairs, $value=null)
Database.
Definition UserTest.php:9
testUserPermissions()
User::getRights.
Definition UserTest.php:87
testGetGroupsWithPermission( $expected, $right)
provideGetGroupsWithPermission User::getGroupsWithPermission
Definition UserTest.php:150
testUserGetRightsHooks()
User::getRights.
Definition UserTest.php:98
testOptions()
Test changing user options.
Definition UserTest.php:343
testGetCanonicalName( $name, $expectedArray)
User::getCanonicalName() provideGetCanonicalName.
Definition UserTest.php:435
User $user
Definition UserTest.php:13
static provideGetGroupsWithPermission()
Definition UserTest.php:158
testIsValidUserName( $username, $result, $message)
provideUserNames User::isValidUserName
Definition UserTest.php:208
testIsIP( $value, $result, $message)
provideIPs User::isIP
Definition UserTest.php:183
testGetEditCount()
Test User::editCount medium User::getEditCount.
Definition UserTest.php:266
static provideGetCanonicalName()
Definition UserTest.php:459
testAnonOptions()
Bug 37963 Make sure defaults are loaded when setOption is called.
Definition UserTest.php:360
setUpPermissionGlobals()
Definition UserTest.php:29
testIncEditCount()
Test User::editCount medium User::incEditCount.
Definition UserTest.php:324
testGetEditCountForAnons()
Test User::editCount medium User::getEditCount.
Definition UserTest.php:303
testRevokePermissions()
User::getGroupPermissions.
Definition UserTest.php:76
testGetId()
User::getId.
Definition UserTest.php:505
testEquals()
User::equals.
Definition UserTest.php:481
testCheckPasswordValidity()
Test password validity checks.
Definition UserTest.php:376
testAllRightsWithMessage()
Test, if for all rights a right- message exist, which is used on Special:ListGroupRights as help text...
Definition UserTest.php:238
testCheckAndSetTouched()
User::checkAndSetTouched.
Definition UserTest.php:533
testLoggedIn()
User::isLoggedIn User::isAnon.
Definition UserTest.php:515
testGroupPermissions()
User::getGroupPermissions.
Definition UserTest.php:59
static provideIPs()
Definition UserTest.php:187
testFindUsersByGroup()
User::findUsersByGroup.
Definition UserTest.php:554
static provideUserNames()
Definition UserTest.php:212
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition User.php:48
getPasswordValidity( $password)
Given unvalidated password input, return error message on failure.
Definition User.php:969
getName()
Get the user name, or the IP of an anonymous user.
Definition User.php:2108
getDBTouched()
Get the user_touched timestamp field (time of last DB updates)
Definition User.php:2442
getId()
Get the user's ID.
Definition User.php:2083
getOption( $oname, $defaultOverride=null, $ignoreHidden=false)
Get the user's current setting for a given option.
Definition User.php:2766
checkPasswordValidity( $password, $purpose='login')
Check if this is a valid password for this user.
Definition User.php:1006
addGroup( $group)
Add the user to the given group.
Definition User.php:3300
setOption( $oname, $val)
Set the given option for a user.
Definition User.php:2853
getEditCount()
Get the user's edit count.
Definition User.php:3270
isValidPassword( $password)
Is the input a valid password for this user?
Definition User.php:958
checkAndSetTouched()
Bump user_touched if it didn't change since this object was loaded.
Definition User.php:1460
isLoggedIn()
Get whether the user is logged in.
Definition User.php:3380
saveSettings()
Save this user's settings into the database.
Definition User.php:3847
getRights()
Get the permissions this user has.
Definition User.php:3142
equals(User $user)
Checks if two user objects point to the same user.
Definition User.php:5392
incEditCount()
Deferred version of incEditCountImmediate()
Definition User.php:4935
isAnon()
Get whether the user is anonymous.
Definition User.php:3388
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition WikiPage.php:115
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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
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 and we might be restricted by PHP settings such as safe mode or open_basedir We cannot assume that the software even has read access anywhere useful Many shared hosts run all users web applications under the same user
Wikitext formatted, in the key only.
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:1937
this hook is for auditing only or null if authentication failed before getting that far $username
Definition hooks.txt:807
Allows to change the fields on the form that will be generated $name
Definition hooks.txt:304
namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable(). 'NewDifferenceEngine' 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:2534
processing should stop and the error should be shown to the user * false
Definition hooks.txt:189
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:37
A helper class for throttling authentication attempts.