protected $mShowReset = false;
protected $mShowSubmit = true;
protected $mSubmitFlags = [ 'constructive', 'primary' ];
+ protected $mShowCancel = false;
+ protected $mCancelTarget;
protected $mSubmitCallback;
protected $mValidationErrorMessage;
) . "\n";
}
+ if ( $this->mShowCancel ) {
+ $target = $this->mCancelTarget ?: Title::newMainPage();
+ if ( $target instanceof Title ) {
+ $target = $target->getLocalURL();
+ }
+ $buttons .= Html::element(
+ 'a',
+ [
+ 'type' => 'reset',
+ 'class' => $useMediaWikiUIEverywhere ? 'mw-ui-button' : null,
+ 'href' => $target,
+ ],
+ $this->msg( 'cancel' )->text()
+ ) . "\n";
+ }
+
// IE<8 has bugs with <button>, so we'll need to avoid them.
$isBadIE = preg_match( '/MSIE [1-7]\./i', $this->getRequest()->getHeader( 'User-Agent' ) );
return $this;
}
+ /**
+ * Show a cancel button (or prevent it). The button is not shown by default.
+ * @param bool $show
+ * @return HTMLForm $this for chaining calls
+ * @since 1.27
+ */
+ public function showCancel( $show = true ) {
+ $this->mShowCancel = $show;
+ return $this;
+ }
+
+ /**
+ * Sets the target where the user is redirected to after clicking cancel.
+ * @param Title|string $target Target as a Title object or an URL
+ * @return HTMLForm $this for chaining calls
+ * @since 1.27
+ */
+ public function setCancelTarget( $target ) {
+ $this->mCancelTarget = $target;
+ return $this;
+ }
+
/**
* Set the id of the \<table\> or outermost \<div\> element.
*
] );
}
+ if ( $this->mShowCancel ) {
+ $target = $this->mCancelTarget ?: Title::newMainPage();
+ if ( $target instanceof Title ) {
+ $target = $target->getLocalURL();
+ }
+ $buttons .= new OOUI\ButtonWidget( [
+ 'label' => $this->msg( 'cancel' )->text(),
+ 'href' => $target,
+ ] );
+ }
+
foreach ( $this->mButtons as $button ) {
$attrs = [];
) . "\n";
}
+ if ( $this->mShowCancel ) {
+ $target = $this->mCancelTarget ?: Title::newMainPage();
+ if ( $target instanceof Title ) {
+ $target = $target->getLocalURL();
+ }
+ $buttons .= Html::element(
+ 'a',
+ [
+ 'type' => 'reset',
+ 'class' => 'mw-ui-button mw-ui-big mw-ui-block',
+ 'href' => $target,
+ ],
+ $this->msg( 'cancel' )->text()
+ ) . "\n";
+ }
+
foreach ( $this->mButtons as $button ) {
$attrs = [
'type' => 'submit',
return;
}
- if ( $this->getRequest()->getCheck( 'wpCancel' ) ) {
- $returnUrl = $this->getReturnUrl() ?: Title::newMainPage()->getFullURL();
- $this->getOutput()->redirect( $returnUrl );
- return;
- }
-
if ( !$this->authRequests ) {
// messages used: changecredentials-invalidsubpage, removecredentials-invalidsubpage
$this->showSubpageList( $this->msg( static::$messagePrefix . '-invalidsubpage', $subPage ) );
);
// messages used: changecredentials-submit removecredentials-submit
- // changecredentials-submit-cancel removecredentials-submit-cancel
$form->setSubmitTextMsg( static::$messagePrefix . '-submit' );
- $form->addButton( [
- 'name' => 'wpCancel',
- 'value' => $this->msg( static::$messagePrefix . '-submit-cancel' )->text()
- ] );
+ $form->showCancel()->setCancelTarget( $this->getReturnUrl() ?: Title::newMainPage() );
return $form;
}
"cannotauth-not-allowed": "You are not allowed to use this page",
"changecredentials" : "Change credentials",
"changecredentials-submit": "Change credentials",
- "changecredentials-submit-cancel": "Cancel",
"changecredentials-invalidsubpage": "$1 is not a valid credential type.",
"changecredentials-success": "Your credentials have been changed.",
"removecredentials" : "Remove credentials",
"removecredentials-submit": "Remove credentials",
- "removecredentials-submit-cancel": "Cancel",
"removecredentials-invalidsubpage": "$1 is not a valid credential type.",
"removecredentials-success": "Your credentials have been removed.",
"credentialsform-provider": "Credentials type:",
"cannotauth-not-allowed": "Text of the error page shown when the user tries t use an authentication-related page they should not have access to.",
"changecredentials": "Title of the special page [[Special:ChangeCredentials]] which allows changing authentication credentials (such as the password).",
"changecredentials-submit": "Used on [[Special:ChangeCredentials]].",
- "changecredentials-submit-cancel": "Used on [[Special:ChangeCredentials]].\n{{Identical|Cancel}}",
"changecredentials-invalidsubpage": "Error message shown when using [[Special:ChangeCredentials]] with an invalid type.\n\nParameters:\n* $1 - subpage name.",
"changecredentials-success": "Success message after using [[Special:ChangeCredentials]].",
"removecredentials": "Title of the special page [[Special:RemoveCredentials]] which allows removing authentication credentials (such as a two-factor token).",
"removecredentials-submit": "Used on [[Special:RemoveCredentials]].",
- "removecredentials-submit-cancel": "Used on [[Special:RemoveCredentials]].\n{{Identical|Cancel}}",
"removecredentials-invalidsubpage": "Error message shown when using [[Special:RemoveCredentials]] with an invalid type.\n\nParameters:\n* $1 - subpage name.",
"removecredentials-success": "Success message after using [[Special:RemoveCredentials]].",
"credentialsform-provider": "Shown on [[Special:ChangeCredentials]]/[[Special:RemoveCredentials]] as the label for the authentication type (e.g. \"password\", \"English Wikipedia via OAuth\")",