18 if (
$user->getId() == 0 ) {
19 $user->addToDatabase();
22 $user->saveSettings();
33 'address' =>
'UTBlockee',
34 'user' =>
$user->getId(),
35 'reason' =>
'Parce que',
36 'expiry' => time() + 100500,
41 $this->
block->insert();
45 $newBlockId = $this->
block->getId();
47 $this->blockId = $newBlockId;
49 throw new MWException(
"Failed to insert block for BlockTest; old leftover block remaining?" );
59 $v = $this->db->select(
'ipblocks',
'*' );
60 print "Got " . $v->numRows() .
" rows. Full dump follow:\n";
61 foreach ( $v
as $row ) {
72 "newFromTarget() returns the same block as the one that was made"
82 "newFromID() returns the same block as the one that was made"
91 $delta = abs( $this->madeAt - $this->
block->mTimestamp );
92 $this->assertLessThan(
95 "If no timestamp is specified, the block is recorded as time()"
111 "newFromTarget() returns the same block as the one that was made when "
112 .
"given empty vagueTarget param " . var_export( $vagueTarget,
true )
128 $username =
'BlockedUserToCreateAccountWith';
131 $userId = $u->getId();
132 $this->assertNotEquals( 0, $userId,
'sanity' );
139 "$username should not be blocked"
145 $u->isBlockedFromCreateAccount(),
146 "Our sandbox user should be able to create account before being blocked"
153 'reason' =>
'crosswiki block...',
155 'expiry' => $this->db->getInfinity(),
156 'createAccount' =>
true,
157 'enableAutoblock' =>
true,
159 'blockEmail' =>
true,
160 'byText' =>
'MetaWikiUser',
169 "Block object in DB should prevents 'createaccount'"
172 $this->assertInstanceOf(
175 "'$username' block block object should be existent"
181 (
bool)$u->isBlockedFromCreateAccount(),
182 "Our sandbox user '$username' should NOT be able to create account"
199 $user->addToDatabase();
200 $userId =
$user->getId();
201 $this->assertNotEquals( 0, $userId,
'sanity' );
205 'address' =>
'UserOnForeignWiki',
206 'user' =>
$user->getId(),
207 'reason' =>
'crosswiki block...',
209 'expiry' => $this->db->getInfinity(),
210 'createAccount' =>
true,
211 'enableAutoblock' =>
true,
213 'blockEmail' =>
true,
214 'byText' =>
'MetaWikiUser',
219 $this->assertTrue( (
bool)
$res[
'id'],
'Block succeeded' );
227 'Correct blockee name'
229 $this->assertEquals( $userId,
$block->
getTarget()->getId(),
'Correct blockee id' );
230 $this->assertEquals(
'MetaWikiUser',
$block->
getBlocker(),
'Correct blocker name' );
231 $this->assertEquals(
'MetaWikiUser',
$block->
getByName(),
'Correct blocker name' );
232 $this->assertEquals( 0,
$block->
getBy(),
'Correct blocker id' );
236 static $inited =
false;
245 [
'target' =>
'70.2.0.0/16',
247 'desc' =>
'Range Hardblock',
248 'ACDisable' =>
false,
249 'isHardblock' =>
true,
250 'isAutoBlocking' =>
false,
252 [
'target' =>
'2001:4860:4001::/48',
254 'desc' =>
'Range6 Hardblock',
255 'ACDisable' =>
false,
256 'isHardblock' =>
true,
257 'isAutoBlocking' =>
false,
259 [
'target' =>
'60.2.0.0/16',
261 'desc' =>
'Range Softblock with AC Disabled',
263 'isHardblock' =>
false,
264 'isAutoBlocking' =>
false,
266 [
'target' =>
'50.2.0.0/16',
268 'desc' =>
'Range Softblock',
269 'ACDisable' =>
false,
270 'isHardblock' =>
false,
271 'isAutoBlocking' =>
false,
273 [
'target' =>
'50.1.1.1',
275 'desc' =>
'Exact Softblock',
276 'ACDisable' =>
false,
277 'isHardblock' =>
false,
278 'isAutoBlocking' =>
false,
282 foreach ( $blockList
as $insBlock ) {
283 $target = $insBlock[
'target'];
294 $block->mReason = $insBlock[
'desc'];
295 $block->mExpiry =
'infinity';
305 [
'xff' =>
'1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
307 'result' =>
'Range Hardblock'
309 [
'xff' =>
'1.2.3.4, 50.2.1.1, 60.2.1.1, 2.3.4.5',
311 'result' =>
'Range Softblock with AC Disabled'
313 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.1.1.1, 2.3.4.5',
315 'result' =>
'Exact Softblock'
317 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.2.1.1, 50.1.1.1, 2.3.4.5',
319 'result' =>
'Exact Softblock'
321 [
'xff' =>
'1.2.3.4, 70.2.1.1, 50.2.1.1, 2.3.4.5',
323 'result' =>
'Range Hardblock'
325 [
'xff' =>
'1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5',
327 'result' =>
'Range Hardblock'
329 [
'xff' =>
'50.2.1.1, 60.2.1.1, 2.3.4.5',
331 'result' =>
'Range Softblock with AC Disabled'
333 [
'xff' =>
'1.2.3.4, 50.1.1.1, 60.2.1.1, 2.3.4.5',
335 'result' =>
'Exact Softblock'
337 [
'xff' =>
'1.2.3.4, <$A_BUNCH-OF{INVALID}TEXT>, 60.2.1.1, 2.3.4.5',
339 'result' =>
'Range Softblock with AC Disabled'
341 [
'xff' =>
'1.2.3.4, 50.2.1.1, 2001:4860:4001:802::1003, 2.3.4.5',
343 'result' =>
'Range6 Hardblock'
354 $list = array_map(
'trim', explode(
',', $xff ) );
356 $this->assertEquals( $exCount, count( $xffblocks ),
'Number of blocks for ' . $xff );
358 $this->assertEquals( $exResult,
$block->mReason,
'Correct block type for XFF header ' . $xff );
362 $this->
hideDeprecated(
'Block::__construct with multiple arguments' );
363 $username =
'UnthinkablySecretRandomUsername';
364 $reason =
'being irrational';
368 if ( $u->getId() == 0 ) {
374 # Make sure the user isn't blocked
377 "$username should not be blocked"
396 "Target should be set properly"
399 # Check supplied parameter
403 "Reason should be non-default"
406 # Check default parameter
409 "Account creation should not be blocked by default"
getBy()
Get the user id of the blocking sysop.
static newFromName($name, $validate= 'valid')
Static factory method for creation from username.
setBlocker($user)
Set the user who implemented (or will implement) this block.
static sanitizeIP($ip)
Convert an IP into a verbose, uppercase, normalized form.
static chooseBlock(array $blocks, array $ipChain)
From a list of multiple blocks, find the most exact and strongest Block.
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.
processing should stop and the error should be shown to the user * false
testBlocksOnXff($xff, $exCount, $exResult)
providerXff Block::getBlocksForIPList Block::chooseBlock
testINewFromIDReturnsCorrectBlock()
Block::newFromID.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
insert($dbw=null)
Insert a block into the block table.
testDeprecatedConstructor()
static setPasswordForUser(User $user, $password)
Set the password on a testing user.
static newFromTarget($specificTarget, $vagueTarget=null, $fromMaster=false)
Given a target and the target's type, get an existing Block object if possible.
testBlockedUserCanNotCreateAccount()
Block::prevents.
setTarget($target)
Set the target for this block, and update $this->type accordingly.
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
testINewFromTargetReturnsCorrectBlock()
Block::newFromTarget.
testBug29116NewFromTargetWithEmptyIp($vagueTarget)
CheckUser since being changed to use Block::newFromTarget started failing because the new function di...
const TS_MW
MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
testBug26425BlockTimestampDefaultsToTime()
per bug 26425
static provideBug29116Data()
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
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging a wrapping ErrorException instead of letting the login form give the generic error message that the account does not exist For when the account has been renamed or deleted or an array to pass a message key and parameters block
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
static getBlocksForIPList(array $ipChain, $isAnon, $fromMaster=false)
Get all blocks that match any IP from an array of IP addresses.
this hook is for auditing only or null if authentication failed before getting that far $username
dumpBlocks()
debug function : dump the ipblocks table
prevents($action, $x=null)
Get/set whether the Block prevents a given action.
getBlocker()
Get the user who implemented this block.
getTarget()
Get the target for this particular Block.
static newFromID($id)
Load a blocked user from their block id.
isHardblock($x=null)
Get/set whether the Block is a hardblock (affects logged-in users on a given IP/range) ...
testCrappyCrossWikiBlocks()
Block::insert.
getByName()
Get the username of the blocking sysop.