* @since 1.26 accepts $options array instead of individual parameters; order
* of parameters above reflects the original order
*/
- function __construct( $options = array() ) {
- $defaults = array(
+ function __construct( $options = [] ) {
+ $defaults = [
'address' => '',
'user' => null,
'by' => null,
'blockEmail' => false,
'allowUsertalk' => false,
'byText' => '',
- );
+ ];
if ( func_num_args() > 1 || !is_array( $options ) ) {
$options = array_combine(
$res = $dbr->selectRow(
'ipblocks',
self::selectFields(),
- array( 'ipb_id' => $id ),
+ [ 'ipb_id' => $id ],
__METHOD__
);
if ( $res ) {
* @return array
*/
public static function selectFields() {
- return array(
+ return [
'ipb_id',
'ipb_address',
'ipb_by',
'ipb_block_email',
'ipb_allow_usertalk',
'ipb_parent_block_id',
- );
+ ];
}
/**
$db = wfGetDB( $this->mFromMaster ? DB_MASTER : DB_SLAVE );
if ( $this->type !== null ) {
- $conds = array(
- 'ipb_address' => array( (string)$this->target ),
- );
+ $conds = [
+ 'ipb_address' => [ (string)$this->target ],
+ ];
} else {
- $conds = array( 'ipb_address' => array() );
+ $conds = [ 'ipb_address' => [] ];
}
# Be aware that the != '' check is explicit, since empty values will be
$safeEnd = $dbr->addQuotes( $end );
return $dbr->makeList(
- array(
+ [
"ipb_range_start $like",
"ipb_range_start <= $safeStart",
"ipb_range_end >= $safeEnd",
- ),
+ ],
LIST_AND
);
}
}
$dbw = wfGetDB( DB_MASTER );
- $dbw->delete( 'ipblocks', array( 'ipb_parent_block_id' => $this->getId() ), __METHOD__ );
- $dbw->delete( 'ipblocks', array( 'ipb_id' => $this->getId() ), __METHOD__ );
+ $dbw->delete( 'ipblocks', [ 'ipb_parent_block_id' => $this->getId() ], __METHOD__ );
+ $dbw->delete( 'ipblocks', [ 'ipb_id' => $this->getId() ], __METHOD__ );
return $dbw->affectedRows() > 0;
}
$row = $this->getDatabaseArray();
$row['ipb_id'] = $dbw->nextSequenceValue( "ipblocks_ipb_id_seq" );
- $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) );
+ $dbw->insert( 'ipblocks', $row, __METHOD__, [ 'IGNORE' ] );
$affected = $dbw->affectedRows();
$this->mId = $dbw->insertId();
# use a standard SELECT + DELETE to avoid annoying gap locks.
$ids = $dbw->selectFieldValues( 'ipblocks',
'ipb_id',
- array(
+ [
'ipb_address' => $row['ipb_address'],
'ipb_user' => $row['ipb_user'],
'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() )
- ),
+ ],
__METHOD__
);
if ( $ids ) {
- $dbw->delete( 'ipblocks', array( 'ipb_id' => $ids ), __METHOD__ );
- $dbw->insert( 'ipblocks', $row, __METHOD__, array( 'IGNORE' ) );
+ $dbw->delete( 'ipblocks', [ 'ipb_id' => $ids ], __METHOD__ );
+ $dbw->insert( 'ipblocks', $row, __METHOD__, [ 'IGNORE' ] );
$affected = $dbw->affectedRows();
$this->mId = $dbw->insertId();
}
if ( $affected ) {
$auto_ipd_ids = $this->doRetroactiveAutoblock();
- return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
+ return [ 'id' => $this->mId, 'autoIds' => $auto_ipd_ids ];
}
return false;
$dbw->update(
'ipblocks',
$this->getDatabaseArray( $dbw ),
- array( 'ipb_id' => $this->getId() ),
+ [ 'ipb_id' => $this->getId() ],
__METHOD__
);
$dbw->update(
'ipblocks',
$this->getAutoblockUpdateArray(),
- array( 'ipb_parent_block_id' => $this->getId() ),
+ [ 'ipb_parent_block_id' => $this->getId() ],
__METHOD__
);
} else {
// autoblock no longer required, delete corresponding autoblock(s)
$dbw->delete(
'ipblocks',
- array( 'ipb_parent_block_id' => $this->getId() ),
+ [ 'ipb_parent_block_id' => $this->getId() ],
__METHOD__
);
}
if ( $affected ) {
$auto_ipd_ids = $this->doRetroactiveAutoblock();
- return array( 'id' => $this->mId, 'autoIds' => $auto_ipd_ids );
+ return [ 'id' => $this->mId, 'autoIds' => $auto_ipd_ids ];
}
return false;
$uid = $this->target instanceof User ? $this->target->getID() : 0;
}
- $a = array(
+ $a = [
'ipb_address' => (string)$this->target,
'ipb_user' => $uid,
'ipb_by' => $this->getBy(),
'ipb_block_email' => $this->prevents( 'sendemail' ),
'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
'ipb_parent_block_id' => $this->mParentBlockId
- );
+ ];
return $a;
}
* @return array
*/
protected function getAutoblockUpdateArray() {
- return array(
+ return [
'ipb_by' => $this->getBy(),
'ipb_by_text' => $this->getByName(),
'ipb_reason' => $this->mReason,
'ipb_create_account' => $this->prevents( 'createaccount' ),
'ipb_deleted' => (int)$this->mHideName, // typecast required for SQLite
'ipb_allow_usertalk' => !$this->prevents( 'editownusertalk' ),
- );
+ ];
}
/**
* @return array Block IDs of retroactive autoblocks made
*/
protected function doRetroactiveAutoblock() {
- $blockIds = array();
+ $blockIds = [];
# If autoblock is enabled, autoblock the LAST IP(s) used
if ( $this->isAutoblocking() && $this->getType() == self::TYPE_USER ) {
wfDebug( "Doing retroactive autoblocks for " . $this->getTarget() . "\n" );
$continue = Hooks::run(
- 'PerformRetroactiveAutoblock', array( $this, &$blockIds ) );
+ 'PerformRetroactiveAutoblock', [ $this, &$blockIds ] );
if ( $continue ) {
self::defaultRetroactiveAutoblock( $this, $blockIds );
$dbr = wfGetDB( DB_SLAVE );
- $options = array( 'ORDER BY' => 'rc_timestamp DESC' );
- $conds = array( 'rc_user_text' => (string)$block->getTarget() );
+ $options = [ 'ORDER BY' => 'rc_timestamp DESC' ];
+ $conds = [ 'rc_user_text' => (string)$block->getTarget() ];
// Just the last IP used.
$options['LIMIT'] = 1;
- $res = $dbr->select( 'recentchanges', array( 'rc_ip' ), $conds,
+ $res = $dbr->select( 'recentchanges', [ 'rc_ip' ], $conds,
__METHOD__, $options );
if ( !$res->numRows() ) {
}
# Allow hooks to cancel the autoblock.
- if ( !Hooks::run( 'AbortAutoblock', array( $autoblockIP, &$this ) ) ) {
+ if ( !Hooks::run( 'AbortAutoblock', [ $autoblockIP, &$this ] ) ) {
wfDebug( "Autoblock aborted by hook.\n" );
return false;
}
$dbw = wfGetDB( DB_MASTER );
$dbw->update( 'ipblocks',
- array( /* SET */
+ [ /* SET */
'ipb_timestamp' => $dbw->timestamp( $this->mTimestamp ),
'ipb_expiry' => $dbw->timestamp( $this->mExpiry ),
- ),
- array( /* WHERE */
- 'ipb_address' => (string)$this->getTarget()
- ),
+ ],
+ [ /* WHERE */
+ 'ipb_id' => $this->getId(),
+ ],
__METHOD__
);
}
if ( $this->mAuto ) {
return Html::rawElement(
'span',
- array( 'class' => 'mw-autoblockid' ),
+ [ 'class' => 'mw-autoblockid' ],
wfMessage( 'autoblockid', $this->mId )
);
} else {
function ( IDatabase $dbw, $fname ) {
$dbw->delete(
'ipblocks',
- array( 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ),
+ [ 'ipb_expiry < ' . $dbw->addQuotes( $dbw->timestamp() ) ],
$fname
);
}
} elseif ( in_array(
$type,
- array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) )
+ [ Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ] )
) {
$block = new Block();
$block->fromMaster( $fromMaster );
*/
public static function getBlocksForIPList( array $ipChain, $isAnon, $fromMaster = false ) {
if ( !count( $ipChain ) ) {
- return array();
+ return [];
}
- $conds = array();
+ $conds = [];
foreach ( array_unique( $ipChain ) as $ipaddr ) {
# Discard invalid IP addresses. Since XFF can be spoofed and we do not
# necessarily trust the header given to us, make sure that we are only
}
if ( !count( $conds ) ) {
- return array();
+ return [];
}
if ( $fromMaster ) {
}
$conds = $db->makeList( $conds, LIST_OR );
if ( !$isAnon ) {
- $conds = array( $conds, 'ipb_anon_only' => 0 );
+ $conds = [ $conds, 'ipb_anon_only' => 0 ];
}
$selectFields = array_merge(
- array( 'ipb_range_start', 'ipb_range_end' ),
+ [ 'ipb_range_start', 'ipb_range_end' ],
Block::selectFields()
);
$rows = $db->select( 'ipblocks',
__METHOD__
);
- $blocks = array();
+ $blocks = [];
foreach ( $rows as $row ) {
$block = self::newFromRow( $row );
if ( !$block->isExpired() ) {
return strcmp( $bWeight, $aWeight ); // highest weight first
} );
- $blocksListExact = array(
+ $blocksListExact = [
'hard' => false,
'disable_create' => false,
'other' => false,
'auto' => false
- );
- $blocksListRange = array(
+ ];
+ $blocksListRange = [
'hard' => false,
'disable_create' => false,
'other' => false,
'auto' => false
- );
+ ];
$ipChain = array_reverse( $ipChain );
/** @var Block $block */
}
// We found closest exact match in the ip list, so go to the next Block
break;
- } elseif ( array_filter( $blocksListExact ) == array()
+ } elseif ( array_filter( $blocksListExact ) == []
&& $block->getRangeStart() <= $checkipHex
&& $block->getRangeEnd() >= $checkipHex
) {
}
}
- if ( array_filter( $blocksListExact ) == array() ) {
+ if ( array_filter( $blocksListExact ) == [] ) {
$blocksList = &$blocksListRange;
} else {
$blocksList = &$blocksListExact;
# We may have been through this before
if ( $target instanceof User ) {
if ( IP::isValid( $target->getName() ) ) {
- return array( $target, self::TYPE_IP );
+ return [ $target, self::TYPE_IP ];
} else {
- return array( $target, self::TYPE_USER );
+ return [ $target, self::TYPE_USER ];
}
} elseif ( $target === null ) {
- return array( null, null );
+ return [ 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)
- return array(
+ return [
User::newFromName( IP::sanitizeIP( $target ), false ),
Block::TYPE_IP
- );
+ ];
} elseif ( IP::isValidBlock( $target ) ) {
# Can't create a User from an IP range
- return array( IP::sanitizeRange( $target ), Block::TYPE_RANGE );
+ return [ IP::sanitizeRange( $target ), Block::TYPE_RANGE ];
}
# Consider the possibility that this is not a username at all
# but actually an old subpage (bug #29797)
if ( strpos( $target, '/' ) !== false ) {
# An old subpage, drill down to the user behind it
- $parts = explode( '/', $target );
- $target = $parts[0];
+ $target = explode( '/', $target )[0];
}
$userObj = User::newFromName( $target );
# Note that since numbers are valid usernames, a $target of "12345" will be
# considered a User. If you want to pass a block ID, prepend a hash "#12345",
# since hash characters are not valid in usernames or titles generally.
- return array( $userObj, Block::TYPE_USER );
+ return [ $userObj, Block::TYPE_USER ];
} elseif ( preg_match( '/^#\d+$/', $target ) ) {
# Autoblock reference in the form "#12345"
- return array( substr( $target, 1 ), Block::TYPE_AUTO );
+ return [ substr( $target, 1 ), Block::TYPE_AUTO ];
} else {
# WTF?
- return array( null, null );
+ return [ null, null ];
}
}
* @todo FIXME: This should be an integral part of the Block member variables
*/
public function getTargetAndType() {
- return array( $this->getTarget(), $this->getType() );
+ return [ $this->getTarget(), $this->getType() ];
}
/**
$intended = $this->getTarget();
$lang = $context->getLanguage();
- return array(
+ return [
$this->mAuto ? 'autoblockedtext' : 'blockedtext',
$link,
$reason,
$lang->formatExpiry( $this->mExpiry ),
(string)$intended,
$lang->userTimeAndDate( $this->mTimestamp, $context->getUser() ),
- );
+ ];
}
}