14 $user = $testUser->getUser();
15 $user->addToDatabase();
17 $user->saveSettings();
36 'address' =>
$user->getName(),
37 'user' =>
$user->getId(),
39 'reason' =>
'Parce que',
40 'expiry' => time() + 100500,
42 $block =
new Block( $blockOptions );
48 if ( !$block->getId() ) {
49 throw new MWException(
"Failed to insert block for BlockTest; old leftover block remaining?" );
66 "newFromTarget() returns the same block as the one that was made"
79 "newFromID() returns the same block as the one that was made"
93 $delta = abs( $madeAt - $block->mTimestamp );
94 $this->assertLessThan(
97 "If no timestamp is specified, the block is recorded as time()"
115 $initialBlock->equals( $block ),
116 "newFromTarget() returns the same block as the one that was made when "
117 .
"given empty vagueTarget param " . var_export( $vagueTarget,
true )
133 $username =
'BlockedUserToCreateAccountWith';
136 $userId = $u->getId();
137 $this->assertNotEquals( 0, $userId,
'sanity' );
144 "$username should not be blocked"
150 $u->isBlockedFromCreateAccount(),
151 "Our sandbox user should be able to create account before being blocked"
158 'reason' =>
'crosswiki block...',
160 'expiry' => $this->db->getInfinity(),
161 'createAccount' =>
true,
162 'enableAutoblock' =>
true,
164 'blockEmail' =>
true,
165 'byText' =>
'm>MetaWikiUser',
167 $block =
new Block( $blockOptions );
173 (
bool)$block->prevents(
'createaccount' ),
174 "Block object in DB should prevents 'createaccount'"
177 $this->assertInstanceOf(
180 "'$username' block block object should be existent"
186 (
bool)$u->isBlockedFromCreateAccount(),
187 "Our sandbox user '$username' should NOT be able to create account"
204 $user->addToDatabase();
205 $userId =
$user->getId();
206 $this->assertNotEquals( 0, $userId,
'sanity' );
210 'address' =>
'UserOnForeignWiki',
211 'user' =>
$user->getId(),
212 'reason' =>
'crosswiki block...',
214 'expiry' => $this->db->getInfinity(),
215 'createAccount' =>
true,
216 'enableAutoblock' =>
true,
218 'blockEmail' =>
true,
219 'byText' =>
'Meta>MetaWikiUser',
221 $block =
new Block( $blockOptions );
223 $res = $block->insert( $this->db );
224 $this->assertTrue( (
bool)
$res[
'id'],
'Block succeeded' );
231 $block->getTarget()->getName(),
232 'Correct blockee name'
234 $this->assertEquals( $userId, $block->getTarget()->getId(),
'Correct blockee id' );
235 $this->assertEquals(
'Meta>MetaWikiUser', $block->getBlocker()->getName(),
236 'Correct blocker name' );
237 $this->assertEquals(
'Meta>MetaWikiUser', $block->getByName(),
'Correct blocker name' );
238 $this->assertEquals( 0, $block->getBy(),
'Correct blocker id' );
242 static $inited =
false;
251 [
'target' =>
'70.2.0.0/16',
253 'desc' =>
'Range Hardblock',
254 'ACDisable' =>
false,
255 'isHardblock' =>
true,
256 'isAutoBlocking' =>
false,
258 [
'target' =>
'2001:4860:4001::/48',
260 'desc' =>
'Range6 Hardblock',
261 'ACDisable' =>
false,
262 'isHardblock' =>
true,
263 'isAutoBlocking' =>
false,
265 [
'target' =>
'60.2.0.0/16',
267 'desc' =>
'Range Softblock with AC Disabled',
269 'isHardblock' =>
false,
270 'isAutoBlocking' =>
false,
272 [
'target' =>
'50.2.0.0/16',
274 'desc' =>
'Range Softblock',
275 'ACDisable' =>
false,
276 'isHardblock' =>
false,
277 'isAutoBlocking' =>
false,
279 [
'target' =>
'50.1.1.1',
281 'desc' =>
'Exact Softblock',
282 'ACDisable' =>
false,
283 'isHardblock' =>
false,
284 'isAutoBlocking' =>
false,
289 foreach ( $blockList
as $insBlock ) {
290 $target = $insBlock[
'target'];
295 $target = IP::sanitizeRange( $target );
298 $block =
new Block();
299 $block->setTarget( $target );
300 $block->setBlocker( $blocker );
301 $block->mReason = $insBlock[
'desc'];
302 $block->mExpiry =
'infinity';
303 $block->prevents(
'createaccount', $insBlock[
'ACDisable'] );
304 $block->isHardblock( $insBlock[
'isHardblock'] );
305 $block->isAutoblocking( $insBlock[
'isAutoBlocking'] );
312 [
'xff' =>
'1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
314 'result' =>
'Range Hardblock'
316 [
'xff' =>
'1.2.3.4, 50.2.1.1, 60.2.1.1, 2.3.4.5',
318 'result' =>
'Range Softblock with AC Disabled'
320 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.1.1.1, 2.3.4.5',
322 'result' =>
'Exact Softblock'
324 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.2.1.1, 50.1.1.1, 2.3.4.5',
326 'result' =>
'Exact Softblock'
328 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.2.1.1, 2.3.4.5',
330 'result' =>
'Range Hardblock'
332 [
'xff' =>
'1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
334 'result' =>
'Range Hardblock'
336 [
'xff' =>
'50.2.1.1, 60.2.1.1, 2.3.4.5',
338 'result' =>
'Range Softblock with AC Disabled'
340 [
'xff' =>
'1.2.3.4, 50.1.1.1, 60.2.1.1, 2.3.4.5',
342 'result' =>
'Exact Softblock'
344 [
'xff' =>
'1.2.3.4, <$A_BUNCH-OF{INVALID}TEXT>, 60.2.1.1, 2.3.4.5',
346 'result' =>
'Range Softblock with AC Disabled'
348 [
'xff' =>
'1.2.3.4, 50.2.1.1, 2001:4860:4001:802::1003, 2.3.4.5',
350 'result' =>
'Range6 Hardblock'
364 $list = array_map(
'trim', explode(
',', $xff ) );
366 $this->assertEquals( $exCount, count( $xffblocks ),
'Number of blocks for ' . $xff );
368 $this->assertEquals( $exResult, $block->mReason,
'Correct block type for XFF header ' . $xff );
375 $this->
hideDeprecated(
'Block::__construct with multiple arguments' );
376 $username =
'UnthinkablySecretRandomUsername';
377 $reason =
'being irrational';
381 if ( $u->getId() == 0 ) {
387 # Make sure the user isn't blocked
390 "$username should not be blocked"
407 $block->getTarget()->getName(),
409 "Target should be set properly"
412 # Check supplied parameter
416 "Reason should be non-default"
419 # Check default parameter
421 (
bool)$block->prevents(
'createaccount' ),
422 "Account creation should not be blocked by default"
436 'address' =>
$user->getName(),
437 'reason' =>
'test system block',
439 'expiry' => $this->db->getInfinity(),
440 'byText' =>
'MediaWiki default',
441 'systemBlock' =>
'test',
442 'enableAutoblock' =>
true,
444 $block =
new Block( $blockOptions );
446 $this->assertSame(
'test', $block->getSystemBlockType() );
450 $this->fail(
'Expected exception not thrown' );
452 $this->assertSame(
'Cannot insert a system block into the database', $ex->getMessage() );
456 $block->doAutoblock(
'192.0.2.2' );
457 $this->fail(
'Expected exception not thrown' );
459 $this->assertSame(
'Cannot autoblock from a system block', $ex->getMessage() );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
testDeprecatedConstructor()
Block::__construct.
testBlockedUserCanNotCreateAccount()
Block::prevents.
testINewFromIDReturnsCorrectBlock()
Block::newFromID.
addBlockForUser(User $user)
testT31116NewFromTargetWithEmptyIp( $vagueTarget)
CheckUser since being changed to use Block::newFromTarget started failing because the new function di...
testCrappyCrossWikiBlocks()
Block::insert.
testINewFromTargetReturnsCorrectBlock()
Block::newFromTarget.
testT28425BlockTimestampDefaultsToTime()
per T28425 Block::__construct
testSystemBlocks()
Block::getSystemBlockType Block::insert Block::doAutoblock.
static provideT31116Data()
testBlocksOnXff( $xff, $exCount, $exResult)
providerXff Block::getBlocksForIPList Block::chooseBlock
static newFromID( $id)
Load a blocked user from their block id.
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
static newFromTarget( $specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
this hook is for auditing only or null if authentication failed before getting that far $username
processing should stop and the error should be shown to the user * false
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 local account $user
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