*
* @ingroup SpecialPage
*/
-class SpecialBlock extends 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;
parent::__construct( 'Block', 'block' );
}
- public function execute( $par ) {
- $this->checkPermissions();
- $this->checkReadOnly();
+ /**
+ * Checks that the user can unblock themselves if they are trying to do so
+ *
+ * @param User $user
+ * @throws ErrorPageError
+ */
+ protected function checkExecutePermissions( User $user ) {
+ parent::checkExecutePermissions( $user );
+
+ # bug 15810: blocked admins should have limited access here
+ $status = self::checkUnblockSelf( $this->target, $user );
+ if ( $status !== true ) {
+ throw new ErrorPageError( 'badaccess', $status );
+ }
+ }
+ /**
+ * Handle some magic here
+ *
+ * @param $par String
+ */
+ protected function setParameter( $par ) {
# Extract variables from the request. Try not to get into a situation where we
# need to extract *every* variable from the form just for processing here, but
# there are legitimate uses for some variables
list( $this->previousTarget, /*...*/ ) = Block::parseTarget( $request->getVal( 'wpPreviousTarget' ) );
$this->requestedHideUser = $request->getBool( 'wpHideUser' );
+ }
- # bug 15810: blocked admins should have limited access here
- $status = self::checkUnblockSelf( $this->target, $user );
- if ( $status !== true ) {
- throw new ErrorPageError( 'badaccess', $status );
- }
-
- $this->setHeaders();
- $this->outputHeader();
-
- $out = $this->getOutput();
- $out->setPageTitle( $this->msg( 'blockip-title' ) );
- $out->addModules( array( 'mediawiki.special', 'mediawiki.special.block' ) );
-
- $fields = $this->getFormFields();
- $this->maybeAlterFormDefaults( $fields );
-
- $form = new HTMLForm( $fields, $this->getContext() );
- $form->setWrapperLegend( wfMsg( 'blockip-legend' ) );
+ /**
+ * Customizes the HTMLForm a bit
+ *
+ * @param $form HTMLForm
+ */
+ protected function alterForm( HTMLForm $form ) {
+ $form->setWrapperLegendMsg( 'blockip-legend' );
+ $form->setHeaderText( '' );
$form->setSubmitCallback( array( __CLASS__, 'processUIForm' ) );
- $t = $this->alreadyBlocked
- ? wfMsg( 'ipb-change-block' )
- : wfMsg( 'ipbsubmit' );
- $form->setSubmitText( $t );
+ $msg = $this->alreadyBlocked ? 'ipb-change-block' : 'ipbsubmit';
+ $form->setSubmitTextMsg( $msg );
- $this->doPreText( $form );
- $this->doHeadertext( $form );
- $this->doPostText( $form );
-
- if( $form->show() ){
- $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
- $out->addWikiMsg( 'blockipsuccesstext', $this->target );
+ # Don't need to do anything if the form has been posted
+ if( !$this->getRequest()->wasPosted() && $this->preErrors ){
+ $s = HTMLForm::formatErrors( $this->preErrors );
+ if( $s ){
+ $form->addHeaderText( Html::rawElement(
+ 'div',
+ array( 'class' => 'error' ),
+ $s
+ ) );
+ }
}
}
'required' => true,
'tabindex' => '2',
'options' => self::getSuggestedDurations(),
- 'other' => wfMsg( 'ipbother' ),
+ 'other' => $this->msg( 'ipbother' )->text(),
),
'Reason' => array(
'type' => 'selectandother',
'label-message' => 'ipb-confirm',
);
+ $this->maybeAlterFormDefaults( $a );
+
return $a;
}
/**
* 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 &$fields Array HTMLForm descriptor array
+ * @param $fields Array HTMLForm descriptor array
* @return Bool whether fields were altered (that is, whether the target is
* already blocked)
*/
}
$this->alreadyBlocked = true;
- $this->preErrors[] = array( 'ipb-needreblock', (string)$block->getTarget() );
+ $this->preErrors[] = array( 'ipb-needreblock', wfEscapeWikiText( (string)$block->getTarget() ) );
}
# We always need confirmation to do HideUser
/**
* Add header elements like block log entries, etc.
- * @param $form HTMLForm
- * @return void
+ * @return String
*/
- protected function doPreText( HTMLForm &$form ){
- $form->addPreText( wfMsgExt( 'blockiptext', 'parse' ) );
+ protected function preText(){
+ $text = $this->msg( 'blockiptext' )->parse();
$otherBlockMessages = array();
if( $this->target !== null ) {
$s = Html::rawElement(
'h2',
array(),
- wfMsgExt( 'ipb-otherblocks-header', 'parseinline', count( $otherBlockMessages ) )
+ $this->msg( 'ipb-otherblocks-header', count( $otherBlockMessages ) )->parse()
) . "\n";
$list = '';
$list
) . "\n";
- $form->addPreText( $s );
+ $text .= $s;
}
}
- }
- /**
- * Add header text inside the form, just underneath where the errors would go
- * @param $form HTMLForm
- * @return void
- */
- protected function doHeaderText( HTMLForm &$form ){
- # Don't need to do anything if the form has been posted
- if( !$this->getRequest()->wasPosted() && $this->preErrors ){
- $s = HTMLForm::formatErrors( $this->preErrors );
- if( $s ){
- $form->addHeaderText( Html::rawElement(
- 'div',
- array( 'class' => 'error' ),
- $s
- ) );
- }
- }
+ return $text;
}
/**
* Add footer elements to the form
- * @param $form HTMLForm
- * @return void
+ * @return string
*/
- protected function doPostText( HTMLForm &$form ){
+ protected function postText(){
# Link to the user's contributions, if applicable
if( $this->target instanceof User ){
$contribsPage = SpecialPage::getTitleFor( 'Contributions', $this->target->getName() );
$links[] = Linker::link(
$contribsPage,
- wfMsgExt( 'ipb-blocklist-contribs', 'escape', $this->target->getName() )
+ $this->msg( 'ipb-blocklist-contribs', $this->target->getName() )->escaped()
);
}
# Link to unblock the specified user, or to a blank unblock form
if( $this->target instanceof User ) {
- $message = wfMsgExt( 'ipb-unblock-addr', array( 'parseinline' ), $this->target->getName() );
+ $message = $this->msg( 'ipb-unblock-addr', wfEscapeWikiText( $this->target->getName() ) )->parse();
$list = SpecialPage::getTitleFor( 'Unblock', $this->target->getName() );
} else {
- $message = wfMsgExt( 'ipb-unblock', array( 'parseinline' ) );
+ $message = $this->msg( 'ipb-unblock' )->parse();
$list = SpecialPage::getTitleFor( 'Unblock' );
}
$links[] = Linker::linkKnown( $list, $message, array() );
# Link to the block list
$links[] = Linker::linkKnown(
SpecialPage::getTitleFor( 'BlockList' ),
- wfMsg( 'ipb-blocklist' )
+ $this->msg( 'ipb-blocklist' )->escaped()
);
$user = $this->getUser();
if ( $user->isAllowed( 'editinterface' ) ) {
$links[] = Linker::link(
Title::makeTitle( NS_MEDIAWIKI, 'Ipbreason-dropdown' ),
- wfMsgHtml( 'ipb-edit-dropdown' ),
+ $this->msg( 'ipb-edit-dropdown' )->escaped(),
array(),
array( 'action' => 'edit' )
);
}
- $form->addPostText( Html::rawElement(
+ $text = Html::rawElement(
'p',
array( 'class' => 'mw-ipb-conveniencelinks' ),
- $this->getLang()->pipeList( $links )
- ) );
+ $this->getLanguage()->pipeList( $links )
+ );
- if( $this->target instanceof User ){
+ $userTitle = self::getTargetUserTitle( $this->target );
+ if( $userTitle ){
# Get relevant extracts from the block and suppression logs, if possible
- $userpage = $this->target->getUserPage();
$out = '';
LogEventsList::showLogExtract(
$out,
'block',
- $userpage,
+ $userTitle,
'',
array(
'lim' => 10,
- 'msgKey' => array( 'blocklog-showlog', $userpage->getText() ),
+ 'msgKey' => array( 'blocklog-showlog', $userTitle->getText() ),
'showIfEmpty' => false
)
);
- $form->addPostText( $out );
+ $text .= $out;
# Add suppression block entries if allowed
if( $user->isAllowed( 'suppressionlog' ) ) {
LogEventsList::showLogExtract(
$out,
'suppress',
- $userpage,
+ $userTitle,
'',
array(
'lim' => 10,
'conds' => array( 'log_action' => array( 'block', 'reblock', 'unblock' ) ),
- 'msgKey' => array( 'blocklog-showsuppresslog', $userpage->getText() ),
+ 'msgKey' => array( 'blocklog-showsuppresslog', $userTitle->getText() ),
'showIfEmpty' => false
)
);
- $form->addPostText( $out );
+ $text .= $out;
}
}
+
+ return $text;
+ }
+
+ /**
+ * Get a user page target for things like logs.
+ * This handles account and IP range targets.
+ * @param $target User|string
+ * @return Title|null
+ */
+ protected static function getTargetUserTitle( $target ) {
+ if( $target instanceof User ) {
+ return $target->getUserPage();
+ } elseif ( IP::isIPAddress( $target ) ) {
+ return Title::makeTitleSafe( NS_USER, $target );
+ }
+ return null;
}
/**
* @since 1.18
* @param $value String
* @param $alldata Array
+ * @param $form HTMLForm
* @return Message
*/
public static function validateTargetField( $value, $alldata, $form ) {
/**
* Submit callback for an HTMLForm object, will simply pass
+ * @param $data array
+ * @param $form HTMLForm
+ * @return Bool|String
*/
public static function processUIForm( array $data, HTMLForm $form ) {
return self::processForm( $data, $form->getContext() );
/**
* Given the form data, actually implement a block
* @param $data Array
+ * @param $context IContextSource
* @return Bool|String
*/
public static function processForm( array $data, IContextSource $context ){
# Give admins a heads-up before they go and block themselves. Much messier
# to do this for IPs, but it's pretty unlikely they'd ever get the 'block'
- # permission anyway, although the code does allow for it
+ # permission anyway, although the code does allow for it.
+ # Note: Important to use $target instead of $data['Target']
+ # since both $data['PreviousTarget'] and $target are normalized
+ # but $data['target'] gets overriden by (non-normalized) request variable
+ # from previous request.
if( $target === $performer->getName() &&
- ( $data['PreviousTarget'] !== $data['Target'] || !$data['Confirm'] ) )
+ ( $data['PreviousTarget'] !== $target || !$data['Confirm'] ) )
{
return array( 'ipb-blockingself' );
}
return implode( ',', $flags );
}
+
+ /**
+ * 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
+ */
+ public function onSubmit( array $data ) {
+ // This isn't used since we need that HTMLForm that's passed in the
+ // second parameter. See alterForm for the real function
+ }
+
+ /**
+ * Do something exciting on successful processing of the form, most likely to show a
+ * confirmation message
+ */
+ public function onSuccess() {
+ $out = $this->getOutput();
+ $out->setPageTitle( $this->msg( 'blockipsuccesssub' ) );
+ $out->addWikiMsg( 'blockipsuccesstext', wfEscapeWikiText( $this->target ) );
+ }
}
# BC @since 1.18