MediaWiki  1.33.0
BlockTest.php
Go to the documentation of this file.
1 <?php
2 
7 
13 
17  private function getUserForBlocking() {
18  $testUser = $this->getMutableTestUser();
19  $user = $testUser->getUser();
20  $user->addToDatabase();
21  TestUser::setPasswordForUser( $user, 'UTBlockeePassword' );
22  $user->saveSettings();
23  return $user;
24  }
25 
32  private function addBlockForUser( User $user ) {
33  // Delete the last round's block if it's still there
34  $oldBlock = Block::newFromTarget( $user->getName() );
35  if ( $oldBlock ) {
36  // An old block will prevent our new one from saving.
37  $oldBlock->delete();
38  }
39 
40  $blockOptions = [
41  'address' => $user->getName(),
42  'user' => $user->getId(),
43  'by' => $this->getTestSysop()->getUser()->getId(),
44  'reason' => 'Parce que',
45  'expiry' => time() + 100500,
46  ];
47  $block = new Block( $blockOptions );
48 
49  $block->insert();
50  // save up ID for use in assertion. Since ID is an autoincrement,
51  // its value might change depending on the order the tests are run.
52  // ApiBlockTest insert its own blocks!
53  if ( !$block->getId() ) {
54  throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" );
55  }
56 
57  $this->addXffBlocks();
58 
59  return $block;
60  }
61 
66  $user = $this->getUserForBlocking();
67  $block = $this->addBlockForUser( $user );
68 
69  $this->assertTrue(
70  $block->equals( Block::newFromTarget( $user->getName() ) ),
71  "newFromTarget() returns the same block as the one that was made"
72  );
73  }
74 
79  $user = $this->getUserForBlocking();
80  $block = $this->addBlockForUser( $user );
81 
82  $this->assertTrue(
83  $block->equals( Block::newFromID( $block->getId() ) ),
84  "newFromID() returns the same block as the one that was made"
85  );
86  }
87 
93  $user = $this->getUserForBlocking();
94  $block = $this->addBlockForUser( $user );
95  $madeAt = wfTimestamp( TS_MW );
96 
97  // delta to stop one-off errors when things happen to go over a second mark.
98  $delta = abs( $madeAt - $block->getTimestamp() );
99  $this->assertLessThan(
100  2,
101  $delta,
102  "If no timestamp is specified, the block is recorded as time()"
103  );
104  }
105 
114  public function testT31116NewFromTargetWithEmptyIp( $vagueTarget ) {
115  $user = $this->getUserForBlocking();
116  $initialBlock = $this->addBlockForUser( $user );
117  $block = Block::newFromTarget( $user->getName(), $vagueTarget );
118 
119  $this->assertTrue(
120  $initialBlock->equals( $block ),
121  "newFromTarget() returns the same block as the one that was made when "
122  . "given empty vagueTarget param " . var_export( $vagueTarget, true )
123  );
124  }
125 
126  public static function provideT31116Data() {
127  return [
128  [ null ],
129  [ '' ],
130  [ false ]
131  ];
132  }
133 
138  $username = 'BlockedUserToCreateAccountWith';
140  $u->addToDatabase();
141  $userId = $u->getId();
142  $this->assertNotEquals( 0, $userId, 'sanity' );
143  TestUser::setPasswordForUser( $u, 'NotRandomPass' );
144  unset( $u );
145 
146  // Sanity check
147  $this->assertNull(
149  "$username should not be blocked"
150  );
151 
152  // Reload user
154  $this->assertFalse(
155  $u->isBlockedFromCreateAccount(),
156  "Our sandbox user should be able to create account before being blocked"
157  );
158 
159  // Foreign perspective (blockee not on current wiki)...
160  $blockOptions = [
161  'address' => $username,
162  'user' => $userId,
163  'reason' => 'crosswiki block...',
164  'timestamp' => wfTimestampNow(),
165  'expiry' => $this->db->getInfinity(),
166  'createAccount' => true,
167  'enableAutoblock' => true,
168  'hideName' => true,
169  'blockEmail' => true,
170  'byText' => 'm>MetaWikiUser',
171  ];
172  $block = new Block( $blockOptions );
173  $block->insert();
174 
175  // Reload block from DB
176  $userBlock = Block::newFromTarget( $username );
177  $this->assertTrue(
178  (bool)$block->appliesToRight( 'createaccount' ),
179  "Block object in DB should block right 'createaccount'"
180  );
181 
182  $this->assertInstanceOf(
183  Block::class,
184  $userBlock,
185  "'$username' block block object should be existent"
186  );
187 
188  // Reload user
190  $this->assertTrue(
191  (bool)$u->isBlockedFromCreateAccount(),
192  "Our sandbox user '$username' should NOT be able to create account"
193  );
194  }
195 
199  public function testCrappyCrossWikiBlocks() {
200  // Delete the last round's block if it's still there
201  $oldBlock = Block::newFromTarget( 'UserOnForeignWiki' );
202  if ( $oldBlock ) {
203  // An old block will prevent our new one from saving.
204  $oldBlock->delete();
205  }
206 
207  // Local perspective (blockee on current wiki)...
208  $user = User::newFromName( 'UserOnForeignWiki' );
209  $user->addToDatabase();
210  $userId = $user->getId();
211  $this->assertNotEquals( 0, $userId, 'sanity' );
212 
213  // Foreign perspective (blockee not on current wiki)...
214  $blockOptions = [
215  'address' => 'UserOnForeignWiki',
216  'user' => $user->getId(),
217  'reason' => 'crosswiki block...',
218  'timestamp' => wfTimestampNow(),
219  'expiry' => $this->db->getInfinity(),
220  'createAccount' => true,
221  'enableAutoblock' => true,
222  'hideName' => true,
223  'blockEmail' => true,
224  'byText' => 'Meta>MetaWikiUser',
225  ];
226  $block = new Block( $blockOptions );
227 
228  $res = $block->insert( $this->db );
229  $this->assertTrue( (bool)$res['id'], 'Block succeeded' );
230 
231  $user = null; // clear
232 
233  $block = Block::newFromID( $res['id'] );
234  $this->assertEquals(
235  'UserOnForeignWiki',
236  $block->getTarget()->getName(),
237  'Correct blockee name'
238  );
239  $this->assertEquals( $userId, $block->getTarget()->getId(), 'Correct blockee id' );
240  $this->assertEquals( 'Meta>MetaWikiUser', $block->getBlocker()->getName(),
241  'Correct blocker name' );
242  $this->assertEquals( 'Meta>MetaWikiUser', $block->getByName(), 'Correct blocker name' );
243  $this->assertEquals( 0, $block->getBy(), 'Correct blocker id' );
244  }
245 
246  protected function addXffBlocks() {
247  static $inited = false;
248 
249  if ( $inited ) {
250  return;
251  }
252 
253  $inited = true;
254 
255  $blockList = [
256  [ 'target' => '70.2.0.0/16',
257  'type' => Block::TYPE_RANGE,
258  'desc' => 'Range Hardblock',
259  'ACDisable' => false,
260  'isHardblock' => true,
261  'isAutoBlocking' => false,
262  ],
263  [ 'target' => '2001:4860:4001::/48',
264  'type' => Block::TYPE_RANGE,
265  'desc' => 'Range6 Hardblock',
266  'ACDisable' => false,
267  'isHardblock' => true,
268  'isAutoBlocking' => false,
269  ],
270  [ 'target' => '60.2.0.0/16',
271  'type' => Block::TYPE_RANGE,
272  'desc' => 'Range Softblock with AC Disabled',
273  'ACDisable' => true,
274  'isHardblock' => false,
275  'isAutoBlocking' => false,
276  ],
277  [ 'target' => '50.2.0.0/16',
278  'type' => Block::TYPE_RANGE,
279  'desc' => 'Range Softblock',
280  'ACDisable' => false,
281  'isHardblock' => false,
282  'isAutoBlocking' => false,
283  ],
284  [ 'target' => '50.1.1.1',
285  'type' => Block::TYPE_IP,
286  'desc' => 'Exact Softblock',
287  'ACDisable' => false,
288  'isHardblock' => false,
289  'isAutoBlocking' => false,
290  ],
291  ];
292 
293  $blocker = $this->getTestUser()->getUser();
294  foreach ( $blockList as $insBlock ) {
295  $target = $insBlock['target'];
296 
297  if ( $insBlock['type'] === Block::TYPE_IP ) {
298  $target = User::newFromName( IP::sanitizeIP( $target ), false )->getName();
299  } elseif ( $insBlock['type'] === Block::TYPE_RANGE ) {
300  $target = IP::sanitizeRange( $target );
301  }
302 
303  $block = new Block();
304  $block->setTarget( $target );
305  $block->setBlocker( $blocker );
306  $block->setReason( $insBlock['desc'] );
307  $block->setExpiry( 'infinity' );
308  $block->isCreateAccountBlocked( $insBlock['ACDisable'] );
309  $block->isHardblock( $insBlock['isHardblock'] );
310  $block->isAutoblocking( $insBlock['isAutoBlocking'] );
311  $block->insert();
312  }
313  }
314 
315  public static function providerXff() {
316  return [
317  [ 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
318  'count' => 2,
319  'result' => 'Range Hardblock'
320  ],
321  [ 'xff' => '1.2.3.4, 50.2.1.1, 60.2.1.1, 2.3.4.5',
322  'count' => 2,
323  'result' => 'Range Softblock with AC Disabled'
324  ],
325  [ 'xff' => '1.2.3.4, 70.2.1.1, 50.1.1.1, 2.3.4.5',
326  'count' => 2,
327  'result' => 'Exact Softblock'
328  ],
329  [ 'xff' => '1.2.3.4, 70.2.1.1, 50.2.1.1, 50.1.1.1, 2.3.4.5',
330  'count' => 3,
331  'result' => 'Exact Softblock'
332  ],
333  [ 'xff' => '1.2.3.4, 70.2.1.1, 50.2.1.1, 2.3.4.5',
334  'count' => 2,
335  'result' => 'Range Hardblock'
336  ],
337  [ 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
338  'count' => 2,
339  'result' => 'Range Hardblock'
340  ],
341  [ 'xff' => '50.2.1.1, 60.2.1.1, 2.3.4.5',
342  'count' => 2,
343  'result' => 'Range Softblock with AC Disabled'
344  ],
345  [ 'xff' => '1.2.3.4, 50.1.1.1, 60.2.1.1, 2.3.4.5',
346  'count' => 2,
347  'result' => 'Exact Softblock'
348  ],
349  [ 'xff' => '1.2.3.4, <$A_BUNCH-OF{INVALID}TEXT>, 60.2.1.1, 2.3.4.5',
350  'count' => 1,
351  'result' => 'Range Softblock with AC Disabled'
352  ],
353  [ 'xff' => '1.2.3.4, 50.2.1.1, 2001:4860:4001:802::1003, 2.3.4.5',
354  'count' => 2,
355  'result' => 'Range6 Hardblock'
356  ],
357  ];
358  }
359 
365  public function testBlocksOnXff( $xff, $exCount, $exResult ) {
366  $user = $this->getUserForBlocking();
367  $this->addBlockForUser( $user );
368 
369  $list = array_map( 'trim', explode( ',', $xff ) );
370  $xffblocks = Block::getBlocksForIPList( $list, true );
371  $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff );
372  $block = Block::chooseBlock( $xffblocks, $list );
373  $this->assertEquals(
374  $exResult, $block->getReason(), 'Correct block type for XFF header ' . $xff
375  );
376  }
377 
383  public function testSystemBlocks() {
384  $user = $this->getUserForBlocking();
385  $this->addBlockForUser( $user );
386 
387  $blockOptions = [
388  'address' => $user->getName(),
389  'reason' => 'test system block',
390  'timestamp' => wfTimestampNow(),
391  'expiry' => $this->db->getInfinity(),
392  'byText' => 'MediaWiki default',
393  'systemBlock' => 'test',
394  'enableAutoblock' => true,
395  ];
396  $block = new Block( $blockOptions );
397 
398  $this->assertSame( 'test', $block->getSystemBlockType() );
399 
400  try {
401  $block->insert();
402  $this->fail( 'Expected exception not thrown' );
403  } catch ( MWException $ex ) {
404  $this->assertSame( 'Cannot insert a system block into the database', $ex->getMessage() );
405  }
406 
407  try {
408  $block->doAutoblock( '192.0.2.2' );
409  $this->fail( 'Expected exception not thrown' );
410  } catch ( MWException $ex ) {
411  $this->assertSame( 'Cannot autoblock from a system block', $ex->getMessage() );
412  }
413  }
414 
418  public function testNewFromRow() {
419  $badActor = $this->getTestUser()->getUser();
420  $sysop = $this->getTestSysop()->getUser();
421 
422  $block = new Block( [
423  'address' => $badActor->getName(),
424  'user' => $badActor->getId(),
425  'by' => $sysop->getId(),
426  'expiry' => 'infinity',
427  ] );
428  $block->insert();
429 
430  $blockQuery = Block::getQueryInfo();
431  $row = $this->db->select(
432  $blockQuery['tables'],
433  $blockQuery['fields'],
434  [
435  'ipb_id' => $block->getId(),
436  ],
437  __METHOD__,
438  [],
439  $blockQuery['joins']
440  )->fetchObject();
441 
442  $block = Block::newFromRow( $row );
443  $this->assertInstanceOf( Block::class, $block );
444  $this->assertEquals( $block->getBy(), $sysop->getId() );
445  $this->assertEquals( $block->getTarget()->getName(), $badActor->getName() );
446  $block->delete();
447  }
448 
452  public function testEquals() {
453  $block = new Block();
454 
455  $this->assertTrue( $block->equals( $block ) );
456 
457  $partial = new Block( [
458  'sitewide' => false,
459  ] );
460  $this->assertFalse( $block->equals( $partial ) );
461  }
462 
466  public function testIsSitewide() {
467  $block = new Block();
468  $this->assertTrue( $block->isSitewide() );
469 
470  $block = new Block( [
471  'sitewide' => true,
472  ] );
473  $this->assertTrue( $block->isSitewide() );
474 
475  $block = new Block( [
476  'sitewide' => false,
477  ] );
478  $this->assertFalse( $block->isSitewide() );
479 
480  $block = new Block( [
481  'sitewide' => false,
482  ] );
483  $block->isSitewide( true );
484  $this->assertTrue( $block->isSitewide() );
485  }
486 
491  public function testRestrictions() {
492  $block = new Block();
493  $restrictions = [
494  new PageRestriction( 0, 1 )
495  ];
496  $block->setRestrictions( $restrictions );
497 
498  $this->assertSame( $restrictions, $block->getRestrictions() );
499  }
500 
505  public function testRestrictionsFromDatabase() {
506  $badActor = $this->getTestUser()->getUser();
507  $sysop = $this->getTestSysop()->getUser();
508 
509  $block = new Block( [
510  'address' => $badActor->getName(),
511  'user' => $badActor->getId(),
512  'by' => $sysop->getId(),
513  'expiry' => 'infinity',
514  ] );
515  $page = $this->getExistingTestPage( 'Foo' );
516  $restriction = new PageRestriction( 0, $page->getId() );
517  $block->setRestrictions( [ $restriction ] );
518  $block->insert();
519 
520  // Refresh the block from the database.
521  $block = Block::newFromID( $block->getId() );
522  $restrictions = $block->getRestrictions();
523  $this->assertCount( 1, $restrictions );
524  $this->assertTrue( $restriction->equals( $restrictions[0] ) );
525  $block->delete();
526  }
527 
531  public function testInsertExistingBlock() {
532  $badActor = $this->getTestUser()->getUser();
533  $sysop = $this->getTestSysop()->getUser();
534 
535  $block = new Block( [
536  'address' => $badActor->getName(),
537  'user' => $badActor->getId(),
538  'by' => $sysop->getId(),
539  'expiry' => 'infinity',
540  ] );
541  $page = $this->getExistingTestPage( 'Foo' );
542  $restriction = new PageRestriction( 0, $page->getId() );
543  $block->setRestrictions( [ $restriction ] );
544  $block->insert();
545 
546  // Insert the block again, which should result in a failur
547  $result = $block->insert();
548 
549  $this->assertFalse( $result );
550 
551  // Ensure that there are no restrictions where the blockId is 0.
552  $count = $this->db->selectRowCount(
553  'ipblocks_restrictions',
554  '*',
555  [ 'ir_ipb_id' => 0 ],
556  __METHOD__
557  );
558  $this->assertSame( 0, $count );
559 
560  $block->delete();
561  }
562 
567  $this->setMwGlobals( [
568  'wgBlockDisablesLogin' => false,
569  ] );
570  $user = $this->getTestUser()->getUser();
571  $block = new Block( [
572  'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
573  'allowUsertalk' => true,
574  'sitewide' => true
575  ] );
576 
577  $block->setTarget( $user );
578  $block->setBlocker( $this->getTestSysop()->getUser() );
579  $block->insert();
580 
581  $title = $this->getExistingTestPage( 'Foo' )->getTitle();
582 
583  $this->assertTrue( $block->appliesToTitle( $title ) );
584 
585  // appliesToTitle() ignores allowUsertalk
586  $title = $user->getTalkPage();
587  $this->assertTrue( $block->appliesToTitle( $title ) );
588 
589  $block->delete();
590  }
591 
596  $this->setMwGlobals( [
597  'wgBlockDisablesLogin' => false,
598  ] );
599  $user = $this->getTestUser()->getUser();
600  $block = new Block( [
601  'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
602  'allowUsertalk' => true,
603  'sitewide' => false
604  ] );
605 
606  $block->setTarget( $user );
607  $block->setBlocker( $this->getTestSysop()->getUser() );
608  $block->insert();
609 
610  $pageFoo = $this->getExistingTestPage( 'Foo' );
611  $pageBar = $this->getExistingTestPage( 'Bar' );
612  $pageJohn = $this->getExistingTestPage( 'User:John' );
613 
614  $pageRestriction = new PageRestriction( $block->getId(), $pageFoo->getId() );
615  $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_USER );
616  $this->getBlockRestrictionStore()->insert( [ $pageRestriction, $namespaceRestriction ] );
617 
618  $this->assertTrue( $block->appliesToTitle( $pageFoo->getTitle() ) );
619  $this->assertFalse( $block->appliesToTitle( $pageBar->getTitle() ) );
620  $this->assertTrue( $block->appliesToTitle( $pageJohn->getTitle() ) );
621 
622  $block->delete();
623  }
624 
630  $this->setMwGlobals( [
631  'wgBlockDisablesLogin' => false,
632  ] );
633  $user = $this->getTestUser()->getUser();
634  $block = new Block( [
635  'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
636  'allowUsertalk' => true,
637  'sitewide' => true
638  ] );
639 
640  $block->setTarget( $user );
641  $block->setBlocker( $this->getTestSysop()->getUser() );
642  $block->insert();
643 
644  $title = $this->getExistingTestPage()->getTitle();
645 
646  $this->assertTrue( $block->appliesToPage( $title->getArticleID() ) );
647  $this->assertTrue( $block->appliesToNamespace( NS_MAIN ) );
648  $this->assertTrue( $block->appliesToNamespace( NS_USER_TALK ) );
649 
650  $block->delete();
651  }
652 
657  $this->setMwGlobals( [
658  'wgBlockDisablesLogin' => false,
659  ] );
660  $user = $this->getTestUser()->getUser();
661  $block = new Block( [
662  'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
663  'allowUsertalk' => true,
664  'sitewide' => false
665  ] );
666 
667  $block->setTarget( $user );
668  $block->setBlocker( $this->getTestSysop()->getUser() );
669  $block->insert();
670 
671  $title = $this->getExistingTestPage()->getTitle();
672 
673  $pageRestriction = new PageRestriction(
674  $block->getId(),
675  $title->getArticleID()
676  );
677  $this->getBlockRestrictionStore()->insert( [ $pageRestriction ] );
678 
679  $this->assertTrue( $block->appliesToPage( $title->getArticleID() ) );
680 
681  $block->delete();
682  }
683 
688  $this->setMwGlobals( [
689  'wgBlockDisablesLogin' => false,
690  ] );
691  $user = $this->getTestUser()->getUser();
692  $block = new Block( [
693  'expiry' => wfTimestamp( TS_MW, wfTimestamp() + ( 40 * 60 * 60 ) ),
694  'allowUsertalk' => true,
695  'sitewide' => false
696  ] );
697 
698  $block->setTarget( $user );
699  $block->setBlocker( $this->getTestSysop()->getUser() );
700  $block->insert();
701 
702  $namespaceRestriction = new NamespaceRestriction( $block->getId(), NS_MAIN );
703  $this->getBlockRestrictionStore()->insert( [ $namespaceRestriction ] );
704 
705  $this->assertTrue( $block->appliesToNamespace( NS_MAIN ) );
706  $this->assertFalse( $block->appliesToNamespace( NS_USER ) );
707 
708  $block->delete();
709  }
710 
714  public function testBlockAllowsPurge() {
715  $this->setMwGlobals( [
716  'wgBlockDisablesLogin' => false,
717  ] );
718  $block = new Block();
719  $this->assertFalse( $block->appliesToRight( 'purge' ) );
720  }
721 
728  return MediaWikiServices::getInstance()->getBlockRestrictionStore();
729  }
730 }
$user
return true to allow those checks to and false if checking is done & $user
Definition: hooks.txt:1476
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
BlockTest\getBlockRestrictionStore
getBlockRestrictionStore()
Get an instance of BlockRestrictionStore.
Definition: BlockTest.php:727
MediaWikiTestCase\getTestUser
static getTestUser( $groups=[])
Convenience method for getting an immutable test user.
Definition: MediaWikiTestCase.php:180
BlockTest\getUserForBlocking
getUserForBlocking()
Definition: BlockTest.php:17
Block\newFromID
static newFromID( $id)
Load a block from the block id.
Definition: Block.php:192
Block\TYPE_IP
const TYPE_IP
Definition: Block.php:97
captcha-old.count
count
Definition: captcha-old.py:249
Block\TYPE_RANGE
const TYPE_RANGE
Definition: Block.php:98
Block\chooseBlock
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
Definition: Block.php:1523
$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 'ImportHandleUnknownUser':When a user doesn 't exist locally, this hook is called to give extensions an opportunity to auto-create it. If the auto-creation is successful, return false. $name:User name '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. '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 '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 since 1.28! 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:1983
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1912
BlockTest\providerXff
static providerXff()
Definition: BlockTest.php:315
BlockTest\testT28425BlockTimestampDefaultsToTime
testT28425BlockTimestampDefaultsToTime()
per T28425 Block::__construct
Definition: BlockTest.php:92
Block\getId
getId()
Get the block ID.
Definition: Block.php:1060
Block\newFromTarget
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
Definition: Block.php:1403
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:585
$res
$res
Definition: database.txt:21
BlockTest\addXffBlocks
addXffBlocks()
Definition: BlockTest.php:246
BlockTest\provideT31116Data
static provideT31116Data()
Definition: BlockTest.php:126
Block\insert
insert( $dbw=null)
Insert a block into the block table.
Definition: Block.php:545
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
BlockTest\testRestrictionsFromDatabase
testRestrictionsFromDatabase()
Block::getRestrictions Block::insert.
Definition: BlockTest.php:505
BlockTest\testINewFromIDReturnsCorrectBlock
testINewFromIDReturnsCorrectBlock()
Block::newFromID.
Definition: BlockTest.php:78
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
BlockTest\testBlockAllowsPurge
testBlockAllowsPurge()
Block::appliesToRight.
Definition: BlockTest.php:714
MWException
MediaWiki exception.
Definition: MWException.php:26
$title
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:925
BlockTest\testT31116NewFromTargetWithEmptyIp
testT31116NewFromTargetWithEmptyIp( $vagueTarget)
CheckUser since being changed to use Block::newFromTarget started failing because the new function di...
Definition: BlockTest.php:114
BlockTest
Database Blocking.
Definition: BlockTest.php:12
MediaWikiTestCase\setMwGlobals
setMwGlobals( $pairs, $value=null)
Sets a global, maintaining a stashed version of the previous global to be restored in tearDown.
Definition: MediaWikiTestCase.php:709
BlockTest\testBlockedUserCanNotCreateAccount
testBlockedUserCanNotCreateAccount()
Block::appliesToRight.
Definition: BlockTest.php:137
BlockTest\testAppliesToReturnsTrueOnSitewideBlock
testAppliesToReturnsTrueOnSitewideBlock()
Block::appliesToNamespace Block::appliesToPage.
Definition: BlockTest.php:629
BlockTest\testNewFromRow
testNewFromRow()
Block::newFromRow.
Definition: BlockTest.php:418
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
wfTimestampNow
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
Definition: GlobalFunctions.php:1941
BlockTest\testCrappyCrossWikiBlocks
testCrappyCrossWikiBlocks()
Block::insert.
Definition: BlockTest.php:199
Block\getBlocksForIPList
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
Definition: Block.php:1442
null
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not null
Definition: hooks.txt:780
BlockTest\testEquals
testEquals()
Block::equals.
Definition: BlockTest.php:452
BlockTest\testAppliesToTitleOnPartialBlock
testAppliesToTitleOnPartialBlock()
Block::appliesToTitle.
Definition: BlockTest.php:595
BlockTest\testIsSitewide
testIsSitewide()
Block::isSitewide.
Definition: BlockTest.php:466
NS_USER_TALK
const NS_USER_TALK
Definition: Defines.php:67
TestUser\setPasswordForUser
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
Definition: TestUser.php:129
MediaWikiTestCase\getMutableTestUser
static getMutableTestUser( $groups=[])
Convenience method for getting a mutable test user.
Definition: MediaWikiTestCase.php:192
MediaWikiTestCase\getTestSysop
static getTestSysop()
Convenience method for getting an immutable admin test user.
Definition: MediaWikiTestCase.php:204
MediaWikiLangTestCase
Base class that store and restore the Language objects.
Definition: MediaWikiLangTestCase.php:8
BlockTest\addBlockForUser
addBlockForUser(User $user)
Definition: BlockTest.php:32
Block\getQueryInfo
static getQueryInfo()
Return the tables, fields, and join conditions to be selected to create a new block object.
Definition: Block.php:260
MediaWikiTestCase\getExistingTestPage
getExistingTestPage( $title=null)
Returns a WikiPage representing an existing page.
Definition: MediaWikiTestCase.php:220
BlockTest\testINewFromTargetReturnsCorrectBlock
testINewFromTargetReturnsCorrectBlock()
Block::newFromTarget.
Definition: BlockTest.php:65
MediaWiki\Block\Restriction\NamespaceRestriction
Definition: NamespaceRestriction.php:25
BlockTest\testAppliesToNamespaceOnPartialNamespaceBlock
testAppliesToNamespaceOnPartialNamespaceBlock()
Block::appliesToNamespace.
Definition: BlockTest.php:687
IP\sanitizeIP
static sanitizeIP( $ip)
Convert an IP into a verbose, uppercase, normalized form.
Definition: IP.php:152
MediaWiki\Block\Restriction\PageRestriction
Definition: PageRestriction.php:25
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 as
Definition: distributors.txt:9
Block
Definition: Block.php:31
BlockTest\testAppliesToTitleReturnsTrueOnSitewideBlock
testAppliesToTitleReturnsTrueOnSitewideBlock()
Block::appliesToTitle.
Definition: BlockTest.php:566
NS_USER
const NS_USER
Definition: Defines.php:66
BlockTest\testSystemBlocks
testSystemBlocks()
Block::getSystemBlockType Block::insert Block::doAutoblock.
Definition: BlockTest.php:383
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
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
BlockTest\testBlocksOnXff
testBlocksOnXff( $xff, $exCount, $exResult)
providerXff Block::getBlocksForIPList Block::chooseBlock
Definition: BlockTest.php:365
BlockTest\testInsertExistingBlock
testInsertExistingBlock()
Block::insert.
Definition: BlockTest.php:531
Block\newFromRow
static newFromRow( $row)
Create a new Block object from a database row.
Definition: Block.php:505
User
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
Definition: User.php:48
$username
this hook is for auditing only or null if authentication failed before getting that far $username
Definition: hooks.txt:780
IP\sanitizeRange
static sanitizeRange( $range)
Gets rid of unneeded numbers in quad-dotted/octet IP strings For example, 127.111....
Definition: IP.php:725
BlockTest\testRestrictions
testRestrictions()
Block::getRestrictions Block::setRestrictions.
Definition: BlockTest.php:491
BlockTest\testAppliesToPageOnPartialPageBlock
testAppliesToPageOnPartialPageBlock()
Block::appliesToPage.
Definition: BlockTest.php:656
MediaWiki\Block\BlockRestrictionStore
Definition: BlockRestrictionStore.php:33