MediaWiki  1.29.1
BotPasswordTest.php
Go to the documentation of this file.
1 <?php
2 
4 use Wikimedia\ScopedCallback;
5 use Wikimedia\TestingAccessWrapper;
6 
12 
14  private $testUser;
15 
17  private $testUserName;
18 
19  protected function setUp() {
20  parent::setUp();
21 
22  $this->setMwGlobals( [
23  'wgEnableBotPasswords' => true,
24  'wgBotPasswordsDatabase' => false,
25  'wgCentralIdLookupProvider' => 'BotPasswordTest OkMock',
26  'wgGrantPermissions' => [
27  'test' => [ 'read' => true ],
28  ],
29  'wgUserrightsInterwikiDelimiter' => '@',
30  ] );
31 
32  $this->testUser = $this->getMutableTestUser();
33  $this->testUserName = $this->testUser->getUser()->getName();
34 
35  $mock1 = $this->getMockForAbstractClass( 'CentralIdLookup' );
36  $mock1->expects( $this->any() )->method( 'isAttached' )
37  ->will( $this->returnValue( true ) );
38  $mock1->expects( $this->any() )->method( 'lookupUserNames' )
39  ->will( $this->returnValue( [ $this->testUserName => 42, 'UTDummy' => 43, 'UTInvalid' => 0 ] ) );
40  $mock1->expects( $this->never() )->method( 'lookupCentralIds' );
41 
42  $mock2 = $this->getMockForAbstractClass( 'CentralIdLookup' );
43  $mock2->expects( $this->any() )->method( 'isAttached' )
44  ->will( $this->returnValue( false ) );
45  $mock2->expects( $this->any() )->method( 'lookupUserNames' )
46  ->will( $this->returnArgument( 0 ) );
47  $mock2->expects( $this->never() )->method( 'lookupCentralIds' );
48 
49  $this->mergeMwGlobalArrayValue( 'wgCentralIdLookupProviders', [
50  'BotPasswordTest OkMock' => [ 'factory' => function () use ( $mock1 ) {
51  return $mock1;
52  } ],
53  'BotPasswordTest FailMock' => [ 'factory' => function () use ( $mock2 ) {
54  return $mock2;
55  } ],
56  ] );
57 
59  }
60 
61  public function addDBData() {
62  $passwordFactory = new \PasswordFactory();
63  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
64  $passwordHash = $passwordFactory->newFromPlaintext( 'foobaz' );
65 
66  $dbw = wfGetDB( DB_MASTER );
67  $dbw->delete(
68  'bot_passwords',
69  [ 'bp_user' => [ 42, 43 ], 'bp_app_id' => 'BotPassword' ],
70  __METHOD__
71  );
72  $dbw->insert(
73  'bot_passwords',
74  [
75  [
76  'bp_user' => 42,
77  'bp_app_id' => 'BotPassword',
78  'bp_password' => $passwordHash->toString(),
79  'bp_token' => 'token!',
80  'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
81  'bp_grants' => '["test"]',
82  ],
83  [
84  'bp_user' => 43,
85  'bp_app_id' => 'BotPassword',
86  'bp_password' => $passwordHash->toString(),
87  'bp_token' => 'token!',
88  'bp_restrictions' => '{"IPAddresses":["127.0.0.0/8"]}',
89  'bp_grants' => '["test"]',
90  ],
91  ],
92  __METHOD__
93  );
94  }
95 
96  public function testBasics() {
97  $user = $this->testUser->getUser();
98  $bp = BotPassword::newFromUser( $user, 'BotPassword' );
99  $this->assertInstanceOf( 'BotPassword', $bp );
100  $this->assertTrue( $bp->isSaved() );
101  $this->assertSame( 42, $bp->getUserCentralId() );
102  $this->assertSame( 'BotPassword', $bp->getAppId() );
103  $this->assertSame( 'token!', trim( $bp->getToken(), " \0" ) );
104  $this->assertEquals( '{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
105  $this->assertSame( [ 'test' ], $bp->getGrants() );
106 
107  $this->assertNull( BotPassword::newFromUser( $user, 'DoesNotExist' ) );
108 
109  $this->setMwGlobals( [
110  'wgCentralIdLookupProvider' => 'BotPasswordTest FailMock'
111  ] );
112  $this->assertNull( BotPassword::newFromUser( $user, 'BotPassword' ) );
113 
114  $this->assertSame( '@', BotPassword::getSeparator() );
115  $this->setMwGlobals( [
116  'wgUserrightsInterwikiDelimiter' => '#',
117  ] );
118  $this->assertSame( '#', BotPassword::getSeparator() );
119  }
120 
121  public function testUnsaved() {
122  $user = $this->testUser->getUser();
123  $bp = BotPassword::newUnsaved( [
124  'user' => $user,
125  'appId' => 'DoesNotExist'
126  ] );
127  $this->assertInstanceOf( 'BotPassword', $bp );
128  $this->assertFalse( $bp->isSaved() );
129  $this->assertSame( 42, $bp->getUserCentralId() );
130  $this->assertSame( 'DoesNotExist', $bp->getAppId() );
131  $this->assertEquals( MWRestrictions::newDefault(), $bp->getRestrictions() );
132  $this->assertSame( [], $bp->getGrants() );
133 
134  $bp = BotPassword::newUnsaved( [
135  'username' => 'UTDummy',
136  'appId' => 'DoesNotExist2',
137  'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
138  'grants' => [ 'test' ],
139  ] );
140  $this->assertInstanceOf( 'BotPassword', $bp );
141  $this->assertFalse( $bp->isSaved() );
142  $this->assertSame( 43, $bp->getUserCentralId() );
143  $this->assertSame( 'DoesNotExist2', $bp->getAppId() );
144  $this->assertEquals( '{"IPAddresses":["127.0.0.0/8"]}', $bp->getRestrictions()->toJson() );
145  $this->assertSame( [ 'test' ], $bp->getGrants() );
146 
147  $user = $this->testUser->getUser();
148  $bp = BotPassword::newUnsaved( [
149  'centralId' => 45,
150  'appId' => 'DoesNotExist'
151  ] );
152  $this->assertInstanceOf( 'BotPassword', $bp );
153  $this->assertFalse( $bp->isSaved() );
154  $this->assertSame( 45, $bp->getUserCentralId() );
155  $this->assertSame( 'DoesNotExist', $bp->getAppId() );
156 
157  $user = $this->testUser->getUser();
158  $bp = BotPassword::newUnsaved( [
159  'user' => $user,
160  'appId' => 'BotPassword'
161  ] );
162  $this->assertInstanceOf( 'BotPassword', $bp );
163  $this->assertFalse( $bp->isSaved() );
164 
165  $this->assertNull( BotPassword::newUnsaved( [
166  'user' => $user,
167  'appId' => '',
168  ] ) );
169  $this->assertNull( BotPassword::newUnsaved( [
170  'user' => $user,
171  'appId' => str_repeat( 'X', BotPassword::APPID_MAXLENGTH + 1 ),
172  ] ) );
173  $this->assertNull( BotPassword::newUnsaved( [
174  'user' => $this->testUserName,
175  'appId' => 'Ok',
176  ] ) );
177  $this->assertNull( BotPassword::newUnsaved( [
178  'username' => 'UTInvalid',
179  'appId' => 'Ok',
180  ] ) );
181  $this->assertNull( BotPassword::newUnsaved( [
182  'appId' => 'Ok',
183  ] ) );
184  }
185 
186  public function testGetPassword() {
187  $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
188 
189  $password = $bp->getPassword();
190  $this->assertInstanceOf( 'Password', $password );
191  $this->assertTrue( $password->equals( 'foobaz' ) );
192 
193  $bp->centralId = 44;
194  $password = $bp->getPassword();
195  $this->assertInstanceOf( 'InvalidPassword', $password );
196 
197  $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
198  $dbw = wfGetDB( DB_MASTER );
199  $dbw->update(
200  'bot_passwords',
201  [ 'bp_password' => 'garbage' ],
202  [ 'bp_user' => 42, 'bp_app_id' => 'BotPassword' ],
203  __METHOD__
204  );
205  $password = $bp->getPassword();
206  $this->assertInstanceOf( 'InvalidPassword', $password );
207  }
208 
210  $bp1 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
211  $bp2 = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 43, 'BotPassword' ) );
212 
213  $this->assertNotInstanceOf( 'InvalidPassword', $bp1->getPassword(), 'sanity check' );
214  $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword(), 'sanity check' );
215  BotPassword::invalidateAllPasswordsForUser( $this->testUserName );
216  $this->assertInstanceOf( 'InvalidPassword', $bp1->getPassword() );
217  $this->assertNotInstanceOf( 'InvalidPassword', $bp2->getPassword() );
218 
219  $bp = TestingAccessWrapper::newFromObject( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
220  $this->assertInstanceOf( 'InvalidPassword', $bp->getPassword() );
221  }
222 
223  public function testRemoveAllPasswordsForUser() {
224  $this->assertNotNull( BotPassword::newFromCentralId( 42, 'BotPassword' ), 'sanity check' );
225  $this->assertNotNull( BotPassword::newFromCentralId( 43, 'BotPassword' ), 'sanity check' );
226 
227  BotPassword::removeAllPasswordsForUser( $this->testUserName );
228 
229  $this->assertNull( BotPassword::newFromCentralId( 42, 'BotPassword' ) );
230  $this->assertNotNull( BotPassword::newFromCentralId( 43, 'BotPassword' ) );
231  }
232 
236  public function testCanonicalizeLoginData( $username, $password, $expectedResult ) {
238  if ( is_array( $expectedResult ) ) {
239  $this->assertArrayEquals( $expectedResult, $result, true, true );
240  } else {
241  $this->assertSame( $expectedResult, $result );
242  }
243  }
244 
245  public function provideCanonicalizeLoginData() {
246  return [
247  [ 'user', 'pass', false ],
248  [ 'user', 'abc@def', false ],
249  [ 'legacy@user', 'pass', false ],
250  [ 'user@bot', '12345678901234567890123456789012',
251  [ 'user@bot', '12345678901234567890123456789012', true ] ],
252  [ 'user', 'bot@12345678901234567890123456789012',
253  [ 'user@bot', '12345678901234567890123456789012', true ] ],
254  [ 'user', 'bot@12345678901234567890123456789012345',
255  [ 'user@bot', '12345678901234567890123456789012345', true ] ],
256  [ 'user', 'bot@x@12345678901234567890123456789012',
257  [ 'user@bot@x', '12345678901234567890123456789012', true ] ],
258  ];
259  }
260 
261  public function testLogin() {
262  // Test failure when bot passwords aren't enabled
263  $this->setMwGlobals( 'wgEnableBotPasswords', false );
264  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', new FauxRequest );
265  $this->assertEquals( Status::newFatal( 'botpasswords-disabled' ), $status );
266  $this->setMwGlobals( 'wgEnableBotPasswords', true );
267 
268  // Test failure when BotPasswordSessionProvider isn't configured
269  $manager = new SessionManager( [
270  'logger' => new Psr\Log\NullLogger,
271  'store' => new EmptyBagOStuff,
272  ] );
274  $this->assertNull(
275  $manager->getProvider( MediaWiki\Session\BotPasswordSessionProvider::class ),
276  'sanity check'
277  );
278  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', new FauxRequest );
279  $this->assertEquals( Status::newFatal( 'botpasswords-no-provider' ), $status );
280  ScopedCallback::consume( $reset );
281 
282  // Now configure BotPasswordSessionProvider for further tests...
283  $mainConfig = RequestContext::getMain()->getConfig();
284  $config = new HashConfig( [
285  'SessionProviders' => $mainConfig->get( 'SessionProviders' ) + [
288  'args' => [ [ 'priority' => 40 ] ],
289  ]
290  ],
291  ] );
292  $manager = new SessionManager( [
293  'config' => new MultiConfig( [ $config, RequestContext::getMain()->getConfig() ] ),
294  'logger' => new Psr\Log\NullLogger,
295  'store' => new EmptyBagOStuff,
296  ] );
298 
299  // No "@"-thing in the username
300  $status = BotPassword::login( $this->testUserName, 'foobaz', new FauxRequest );
301  $this->assertEquals( Status::newFatal( 'botpasswords-invalid-name', '@' ), $status );
302 
303  // No base user
304  $status = BotPassword::login( 'UTDummy@BotPassword', 'foobaz', new FauxRequest );
305  $this->assertEquals( Status::newFatal( 'nosuchuser', 'UTDummy' ), $status );
306 
307  // No bot password
308  $status = BotPassword::login( "{$this->testUserName}@DoesNotExist", 'foobaz', new FauxRequest );
309  $this->assertEquals(
310  Status::newFatal( 'botpasswords-not-exist', $this->testUserName, 'DoesNotExist' ),
311  $status
312  );
313 
314  // Failed restriction
315  $request = $this->getMockBuilder( 'FauxRequest' )
316  ->setMethods( [ 'getIP' ] )
317  ->getMock();
318  $request->expects( $this->any() )->method( 'getIP' )
319  ->will( $this->returnValue( '10.0.0.1' ) );
320  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
321  $this->assertEquals( Status::newFatal( 'botpasswords-restriction-failed' ), $status );
322 
323  // Wrong password
325  "{$this->testUserName}@BotPassword", $this->testUser->getPassword(), new FauxRequest );
326  $this->assertEquals( Status::newFatal( 'wrongpassword' ), $status );
327 
328  // Success!
329  $request = new FauxRequest;
330  $this->assertNotInstanceOf(
332  $request->getSession()->getProvider(),
333  'sanity check'
334  );
335  $status = BotPassword::login( "{$this->testUserName}@BotPassword", 'foobaz', $request );
336  $this->assertInstanceOf( 'Status', $status );
337  $this->assertTrue( $status->isGood() );
338  $session = $status->getValue();
339  $this->assertInstanceOf( MediaWiki\Session\Session::class, $session );
340  $this->assertInstanceOf(
341  MediaWiki\Session\BotPasswordSessionProvider::class, $session->getProvider()
342  );
343  $this->assertSame( $session->getId(), $request->getSession()->getId() );
344 
345  ScopedCallback::consume( $reset );
346  }
347 
352  public function testSave( $password ) {
353  $passwordFactory = new \PasswordFactory();
354  $passwordFactory->init( \RequestContext::getMain()->getConfig() );
355 
356  $bp = BotPassword::newUnsaved( [
357  'centralId' => 42,
358  'appId' => 'TestSave',
359  'restrictions' => MWRestrictions::newFromJson( '{"IPAddresses":["127.0.0.0/8"]}' ),
360  'grants' => [ 'test' ],
361  ] );
362  $this->assertFalse( $bp->isSaved(), 'sanity check' );
363  $this->assertNull(
364  BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ), 'sanity check'
365  );
366 
367  $passwordHash = $password ? $passwordFactory->newFromPlaintext( $password ) : null;
368  $this->assertFalse( $bp->save( 'update', $passwordHash ) );
369  $this->assertTrue( $bp->save( 'insert', $passwordHash ) );
370  $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
371  $this->assertInstanceOf( 'BotPassword', $bp2 );
372  $this->assertEquals( $bp->getUserCentralId(), $bp2->getUserCentralId() );
373  $this->assertEquals( $bp->getAppId(), $bp2->getAppId() );
374  $this->assertEquals( $bp->getToken(), $bp2->getToken() );
375  $this->assertEquals( $bp->getRestrictions(), $bp2->getRestrictions() );
376  $this->assertEquals( $bp->getGrants(), $bp2->getGrants() );
377  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
378  if ( $password === null ) {
379  $this->assertInstanceOf( 'InvalidPassword', $pw );
380  } else {
381  $this->assertTrue( $pw->equals( $password ) );
382  }
383 
384  $token = $bp->getToken();
385  $this->assertFalse( $bp->save( 'insert' ) );
386  $this->assertTrue( $bp->save( 'update' ) );
387  $this->assertNotEquals( $token, $bp->getToken() );
388  $bp2 = BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST );
389  $this->assertInstanceOf( 'BotPassword', $bp2 );
390  $this->assertEquals( $bp->getToken(), $bp2->getToken() );
391  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
392  if ( $password === null ) {
393  $this->assertInstanceOf( 'InvalidPassword', $pw );
394  } else {
395  $this->assertTrue( $pw->equals( $password ) );
396  }
397 
398  $passwordHash = $passwordFactory->newFromPlaintext( 'XXX' );
399  $token = $bp->getToken();
400  $this->assertTrue( $bp->save( 'update', $passwordHash ) );
401  $this->assertNotEquals( $token, $bp->getToken() );
402  $pw = TestingAccessWrapper::newFromObject( $bp )->getPassword();
403  $this->assertTrue( $pw->equals( 'XXX' ) );
404 
405  $this->assertTrue( $bp->delete() );
406  $this->assertFalse( $bp->isSaved() );
407  $this->assertNull( BotPassword::newFromCentralId( 42, 'TestSave', BotPassword::READ_LATEST ) );
408 
409  $this->assertFalse( $bp->save( 'foobar' ) );
410  }
411 
412  public static function provideSave() {
413  return [
414  [ null ],
415  [ 'foobar' ],
416  ];
417  }
418 }
BotPasswordTest\setUp
setUp()
Definition: BotPasswordTest.php:19
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
MediaWikiTestCase\assertArrayEquals
assertArrayEquals(array $expected, array $actual, $ordered=false, $named=false)
Assert that two arrays are equal.
Definition: MediaWikiTestCase.php:1498
$request
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2612
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
MediaWikiTestCase\mergeMwGlobalArrayValue
mergeMwGlobalArrayValue( $name, $values)
Merges the given values into a MW global array variable.
Definition: MediaWikiTestCase.php:766
EmptyBagOStuff
A BagOStuff object with no objects in it.
Definition: EmptyBagOStuff.php:29
BotPasswordTest\testInvalidateAllPasswordsForUser
testInvalidateAllPasswordsForUser()
Definition: BotPasswordTest.php:209
MultiConfig
Provides a fallback sequence for Config objects.
Definition: MultiConfig.php:28
BotPassword\canonicalizeLoginData
static canonicalizeLoginData( $username, $password)
There are two ways to login with a bot password: "username@appId", "password" and "username",...
Definition: BotPassword.php:413
HashConfig
A Config instance which stores all settings as a member variable.
Definition: HashConfig.php:28
BotPasswordTest\testGetPassword
testGetPassword()
Definition: BotPasswordTest.php:186
$result
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:Array with elements of the form "language:title" in the order that they will be output. & $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:1954
BotPassword\getSeparator
static getSeparator()
Get the separator for combined user name + app ID.
Definition: BotPassword.php:230
$status
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
Definition: hooks.txt:1049
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
$user
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
Definition: hooks.txt:246
BotPasswordTest\$testUser
TestUser $testUser
Definition: BotPasswordTest.php:14
StatusValue\newFatal
static newFatal( $message)
Factory function for fatal errors.
Definition: StatusValue.php:63
MediaWiki\Session\TestUtils\setSessionManagerSingleton
static setSessionManagerSingleton(SessionManager $manager=null)
Override the singleton for unit testing.
Definition: TestUtils.php:18
BotPassword\APPID_MAXLENGTH
const APPID_MAXLENGTH
Definition: BotPassword.php:30
php
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
TestUser
Wraps the user object, so we can also retain full access to properties like password if we log in via...
Definition: TestUser.php:7
BotPasswordTest\testSave
testSave( $password)
provideSave
Definition: BotPasswordTest.php:352
BotPassword\newUnsaved
static newUnsaved(array $data, $flags=self::READ_NORMAL)
Create an unsaved BotPassword.
Definition: BotPassword.php:135
wfGetDB
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3060
BotPasswordTest\testCanonicalizeLoginData
testCanonicalizeLoginData( $username, $password, $expectedResult)
provideCanonicalizeLoginData
Definition: BotPasswordTest.php:236
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Definition: MediaWikiTestCase.php:658
MediaWikiTestCase
Definition: MediaWikiTestCase.php:13
BotPasswordTest\addDBData
addDBData()
Stub.
Definition: BotPasswordTest.php:61
MediaWiki
A helper class for throttling authentication attempts.
DB_MASTER
const DB_MASTER
Definition: defines.php:26
MWRestrictions\newDefault
static newDefault()
Definition: MWRestrictions.php:41
BotPassword\newFromUser
static newFromUser(User $user, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
Definition: BotPassword.php:90
any
they could even be mouse clicks or menu items whatever suits your program You should also get your if any
Definition: COPYING.txt:326
CentralIdLookup\resetCache
static resetCache()
Reset internal cache for unit testing.
Definition: CentralIdLookup.php:70
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:158
BotPassword\invalidateAllPasswordsForUser
static invalidateAllPasswordsForUser( $username)
Invalidate all passwords for a user, by name.
Definition: BotPassword.php:330
BotPasswordTest\testRemoveAllPasswordsForUser
testRemoveAllPasswordsForUser()
Definition: BotPasswordTest.php:223
MediaWiki\Session\SessionManager
This serves as the entry point to the MediaWiki session handling system.
Definition: SessionManager.php:49
BotPasswordTest\testBasics
testBasics()
Definition: BotPasswordTest.php:96
RequestContext\getMain
static getMain()
Static methods.
Definition: RequestContext.php:468
BotPassword\newFromCentralId
static newFromCentralId( $centralId, $appId, $flags=self::READ_NORMAL)
Load a BotPassword from the database.
Definition: BotPassword.php:104
BotPassword\login
static login( $username, $password, WebRequest $request)
Try to log the user in.
Definition: BotPassword.php:439
BotPasswordTest\provideCanonicalizeLoginData
provideCanonicalizeLoginData()
Definition: BotPasswordTest.php:245
BotPasswordTest\$testUserName
string $testUserName
Definition: BotPasswordTest.php:17
MWRestrictions\newFromJson
static newFromJson( $json)
Definition: MWRestrictions.php:59
BotPasswordTest
BotPassword Database.
Definition: BotPasswordTest.php:11
true
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:1956
BotPassword\removeAllPasswordsForUser
static removeAllPasswordsForUser( $username)
Remove all passwords for a user, by name.
Definition: BotPassword.php:364
class
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
Definition: maintenance.txt:52
BotPasswordTest\testLogin
testLogin()
Definition: BotPasswordTest.php:261
BotPasswordTest\testUnsaved
testUnsaved()
Definition: BotPasswordTest.php:121
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:783
BotPasswordTest\provideSave
static provideSave()
Definition: BotPasswordTest.php:412