From 0c9712c31a7202be8c983a01a7077e4ab5a6dd1d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerg=C5=91=20Tisza?= Date: Thu, 2 Jun 2016 14:17:13 +0000 Subject: [PATCH] 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 --- includes/htmlform/HTMLForm.php | 40 +++++++++++++++++++ includes/htmlform/OOUIHTMLForm.php | 11 +++++ includes/htmlform/VFormHTMLForm.php | 16 ++++++++ .../specials/SpecialChangeCredentials.php | 12 +----- languages/i18n/en.json | 2 - languages/i18n/qqq.json | 2 - 6 files changed, 68 insertions(+), 15 deletions(-) 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