summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialBlock.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2014-12-27 15:41:37 +0100
committerPierre Schmitz <pierre@archlinux.de>2014-12-31 11:43:28 +0100
commitc1f9b1f7b1b77776192048005dcc66dcf3df2bfb (patch)
tree2b38796e738dd74cb42ecd9bfd151803108386bc /includes/specials/SpecialBlock.php
parentb88ab0086858470dd1f644e64cb4e4f62bb2be9b (diff)
Update to MediaWiki 1.24.1
Diffstat (limited to 'includes/specials/SpecialBlock.php')
-rw-r--r--includes/specials/SpecialBlock.php141
1 files changed, 78 insertions, 63 deletions
diff --git a/includes/specials/SpecialBlock.php b/includes/specials/SpecialBlock.php
index 3b73a374..3297c17a 100644
--- a/includes/specials/SpecialBlock.php
+++ b/includes/specials/SpecialBlock.php
@@ -28,27 +28,23 @@
* @ingroup SpecialPage
*/
class SpecialBlock extends FormSpecialPage {
- /** The maximum number of edits a user can have and still be hidden
- * TODO: config setting? */
- const HIDEUSER_CONTRIBLIMIT = 1000;
-
- /** @var User user to be blocked, as passed either by parameter (url?wpTarget=Foo)
+ /** @var User User to be blocked, as passed either by parameter (url?wpTarget=Foo)
* or as subpage (Special:Block/Foo) */
protected $target;
- /// @var Block::TYPE_ constant
+ /** @var int Block::TYPE_ constant */
protected $type;
- /// @var User|String the previous block target
+ /** @var User|string The previous block target */
protected $previousTarget;
- /// @var Bool whether the previous submission of the form asked for HideUser
+ /** @var bool Whether the previous submission of the form asked for HideUser */
protected $requestedHideUser;
- /// @var Bool
+ /** @var bool */
protected $alreadyBlocked;
- /// @var Array
+ /** @var array */
protected $preErrors = array();
public function __construct() {
@@ -74,7 +70,7 @@ class SpecialBlock extends FormSpecialPage {
/**
* Handle some magic here
*
- * @param $par String
+ * @param string $par
*/
protected function setParameter( $par ) {
# Extract variables from the request. Try not to get into a situation where we
@@ -88,14 +84,15 @@ class SpecialBlock extends FormSpecialPage {
$this->getSkin()->setRelevantUser( $this->target );
}
- list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
+ list( $this->previousTarget, /*...*/ ) =
+ Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
$this->requestedHideUser = $request->getBool( 'wpHideUser' );
}
/**
* Customizes the HTMLForm a bit
*
- * @param $form HTMLForm
+ * @param HTMLForm $form
*/
protected function alterForm( HTMLForm $form ) {
$form->setWrapperLegendMsg( 'blockip-legend' );
@@ -120,7 +117,7 @@ class SpecialBlock extends FormSpecialPage {
/**
* Get the HTMLForm descriptor array for the block form
- * @return Array
+ * @return array
*/
protected function getFormFields() {
global $wgBlockAllowsUTEdit;
@@ -132,8 +129,7 @@ class SpecialBlock extends FormSpecialPage {
$a = array(
'Target' => array(
'type' => 'text',
- 'label-message' => 'ipadressorusername',
- 'tabindex' => '1',
+ 'label-message' => 'ipaddressorusername',
'id' => 'mw-bi-target',
'size' => '45',
'autofocus' => true,
@@ -144,7 +140,6 @@ class SpecialBlock extends FormSpecialPage {
'type' => !count( $suggestedDurations ) ? 'text' : 'selectorother',
'label-message' => 'ipbexpiry',
'required' => true,
- 'tabindex' => '2',
'options' => $suggestedDurations,
'other' => $this->msg( 'ipbother' )->text(),
'default' => $this->msg( 'ipb-default-expiry' )->inContentLanguage()->text(),
@@ -221,6 +216,9 @@ class SpecialBlock extends FormSpecialPage {
$this->maybeAlterFormDefaults( $a );
+ // Allow extensions to add more fields
+ wfRunHooks( 'SpecialBlockModifyFormFields', array( $this, &$a ) );
+
return $a;
}
@@ -228,7 +226,7 @@ class SpecialBlock extends FormSpecialPage {
* If the user has already been blocked with similar settings, load that block
* and change the defaults for the form fields to match the existing settings.
* @param array $fields HTMLForm descriptor array
- * @return Bool whether fields were altered (that is, whether the target is
+ * @return bool Whether fields were altered (that is, whether the target is
* already blocked)
*/
protected function maybeAlterFormDefaults( &$fields ) {
@@ -293,20 +291,20 @@ class SpecialBlock extends FormSpecialPage {
if ( $this->requestedHideUser ) {
$fields['Confirm']['type'] = 'check';
unset( $fields['Confirm']['default'] );
- $this->preErrors[] = 'ipb-confirmhideuser';
+ $this->preErrors[] = array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
}
# Or if the user is trying to block themselves
if ( (string)$this->target === $this->getUser()->getName() ) {
$fields['Confirm']['type'] = 'check';
unset( $fields['Confirm']['default'] );
- $this->preErrors[] = 'ipb-blockingself';
+ $this->preErrors[] = array( 'ipb-blockingself', 'ipb-confirmaction' );
}
}
/**
* Add header elements like block log entries, etc.
- * @return String
+ * @return string
*/
protected function preText() {
$this->getOutput()->addModules( 'mediawiki.special.block' );
@@ -362,7 +360,10 @@ class SpecialBlock extends FormSpecialPage {
# Link to unblock the specified user, or to a blank unblock form
if ( $this->target instanceof User ) {
- $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target->getName() ) )->parse();
+ $message = $this->msg(
+ 'ipb-unblock-addr',
+ wfEscapeWikiText( $this->target->getName() )
+ )->parse();
$list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
} else {
$message = $this->msg( 'ipb-unblock' )->parse();
@@ -437,7 +438,7 @@ class SpecialBlock extends FormSpecialPage {
/**
* Get a user page target for things like logs.
* This handles account and IP range targets.
- * @param $target User|string
+ * @param User|string $target
* @return Title|null
*/
protected static function getTargetUserTitle( $target ) {
@@ -452,10 +453,10 @@ class SpecialBlock extends FormSpecialPage {
/**
* Determine the target of the block, and the type of target
- * TODO: should be in Block.php?
- * @param string $par subpage parameter passed to setup, or data value from
+ * @todo Should be in Block.php?
+ * @param string $par Subpage parameter passed to setup, or data value from
* the HTMLForm
- * @param $request WebRequest optionally try and get data from a request too
+ * @param WebRequest $request Optionally try and get data from a request too
* @return array( User|string|null, Block::TYPE_ constant|null )
*/
public static function getTargetAndType( $par, WebRequest $request = null ) {
@@ -504,9 +505,9 @@ class SpecialBlock extends FormSpecialPage {
/**
* HTMLForm field validation-callback for Target field.
* @since 1.18
- * @param $value String
- * @param $alldata Array
- * @param $form HTMLForm
+ * @param string $value
+ * @param array $alldata
+ * @param HTMLForm $form
* @return Message
*/
public static function validateTargetField( $value, $alldata, $form ) {
@@ -584,9 +585,9 @@ class SpecialBlock extends FormSpecialPage {
/**
* Submit callback for an HTMLForm object, will simply pass
- * @param $data array
- * @param $form HTMLForm
- * @return Bool|String
+ * @param array $data
+ * @param HTMLForm $form
+ * @return bool|string
*/
public static function processUIForm( array $data, HTMLForm $form ) {
return self::processForm( $data, $form->getContext() );
@@ -594,12 +595,12 @@ class SpecialBlock extends FormSpecialPage {
/**
* Given the form data, actually implement a block
- * @param $data Array
- * @param $context IContextSource
- * @return Bool|String
+ * @param array $data
+ * @param IContextSource $context
+ * @return bool|string
*/
public static function processForm( array $data, IContextSource $context ) {
- global $wgBlockAllowsUTEdit;
+ global $wgBlockAllowsUTEdit, $wgHideUserContribLimit, $wgContLang;
$performer = $context->getUser();
@@ -627,7 +628,7 @@ class SpecialBlock extends FormSpecialPage {
if ( $target === $performer->getName() &&
( $data['PreviousTarget'] !== $target || !$data['Confirm'] )
) {
- return array( 'ipb-blockingself' );
+ return array( 'ipb-blockingself', 'ipb-confirmaction' );
}
} elseif ( $type == Block::TYPE_RANGE ) {
$userId = 0;
@@ -670,12 +671,15 @@ class SpecialBlock extends FormSpecialPage {
} elseif ( !in_array( $data['Expiry'], array( 'infinite', 'infinity', 'indefinite' ) ) ) {
# Bad expiry.
return array( 'ipb_expiry_temp' );
- } elseif ( $user->getEditCount() > self::HIDEUSER_CONTRIBLIMIT ) {
+ } elseif ( $wgHideUserContribLimit !== false
+ && $user->getEditCount() > $wgHideUserContribLimit
+ ) {
# Typically, the user should have a handful of edits.
# Disallow hiding users with many edits for performance.
- return array( 'ipb_hide_invalid' );
+ return array( array( 'ipb_hide_invalid',
+ Message::numParam( $wgHideUserContribLimit ) ) );
} elseif ( !$data['Confirm'] ) {
- return array( 'ipb-confirmhideuser' );
+ return array( 'ipb-confirmhideuser', 'ipb-confirmaction' );
}
}
@@ -683,7 +687,8 @@ class SpecialBlock extends FormSpecialPage {
$block = new Block();
$block->setTarget( $target );
$block->setBlocker( $performer );
- $block->mReason = $data['Reason'][0];
+ # Truncate reason for whole multibyte characters
+ $block->mReason = $wgContLang->truncate( $data['Reason'][0], 255 );
$block->mExpiry = self::parseExpiryInput( $data['Expiry'] );
$block->prevents( 'createaccount', $data['CreateAccount'] );
$block->prevents( 'editownusertalk', ( !$wgBlockAllowsUTEdit || $data['DisableUTEdit'] ) );
@@ -692,8 +697,9 @@ class SpecialBlock extends FormSpecialPage {
$block->isAutoblocking( $data['AutoBlock'] );
$block->mHideName = $data['HideUser'];
- if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer ) ) ) {
- return array( 'hookaborted' );
+ $reason = array( 'hookaborted' );
+ if ( !wfRunHooks( 'BlockIp', array( &$block, &$performer, &$reason ) ) ) {
+ return $reason;
}
# Try to insert block. Is there a conflicting block?
@@ -726,8 +732,17 @@ class SpecialBlock extends FormSpecialPage {
return array( 'cant-see-hidden-user' );
}
- $currentBlock->delete();
- $status = $block->insert();
+ $currentBlock->isHardblock( $block->isHardblock() );
+ $currentBlock->prevents( 'createaccount', $block->prevents( 'createaccount' ) );
+ $currentBlock->mExpiry = $block->mExpiry;
+ $currentBlock->isAutoblocking( $block->isAutoblocking() );
+ $currentBlock->mHideName = $block->mHideName;
+ $currentBlock->prevents( 'sendemail', $block->prevents( 'sendemail' ) );
+ $currentBlock->prevents( 'editownusertalk', $block->prevents( 'editownusertalk' ) );
+ $currentBlock->mReason = $block->mReason;
+
+ $status = $currentBlock->update();
+
$logaction = 'reblock';
# Unset _deleted fields if requested
@@ -753,7 +768,11 @@ class SpecialBlock extends FormSpecialPage {
# Can't watch a rangeblock
if ( $type != Block::TYPE_RANGE && $data['Watch'] ) {
- WatchAction::doWatch( Title::makeTitle( NS_USER, $target ), $performer, WatchedItem::IGNORE_USER_RIGHTS );
+ WatchAction::doWatch(
+ Title::makeTitle( NS_USER, $target ),
+ $performer,
+ WatchedItem::IGNORE_USER_RIGHTS
+ );
}
# Block constructor sanitizes certain block options on insert
@@ -787,9 +806,9 @@ class SpecialBlock extends FormSpecialPage {
* Get an array of suggested block durations from MediaWiki:Ipboptions
* @todo FIXME: This uses a rather odd syntax for the options, should it be converted
* to the standard "**<duration>|<displayname>" format?
- * @param $lang Language|null the language to get the durations in, or null to use
+ * @param Language|null $lang The language to get the durations in, or null to use
* the wiki's content language
- * @return Array
+ * @return array
*/
public static function getSuggestedDurations( $lang = null ) {
$a = array();
@@ -816,8 +835,8 @@ class SpecialBlock extends FormSpecialPage {
/**
* Convert a submitted expiry time, which may be relative ("2 weeks", etc) or absolute
* ("24 May 2034", etc), into an absolute timestamp we can put into the database.
- * @param string $expiry whatever was typed into the form
- * @return String: timestamp or "infinity" string for the DB implementation
+ * @param string $expiry Whatever was typed into the form
+ * @return string Timestamp or "infinity" string for the DB implementation
*/
public static function parseExpiryInput( $expiry ) {
static $infinity;
@@ -842,8 +861,8 @@ class SpecialBlock extends FormSpecialPage {
/**
* Can we do an email block?
- * @param $user User: the sysop wanting to make a block
- * @return Boolean
+ * @param User $user The sysop wanting to make a block
+ * @return bool
*/
public static function canBlockEmail( $user ) {
global $wgEnableUserEmail, $wgSysopEmailBans;
@@ -855,9 +874,9 @@ class SpecialBlock extends FormSpecialPage {
* bug 15810: blocked admins should not be able to block/unblock
* others, and probably shouldn't be able to unblock themselves
* either.
- * @param $user User|Int|String
- * @param $performer User user doing the request
- * @return Bool|String true or error message key
+ * @param User|int|string $user
+ * @param User $performer User doing the request
+ * @return bool|string True or error message key
*/
public static function checkUnblockSelf( $user, User $performer ) {
if ( is_int( $user ) ) {
@@ -889,8 +908,8 @@ class SpecialBlock extends FormSpecialPage {
/**
* Return a comma-delimited list of "flags" to be passed to the log
* reader for this block, to provide more information in the logs
- * @param array $data from HTMLForm data
- * @param $type Block::TYPE_ constant (USER, RANGE, or IP)
+ * @param array $data From HTMLForm data
+ * @param int $type Block::TYPE_ constant (USER, RANGE, or IP)
* @return string
*/
protected static function blockLogFlags( array $data, $type ) {
@@ -935,8 +954,8 @@ class SpecialBlock extends FormSpecialPage {
/**
* Process the form on POST submission.
- * @param $data Array
- * @return Bool|Array true for success, false for didn't-try, array of errors on failure
+ * @param array $data
+ * @return bool|array True for success, false for didn't-try, array of errors on failure
*/
public function onSubmit( array $data ) {
// This isn't used since we need that HTMLForm that's passed in the
@@ -957,7 +976,3 @@ class SpecialBlock extends FormSpecialPage {
return 'users';
}
}
-
-# BC @since 1.18
-class IPBlockForm extends SpecialBlock {
-}