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