From: Gergő Tisza Date: Thu, 2 Jun 2016 14:17:13 +0000 (+0000) Subject: Improve HTMLForm (and Special:ChangeCredentials) cancel button X-Git-Tag: 1.31.0-rc.0~6725^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22suivi_revisions%22%29%20.%20%22?a=commitdiff_plain;h=0c9712c31a7202be8c983a01a7077e4ab5a6dd1d;p=lhc%2Fweb%2Fwiklou.git Improve HTMLForm (and Special:ChangeCredentials) cancel button Add two new HTMLForm methods: * showCancel( [bool] ) to display a cancel button * setCancelTarget( Title|string ) to set where it should take the user. The cancel button is a simple link formatted as a button. This is faster than a real button (skips an unnecessary submit and redirect) and avoids some UX problems: * when clicking on a real button, HTML5 or JS validators might prevent submission, which does not make sense for cancel * form field values might get saved by the brower, which again does not make sense for cancelling Use the cancel button for Special:ChangeCredentials. Bug: T136809 Change-Id: Ieb80e2ff36751abc6f00e2a02926fe9800666a8b --- diff --git a/includes/htmlform/HTMLForm.php b/includes/htmlform/HTMLForm.php index de3e0ae32f..f07371793e 100644 --- a/includes/htmlform/HTMLForm.php +++ b/includes/htmlform/HTMLForm.php @@ -169,6 +169,8 @@ class HTMLForm extends ContextSource { protected $mShowReset = false; protected $mShowSubmit = true; protected $mSubmitFlags = [ 'constructive', 'primary' ]; + protected $mShowCancel = false; + protected $mCancelTarget; protected $mSubmitCallback; protected $mValidationErrorMessage; @@ -1108,6 +1110,22 @@ class HTMLForm extends ContextSource { ) . "\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