Block Class Reference

The block class All the functions in this class assume the object is either explicitly loaded or filled. More...

List of all members.

Public Member Functions

 __construct ($address= '', $user=0, $by=0, $reason= '', $timestamp= '', $auto=0, $expiry= '', $anonOnly=0, $createAccount=0, $enableAutoblock=0, $hideName=0, $blockEmail=0, $allowUsertalk=0)
 equals (Block $block)
 Check if two blocks are effectively equal.
 clear ()
 Clear all member variables in the current object.
 load ($address= '', $user=0, $killExpired=true)
 Get a block from the DB, with either the given address or the given username.
 loadRange ($address, $killExpired=true, $user=0)
 Search the database for any range blocks matching the given address, and load the row if one is found.
 initFromRow ($row)
 Given a database row from the ipblocks table, initialize member variables.
 delete ()
 Delete the row from the IP blocks table.
 insert ()
 Insert a block into the block table.
 update ()
 Update a block in the DB with new parameters.
 doRetroactiveAutoblock ()
 Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.
 doAutoblock ($autoblockIP, $justInserted=false)
 Autoblocks the given IP, referring to this Block.
 deleteIfExpired ()
 Check if a block has expired.
 isExpired ()
 Has the block expired?
 isValid ()
 Is the block address valid (i.e.
 updateTimestamp ()
 Update the timestamp on autoblocks.
 getBy ()
 Get the user id of the blocking sysop.
 getByName ()
 Get the username of the blocking sysop.
 forUpdate ($x=NULL)
 Get/set the SELECT .
 fromMaster ($x=NULL)
 Get/set a flag determining whether the master is used for reads.
 getRedactedName ()
 Get the block name, but with autoblocked IPs hidden as per standard privacy policy.

Static Public Member Functions

static newFromDB ($address, $user=0, $killExpired=true)
 Load a block from the database, using either the IP address or user ID.
static newFromID ($id)
 Load a blocked user from their block id.
static isWhitelistedFromAutoblocks ($ip)
 Checks whether a given IP is on the autoblock whitelist.
static encodeExpiry ($expiry, $db)
 Encode expiry for DB.
static decodeExpiry ($expiry, $timestampType=TS_MW)
 Decode expiry which has come from the DB.
static getAutoblockExpiry ($timestamp)
 Get a timestamp of the expiry for autoblocks.
static normaliseRange ($range)
 Gets rid of uneeded numbers in quad-dotted/octet IP strings For example, 127.111.113.151/24 -> 127.111.113.0/24.
static purgeExpired ()
 Purge expired blocks from the ipblocks table.
static infinity ()
 Get a value to insert into expiry field of the database when infinite expiry is desired.
static formatExpiry ($encoded_expiry)
 Convert a DB-encoded expiry into a real string that humans can read.
static parseExpiryInput ($expiry_input)
 Convert a typed-in expiry time into something we can put into the database.

Public Attributes

 $mAddress
 $mUser
 $mBy
 $mReason
 $mTimestamp
 $mAuto
 $mId
 $mExpiry
 $mRangeStart
 $mRangeEnd
 $mAnonOnly
 $mEnableAutoblock
 $mHideName
 $mBlockEmail
 $mByName
 $mAngryAutoblock
 $mAllowUsertalk
 $mNetworkBits
 $mIntegerAddr
 $mForUpdate
 $mFromMaster
const EB_KEEP_EXPIRED = 1
const EB_FOR_UPDATE = 2
const EB_RANGE_ONLY = 4

Protected Member Functions

getDBOptions (&$options)
 Get the DB object and set the reference parameter to the select options.
 loadFromResult (ResultWrapper $res, $killExpired=true)
 Fill in member variables from a result wrapper.
 initialiseRange ()
 Once $mAddress has been set, get the range they came from.
 validateBlockParams ()
 Make sure all the proper members are set to sane values before adding/updating a block.


Detailed Description

The block class All the functions in this class assume the object is either explicitly loaded or filled.

It is not load-on-demand. There are no accessors.

Globals used: $wgAutoblockExpiry, $wgAntiLockFlags

Todo:
This could be used everywhere, but it isn't.

Definition at line 16 of file Block.php.


Constructor & Destructor Documentation

Block::__construct ( address = '',
user = 0,
by = 0,
reason = '',
timestamp = '',
auto = 0,
expiry = '',
anonOnly = 0,
createAccount = 0,
enableAutoblock = 0,
hideName = 0,
blockEmail = 0,
allowUsertalk = 0 
)

Definition at line 26 of file Block.php.

References $reason, $user, decodeExpiry(), initialiseRange(), IP::sanitizeIP(), and wfTimestamp().


Member Function Documentation

Block::clear (  ) 

Clear all member variables in the current object.

Does not clear the block from the DB.

Definition at line 116 of file Block.php.

Referenced by load().

static Block::decodeExpiry ( expiry,
timestampType = TS_MW 
) [static]

Decode expiry which has come from the DB.

Parameters:
$expiry String: Database expiry format
$timestampType Requested timestamp format
Returns:
String

Definition at line 748 of file Block.php.

References infinity(), and wfTimestamp().

Referenced by __construct(), ApiQueryBlocks::execute(), formatExpiry(), ProtectedTitlesForm::formatRow(), ProtectedPagesForm::formatRow(), Title::getCascadeProtectionSources(), ApiQueryInfo::getProtectionInfo(), initFromRow(), Title::loadRestrictions(), Title::loadRestrictionsFromRow(), and ApiQueryProtectedTitles::run().

Block::delete (  ) 

Delete the row from the IP blocks table.

Returns:
Boolean

Definition at line 351 of file Block.php.

References $dbw, wfGetDB(), and wfReadOnly().

Block::deleteIfExpired (  ) 

Check if a block has expired.

Delete it if it is.

Returns:
Boolean

Definition at line 626 of file Block.php.

References $fname, isExpired(), wfDebug(), wfProfileIn(), and wfProfileOut().

Referenced by loadFromResult().

Block::doAutoblock ( autoblockIP,
justInserted = false 
)

Autoblocks the given IP, referring to this Block.

Parameters:
$autoblockIP String: the IP to autoblock.
$justInserted Boolean: the main block was just inserted
Returns:
Boolean: whether or not an autoblock was inserted.

Definition at line 561 of file Block.php.

References getAutoblockExpiry(), isWhitelistedFromAutoblocks(), newFromDB(), wfDebug(), wfMsgForContent(), wfRunHooks(), and wfTimestampNow().

Referenced by doRetroactiveAutoblock().

Block::doRetroactiveAutoblock (  ) 

Retroactively autoblocks the last IP used by the user (if it is a user) blocked by this Block.

Returns:
Boolean: whether or not a retroactive autoblock was made.

Definition at line 476 of file Block.php.

References $conds, $dbr, $options, $res, $row, doAutoblock(), wfDebug(), and wfGetDB().

Referenced by insert().

static Block::encodeExpiry ( expiry,
db 
) [static]

Encode expiry for DB.

Parameters:
$expiry String: timestamp for expiry, or
$db Database object
Returns:
String

Definition at line 733 of file Block.php.

References $db, and infinity().

Referenced by insert(), update(), Article::updateRestrictions(), and Title::updateTitleProtection().

Block::equals ( Block block  ) 

Check if two blocks are effectively equal.

Returns:
Boolean

Definition at line 96 of file Block.php.

static Block::formatExpiry ( encoded_expiry  )  [static]

Convert a DB-encoded expiry into a real string that humans can read.

Parameters:
$encoded_expiry String: Database encoded expiry time
Returns:
String

Definition at line 828 of file Block.php.

References $key, $keys, $msg, $wgLang, decodeExpiry(), wfMsgHtml(), and wfMsgReplaceArgs().

Referenced by IPUnblockForm::formatRow().

Block::forUpdate ( x = NULL  ) 

Get/set the SELECT .

.. FOR UPDATE flag

Definition at line 703 of file Block.php.

References wfSetVar().

Block::fromMaster ( x = NULL  ) 

Get/set a flag determining whether the master is used for reads.

Definition at line 710 of file Block.php.

References wfSetVar().

static Block::getAutoblockExpiry ( timestamp  )  [static]

Get a timestamp of the expiry for autoblocks.

Returns:
String

Definition at line 761 of file Block.php.

References $wgAutoblockExpiry, and wfTimestamp().

Referenced by doAutoblock(), and updateTimestamp().

Block::getBy (  ) 

Get the user id of the blocking sysop.

Returns:
Integer

Definition at line 687 of file Block.php.

Block::getByName (  ) 

Get the username of the blocking sysop.

Returns:
String

Definition at line 696 of file Block.php.

& Block::getDBOptions ( &$  options  )  [protected]

Get the DB object and set the reference parameter to the select options.

The options array will contain FOR UPDATE if appropriate.

Parameters:
$options Array
Returns:
Database

Definition at line 131 of file Block.php.

References $db, $options, $wgAntiLockFlags, and wfGetDB().

Referenced by load(), and loadRange().

Block::getRedactedName (  ) 

Get the block name, but with autoblocked IPs hidden as per standard privacy policy.

Returns:
String

Definition at line 718 of file Block.php.

static Block::infinity (  )  [static]

Get a value to insert into expiry field of the database when infinite expiry is desired.

In principle this could be DBMS-dependant, but currently all supported DBMS's support the string "infinity", so we just use that.

Returns:
String

Definition at line 816 of file Block.php.

Referenced by decodeExpiry(), RestrictUserForm::doNamespaceRestriction(), RestrictUserForm::doPageRestriction(), encodeExpiry(), ApiProtect::execute(), ApiBlock::execute(), and ProtectionForm::getExpiry().

Block::initFromRow ( row  ) 

Given a database row from the ipblocks table, initialize member variables.

Parameters:
$row ResultWrapper: a row from the ipblocks table

Definition at line 309 of file Block.php.

References $row, decodeExpiry(), and wfTimestamp().

Referenced by loadFromResult().

Block::initialiseRange (  )  [protected]

Once $mAddress has been set, get the range they came from.

Wrapper for IP::parseRange

Definition at line 337 of file Block.php.

References IP::parseRange().

Referenced by __construct(), and insert().

Block::insert (  ) 

Insert a block into the block table.

Will fail if there is a conflicting block (same name and options) already in the database.

Returns:
Boolean: whether or not the insertion was successful.

Definition at line 370 of file Block.php.

References $affected, $dbw, doRetroactiveAutoblock(), encodeExpiry(), initialiseRange(), purgeExpired(), validateBlockParams(), wfDebug(), and wfGetDB().

Block::isExpired (  ) 

Has the block expired?

Returns:
Boolean

Definition at line 645 of file Block.php.

References wfDebug(), and wfTimestampNow().

Referenced by deleteIfExpired().

Block::isValid (  ) 

Is the block address valid (i.e.

not a null string?)

Returns:
Boolean

Definition at line 658 of file Block.php.

static Block::isWhitelistedFromAutoblocks ( ip  )  [static]

Checks whether a given IP is on the autoblock whitelist.

Parameters:
$ip String: The IP to check
Returns:
Boolean

Definition at line 517 of file Block.php.

References $key, $wgMemc, IP::isInRange(), wfDebug(), wfMemcKey(), and wfMsgForContentNoTrans().

Referenced by doAutoblock().

Block::load ( address = '',
user = 0,
killExpired = true 
)

Get a block from the DB, with either the given address or the given username.

Parameters:
$address string The IP address of the user, or blank to skip IP blocks
$user int The user ID, or zero for anonymous users
$killExpired bool Whether to delete expired rows while loading
Returns:
Boolean: the user is blocked from editing

Definition at line 156 of file Block.php.

References $conds, $db, $options, $res, $user, clear(), getDBOptions(), loadFromResult(), loadRange(), and wfDebug().

Block::loadFromResult ( ResultWrapper res,
killExpired = true 
) [protected]

Fill in member variables from a result wrapper.

Parameters:
$res ResultWrapper: row from the ipblocks table
$killExpired Boolean: whether to delete expired rows while loading
Returns:
Boolean

Definition at line 235 of file Block.php.

References $row, deleteIfExpired(), ResultWrapper::fetchObject(), ResultWrapper::free(), initFromRow(), and ResultWrapper::numRows().

Referenced by load(), and loadRange().

Block::loadRange ( address,
killExpired = true,
user = 0 
)

Search the database for any range blocks matching the given address, and load the row if one is found.

Parameters:
$address String: IP address range
$killExpired Boolean: whether to delete expired rows while loading
$userid Integer: if not 0, then sets ipb_anon_only
Returns:
Boolean

Definition at line 275 of file Block.php.

References $conds, $db, $options, $res, $success, $user, getDBOptions(), loadFromResult(), and IP::toHex().

Referenced by load().

static Block::newFromDB ( address,
user = 0,
killExpired = true 
) [static]

Load a block from the database, using either the IP address or user ID.

Tries the user ID first, and if that doesn't work, tries the address.

Parameters:
$address String: IP address of user/anon
$user Integer: user id of user
$killExpired Boolean: delete expired blocks on load
Returns:
Block Object

Definition at line 63 of file Block.php.

References $user.

Referenced by doAutoblock(), IPBlockForm::doMassUserBlock(), IPUnblockForm::doUnblock(), IPBlockForm::showForm(), and User::spreadBlock().

static Block::newFromID ( id  )  [static]

Load a blocked user from their block id.

Parameters:
$id Integer: Block id to search for
Returns:
Block object

Definition at line 79 of file Block.php.

References $dbr, $res, and wfGetDB().

Referenced by IPUnblockForm::doUnblock(), and IPUnblockForm::showForm().

static Block::normaliseRange ( range  )  [static]

Gets rid of uneeded numbers in quad-dotted/octet IP strings For example, 127.111.113.151/24 -> 127.111.113.0/24.

Parameters:
$range String: IP address to normalize
Returns:
string

Definition at line 772 of file Block.php.

References IP::isIPv4(), IP::isIPv6(), IP::toOctet(), IP::toUnsigned(), IP::toUnsigned6(), and wfBaseConvert().

Referenced by IPUnblockForm::showList().

static Block::parseExpiryInput ( expiry_input  )  [static]

Convert a typed-in expiry time into something we can put into the database.

Parameters:
$expiry_input String: whatever was typed into the form
Returns:
String: more database friendly

Definition at line 855 of file Block.php.

Referenced by IPBlockForm::doMassUserBlock().

static Block::purgeExpired (  )  [static]

Purge expired blocks from the ipblocks table.

Definition at line 804 of file Block.php.

References $dbw, and wfGetDB().

Referenced by ApiQueryBlocks::execute(), insert(), and IPUnblockForm::showList().

Block::update (  ) 

Update a block in the DB with new parameters.

The ID field needs to be loaded first.

Definition at line 414 of file Block.php.

References $dbw, encodeExpiry(), validateBlockParams(), wfDebug(), and wfGetDB().

Block::updateTimestamp (  ) 

Update the timestamp on autoblocks.

Definition at line 665 of file Block.php.

References $dbw, getAutoblockExpiry(), wfGetDB(), and wfTimestamp().

Block::validateBlockParams (  )  [protected]

Make sure all the proper members are set to sane values before adding/updating a block.

Definition at line 447 of file Block.php.

References $wgUser, and User::whoIs().

Referenced by insert(), and update().


Member Data Documentation

Block::$mAddress

Definition at line 17 of file Block.php.

Block::$mAllowUsertalk

Definition at line 17 of file Block.php.

Block::$mAngryAutoblock

Definition at line 17 of file Block.php.

Block::$mAnonOnly

Definition at line 17 of file Block.php.

Block::$mAuto

Definition at line 17 of file Block.php.

Block::$mBlockEmail

Definition at line 17 of file Block.php.

Block::$mBy

Definition at line 17 of file Block.php.

Block::$mByName

Definition at line 17 of file Block.php.

Block::$mEnableAutoblock

Definition at line 17 of file Block.php.

Block::$mExpiry

Definition at line 17 of file Block.php.

Block::$mForUpdate

Definition at line 20 of file Block.php.

Block::$mFromMaster

Definition at line 20 of file Block.php.

Block::$mHideName

Definition at line 17 of file Block.php.

Block::$mId

Definition at line 17 of file Block.php.

Block::$mIntegerAddr

Definition at line 20 of file Block.php.

Block::$mNetworkBits

Definition at line 20 of file Block.php.

Block::$mRangeEnd

Definition at line 17 of file Block.php.

Block::$mRangeStart

Definition at line 17 of file Block.php.

Block::$mReason

Definition at line 17 of file Block.php.

Block::$mTimestamp

Definition at line 17 of file Block.php.

Block::$mUser

Definition at line 17 of file Block.php.

Definition at line 23 of file Block.php.

Definition at line 22 of file Block.php.

Definition at line 24 of file Block.php.


The documentation for this class was generated from the following file:

Generated on Sat Sep 5 02:08:33 2009 for MediaWiki by  doxygen 1.5.9