summaryrefslogtreecommitdiff
path: root/includes/Block.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
committerPierre Schmitz <pierre@archlinux.de>2013-01-18 16:46:04 +0100
commit63601400e476c6cf43d985f3e7b9864681695ed4 (patch)
treef7846203a952e38aaf66989d0a4702779f549962 /includes/Block.php
parent8ff01378c9e0207f9169b81966a51def645b6a51 (diff)
Update to MediaWiki 1.20.2
this update includes: * adjusted Arch Linux skin * updated FluxBBAuthPlugin * patch for https://bugzilla.wikimedia.org/show_bug.cgi?id=44024
Diffstat (limited to 'includes/Block.php')
-rw-r--r--includes/Block.php100
1 files changed, 52 insertions, 48 deletions
diff --git a/includes/Block.php b/includes/Block.php
index d80edb5e..732699dc 100644
--- a/includes/Block.php
+++ b/includes/Block.php
@@ -28,11 +28,15 @@ class Block {
$mBlockEmail,
$mDisableUsertalk,
- $mCreateAccount;
+ $mCreateAccount,
+ $mParentBlockId;
/// @var User|String
protected $target;
+ // @var Integer Hack for foreign blocking (CentralAuth)
+ protected $forcedTargetID;
+
/// @var Block::TYPE_ constant. Can only be USER, IP or RANGE internally
protected $type;
@@ -72,7 +76,7 @@ class Block {
$this->setTarget( $address );
if ( $this->target instanceof User && $user ) {
- $this->target->setId( $user ); // needed for foreign users
+ $this->forcedTargetID = $user; // needed for foreign users
}
if ( $by ) { // local user
$this->setBlocker( User::newFromID( $by ) );
@@ -122,18 +126,43 @@ class Block {
$dbr = wfGetDB( DB_SLAVE );
$res = $dbr->selectRow(
'ipblocks',
- '*',
+ self::selectFields(),
array( 'ipb_id' => $id ),
__METHOD__
);
if ( $res ) {
- return Block::newFromRow( $res );
+ return self::newFromRow( $res );
} else {
return null;
}
}
/**
+ * Return the list of ipblocks fields that should be selected to create
+ * a new block.
+ * @return array
+ */
+ public static function selectFields() {
+ return array(
+ 'ipb_id',
+ 'ipb_address',
+ 'ipb_by',
+ 'ipb_by_text',
+ 'ipb_reason',
+ 'ipb_timestamp',
+ 'ipb_auto',
+ 'ipb_anon_only',
+ 'ipb_create_account',
+ 'ipb_enable_autoblock',
+ 'ipb_expiry',
+ 'ipb_deleted',
+ 'ipb_block_email',
+ 'ipb_allow_usertalk',
+ 'ipb_parent_block_id',
+ );
+ }
+
+ /**
* Check if two blocks are effectively equal. Doesn't check irrelevant things like
* the blocking user or the block timestamp, only things which affect the blocked user *
*
@@ -243,7 +272,7 @@ class Block {
}
}
- $res = $db->select( 'ipblocks', '*', $conds, __METHOD__ );
+ $res = $db->select( 'ipblocks', self::selectFields(), $conds, __METHOD__ );
# This result could contain a block on the user, a block on the IP, and a russian-doll
# set of rangeblocks. We want to choose the most specific one, so keep a leader board.
@@ -256,7 +285,7 @@ class Block {
$bestBlockPreventsEdit = null;
foreach( $res as $row ){
- $block = Block::newFromRow( $row );
+ $block = self::newFromRow( $row );
# Don't use expired blocks
if( $block->deleteIfExpired() ){
@@ -365,6 +394,7 @@ class Block {
$this->mAuto = $row->ipb_auto;
$this->mHideName = $row->ipb_deleted;
$this->mId = $row->ipb_id;
+ $this->mParentBlockId = $row->ipb_parent_block_id;
// I wish I didn't have to do this
$db = wfGetDB( DB_SLAVE );
@@ -408,6 +438,7 @@ class Block {
}
$dbw = wfGetDB( DB_MASTER );
+ $dbw->delete( 'ipblocks', array( 'ipb_parent_block_id' => $this->getId() ), __METHOD__ );
$dbw->delete( 'ipblocks', array( 'ipb_id' => $this->getId() ), __METHOD__ );
return $dbw->affectedRows() > 0;
@@ -483,9 +514,15 @@ class Block {
}
$expiry = $db->encodeExpiry( $this->mExpiry );
+ if ( $this->forcedTargetID ) {
+ $uid = $this->forcedTargetID;
+ } else {
+ $uid = $this->target instanceof User ? $this->target->getID() : 0;
+ }
+
$a = array(
'ipb_address' => (string)$this->target,
- 'ipb_user' => $this->target instanceof User ? $this->target->getID() : 0,
+ 'ipb_user' => $uid,
'ipb_by' => $this->getBy(),
'ipb_by_text' => $this->getByName(),
'ipb_reason' => $this->mReason,
@@ -499,7 +536,8 @@ class Block {
'ipb_range_end' => $this->getRangeEnd(),
'ipb_deleted' => intval( $this->mHideName ), // typecast required for SQLite
'ipb_block_email' => $this->prevents( 'sendemail' ),
- 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' )
+ 'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
+ 'ipb_parent_block_id' => $this->mParentBlockId
);
return $a;
@@ -575,7 +613,7 @@ class Block {
$key = wfMemcKey( 'ipb', 'autoblock', 'whitelist' );
$lines = $wgMemc->get( $key );
if ( !$lines ) {
- $lines = explode( "\n", wfMsgForContentNoTrans( 'autoblock_whitelist' ) );
+ $lines = explode( "\n", wfMessage( 'autoblock_whitelist' )->inContentLanguage()->plain() );
$wgMemc->set( $key, $lines, 3600 * 24 );
}
@@ -649,7 +687,7 @@ class Block {
wfDebug( "Autoblocking {$this->getTarget()}@" . $autoblockIP . "\n" );
$autoblock->setTarget( $autoblockIP );
$autoblock->setBlocker( $this->getBlocker() );
- $autoblock->mReason = wfMsgForContent( 'autoblocker', $this->getTarget(), $this->mReason );
+ $autoblock->mReason = wfMessage( 'autoblocker', $this->getTarget(), $this->mReason )->inContentLanguage()->text();
$timestamp = wfTimestampNow();
$autoblock->mTimestamp = $timestamp;
$autoblock->mAuto = 1;
@@ -657,6 +695,7 @@ class Block {
# Continue suppressing the name if needed
$autoblock->mHideName = $this->mHideName;
$autoblock->prevents( 'editownusertalk', $this->prevents( 'editownusertalk' ) );
+ $autoblock->mParentBlockId = $this->mId;
if ( $this->mExpiry == 'infinity' ) {
# Original block was indefinite, start an autoblock now
@@ -896,7 +935,7 @@ class Block {
* Encode expiry for DB
*
* @param $expiry String: timestamp for expiry, or
- * @param $db Database object
+ * @param $db DatabaseBase object
* @return String
* @deprecated since 1.18; use $dbw->encodeExpiry() instead
*/
@@ -964,41 +1003,6 @@ class Block {
}
/**
- * Convert a DB-encoded expiry into a real string that humans can read.
- *
- * @param $encoded_expiry String: Database encoded expiry time
- * @return Html-escaped String
- * @deprecated since 1.18; use $wgLang->formatExpiry() instead
- */
- public static function formatExpiry( $encoded_expiry ) {
- wfDeprecated( __METHOD__, '1.18' );
-
- global $wgContLang;
- static $msg = null;
-
- if ( is_null( $msg ) ) {
- $msg = array();
- $keys = array( 'infiniteblock', 'expiringblock' );
-
- foreach ( $keys as $key ) {
- $msg[$key] = wfMsgHtml( $key );
- }
- }
-
- $expiry = $wgContLang->formatExpiry( $encoded_expiry, TS_MW );
- if ( $expiry == wfGetDB( DB_SLAVE )->getInfinity() ) {
- $expirystr = $msg['infiniteblock'];
- } else {
- global $wgLang;
- $expiredatestr = htmlspecialchars( $wgLang->date( $expiry, true ) );
- $expiretimestr = htmlspecialchars( $wgLang->time( $expiry, true ) );
- $expirystr = wfMsgReplaceArgs( $msg['expiringblock'], array( $expiredatestr, $expiretimestr ) );
- }
-
- return $expirystr;
- }
-
- /**
* Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
* ("24 May 2034"), into an absolute timestamp we can put into the database.
* @param $expiry String: whatever was typed into the form
@@ -1066,8 +1070,6 @@ class Block {
* @return array( User|String, Block::TYPE_ constant )
*/
public static function parseTarget( $target ) {
- $target = trim( $target );
-
# We may have been through this before
if( $target instanceof User ){
if( IP::isValid( $target->getName() ) ){
@@ -1079,6 +1081,8 @@ class Block {
return array( null, null );
}
+ $target = trim( $target );
+
if ( IP::isValid( $target ) ) {
# We can still create a User if it's an IP address, but we need to turn
# off validation checking (which would exclude IP addresses)