Bury the reset preferences link

* Move the reset preferences link from the bottom of the preferences
  form to the "basic information" section.
* Change the link from "destructive" red to default styling, since the
  action requires confirmation so there is no reason to make the user be
  afraid of clicking it by accident.
* Add a checkbox to the /reset form, for triple confirmation.
* Add a cancel button to the /reset form, to take the user back to
  safety.
* Allow checkboxes to be "required" by fixing a detail in
  HTMLFormField::validate(). The UI is not pretty, but it works.

Bug: T226325
Change-Id: I116d5275ba1a5beaaa44b32b8eff5824e94b437a
This commit is contained in:
Tim Starling 2022-05-10 15:18:17 +10:00
parent 63c77060a0
commit d36ea62c20
8 changed files with 38 additions and 35 deletions

View file

@ -401,7 +401,7 @@ abstract class HTMLFormField {
if ( isset( $this->mParams['required'] )
&& $this->mParams['required'] !== false
&& $value === ''
&& ( $value === '' || $value === false )
) {
return $this->msg( 'htmlform-required' );
}

View file

@ -552,7 +552,7 @@ class DefaultPreferencesFactory implements PreferencesFactory {
'type' => 'info',
'raw' => true,
'label-message' => 'prefs-user-downloaddata-label',
'default' => HTML::Element(
'default' => Html::element(
'a',
[
'href' => $this->options->get( MainConfigNames::ScriptPath ) .
@ -564,6 +564,21 @@ class DefaultPreferencesFactory implements PreferencesFactory {
'section' => 'personal/info',
];
$defaultPreferences['restoreprefs'] = [
'type' => 'info',
'raw' => true,
'label-message' => 'prefs-user-restoreprefs-label',
'default' => Html::element(
'a',
[
'href' => SpecialPage::getTitleFor( 'Preferences' )
->getSubpage( 'reset' )->getLocalURL()
],
$context->msg( 'prefs-user-restoreprefs-info' )->text()
),
'section' => 'personal/info',
];
$languages = $this->languageNameUtils->getLanguageNames(
LanguageNameUtils::AUTONYMS,
LanguageNameUtils::SUPPORTED

View file

@ -142,11 +142,21 @@ class SpecialPreferences extends SpecialPage {
$context = new DerivativeContext( $this->getContext() );
$context->setTitle( $this->getPageTitle( 'reset' ) ); // Reset subpage
HTMLForm::factory( 'ooui', [], $context, 'prefs-restore' )
$desc = [
'confirm' => [
'type' => 'check',
'label-message' => 'prefs-reset-confirm',
'required' => true,
],
];
// TODO: disable the submit button if the checkbox is not checked
HTMLForm::factory( 'ooui', $desc, $context, 'prefs-restore' )
->setSubmitTextMsg( 'restoreprefs' )
->setSubmitDestructive()
->setSubmitCallback( [ $this, 'submitReset' ] )
->suppressReset()
->showCancel()
->setCancelTarget( $this->getPageTitle() )
->show();
}

View file

@ -114,17 +114,6 @@ class PreferencesFormOOUI extends OOUIHTMLForm {
$html = parent::getButtons();
if ( $this->areOptionsEditable() ) {
$t = $this->getTitle()->getSubpage( 'reset' );
$html .= new OOUI\ButtonWidget( [
'infusable' => true,
'id' => 'mw-prefs-restoreprefs',
'label' => $this->msg( 'restoreprefs' )->text(),
'href' => $t->getLinkURL(),
'flags' => [ 'destructive' ],
'framed' => false,
] );
$html = Xml::tags( 'div', [ 'class' => 'mw-prefs-buttons' ], $html );
}

View file

@ -1098,7 +1098,7 @@
"prefs-rendering": "Appearance",
"prefs-searchmisc": "General",
"saveprefs": "Save",
"restoreprefs": "Restore all default settings (in all sections)",
"restoreprefs": "Restore all default settings",
"prefs-editing": "Editing",
"searchresultshead": "Search",
"recentchangesdays": "Days to show in recent changes:",
@ -1107,9 +1107,11 @@
"prefs-help-recentchangescount": "Maximum number: 1000",
"prefs-help-watchlist-token2": "This is the secret key to the web feed of your watchlist.\nAnyone who knows it will be able to read your watchlist, so do not share it.\nIf you need to, [[Special:ResetTokens|you can reset it]].",
"prefs-help-tokenmanagement": "You can see and reset the secret key for your account that can access the Web feed of your watchlist. Anyone who knows the key will be able to read your watchlist, so do not share it.",
"prefs-user-downloaddata-label": "Account data:",
"prefs-user-downloaddata-label": "Access account data:",
"prefs-user-downloaddata-info": "My account data from this project",
"prefs-user-downloaddata-help-message": "",
"prefs-user-restoreprefs-label": "Delete account data:",
"prefs-user-restoreprefs-info": "Restore all default preferences (in all sections)",
"savedprefs": "Your preferences have been saved.",
"savedrights": "The user groups of {{GENDER:$1|$1}} have been saved.",
"timezonelegend": "Time zone:",
@ -1141,6 +1143,7 @@
"prefs-custom-js": "Custom JavaScript",
"prefs-common-config": "Shared CSS/JSON/JavaScript for all skins:",
"prefs-reset-intro": "You can use this page to reset your preferences to the site defaults.\nThis cannot be undone.",
"prefs-reset-confirm": "Yes, I want to reset my preferences.",
"prefs-emailconfirm-label": "Email confirmation:",
"youremail": "Email:",
"username": "{{GENDER:$1|Username}}:",

View file

@ -1333,7 +1333,7 @@
"prefs-rendering": "Title of tab in [[Special:Preferences]].\n{{Identical|Appearance}}",
"prefs-searchmisc": "Title of general search options section in search tab",
"saveprefs": "Button for saving changes in the preferences page.\n\nSee also:\n* {{msg-mw|Saveprefs}}\n* {{msg-mw|Accesskey-preferences-save}}\n* {{msg-mw|Tooltip-preferences-save}}\n{{Identical|Save}}",
"restoreprefs": "Used as link text in [[Special:Preferences]]. The link points to [[Special:Preferences/reset]] which shows the \"Restore all default settings\" form.\n\nAlso used as label for the Submit button in [[Special:Preferences/reset]].",
"restoreprefs": "Used as label for the Submit button in [[Special:Preferences/reset]].",
"prefs-editing": "Title of a tab in [[Special:Preferences]].\n{{Identical|Editing}}",
"searchresultshead": "Replaced by {{msg-mw|prefs-searchoptions}}, though may still be used in some extensions. DEPRECATED.\n\n{{Identical|Search}}",
"recentchangesdays": "Used in [[Special:Preferences]], tab \"Recent changes\".",
@ -1345,6 +1345,8 @@
"prefs-user-downloaddata-label": "Used in [[Special:Preferences]], tab \"User profile\".",
"prefs-user-downloaddata-info": "This message shows where to view the user's data from this wiki",
"prefs-user-downloaddata-help-message": "Used in [[Special:Preferences]], optional message for user data download help.\n* $1 - The username with spaces replaced by underscores, for including in links",
"prefs-user-restoreprefs-label": "Used as a label introducing the link to [[Special:Preferences/reset]]",
"prefs-user-restoreprefs-info": "Used as link text to link to [[Special:Preferences/reset]]",
"savedprefs": "This message appears after saving changes to your user preferences.",
"savedrights": "This message appears after saving the user groups on [[Special:UserRights]].\n* $1 - The username of the user which groups was saved.",
"timezonelegend": "{{Identical|Time zone}}",
@ -1376,6 +1378,7 @@
"prefs-custom-js": "visible on [[Special:Preferences]] -[Skins].\n{{Identical|Custom JavaScript}}",
"prefs-common-config": "Used as label in [[Special:Preferences#mw-prefsection-rendering|preferences]], tab \"Appearance\", section \"Skin\".\n\nSee also:\n* {{msg-mw|Globalcssjs-custom-css-js}}",
"prefs-reset-intro": "Used in [[Special:Preferences/reset]].",
"prefs-reset-confirm": "Used as a checkbox label on [[Special:Preferences/reset]].",
"prefs-emailconfirm-label": "Sub-heading in [[Special:Preferences]] > {{int:prefs-personal}} > {{int:email}}.",
"youremail": "Label of the e-mail text box of the \"E-mail options\" section of [[Special:Preferences]].\nAlso used on create account form.\n\n{{Identical|E-mail}}",
"username": "Username field in [[Special:Preferences]]. $1 is the current username for GENDER distinction (depends on grammatical gender setting).\n\n{{Identical|Username}}",

View file

@ -4,7 +4,7 @@
*/
( function () {
$( function () {
var allowCloseWindow, saveButton, restoreButton;
var allowCloseWindow, saveButton;
// Check if all of the form values are unchanged.
// (This function could be changed to infuse and check OOUI widgets, but that would only make it
@ -46,7 +46,6 @@
}
saveButton = OO.ui.infuse( $( '#prefcontrol' ) );
restoreButton = OO.ui.infuse( $( '#mw-prefs-restoreprefs' ) );
// Disable the button to save preferences unless preferences have changed
// Check if preferences have been changed before JS has finished loading
@ -70,11 +69,5 @@
test: isPrefsChanged
} );
$( '#mw-prefs-form' ).on( 'submit', allowCloseWindow.release );
restoreButton.on( 'click', function () {
allowCloseWindow.release();
// The default behavior of events in OOUI is always prevented. Follow the link manually.
// Note that middle-click etc. still works, as it doesn't emit a OOUI 'click' event.
location.href = restoreButton.getHref();
} );
} );
}() );

View file

@ -49,19 +49,9 @@
/* This is needed because add extra buttons in a weird way */
.mw-prefs-buttons .mw-htmlform-submit-buttons {
display: inline;
margin: 0;
}
// This button has a very long label, allow wrapping for mobile (T227131)
#mw-prefs-restoreprefs .oo-ui-buttonElement-button {
white-space: normal;
}
#prefcontrol {
margin-right: 0.5em;
}
/*
* Hide, when not keyboard focussed.
*/