*/
function getButtons() {
global $wgUseMediaWikiUIEverywhere;
- $attrs = $wgUseMediaWikiUIEverywhere ? array( 'class' => 'mw-ui-button mw-ui-quiet' ) : array();
+
+ $attrs = array( 'id' => 'mw-prefs-restoreprefs' );
+ if ( $wgUseMediaWikiUIEverywhere ) {
+ $attrs['class'] = 'mw-ui-button mw-ui-quiet';
+ }
if ( !$this->getModifiedUser()->isAllowedAny( 'editmyprivateinfo', 'editmyoptions' ) ) {
return '';
"prefs-tokenwatchlist": "Token",
"prefs-diffs": "Diffs",
"prefs-help-prefershttps": "This preference will take effect on your next login.",
+ "prefswarning-warning": "You've made changes to your preferences that have not been saved yet.\nIf you leave this page without clicking \"$1\" your preferences will not be updated.",
"prefs-tabs-navigation-hint": "Tip: You can use the left and right arrow keys to navigate between the tabs in the tabs list.",
"email-address-validity-valid": "Email address appears valid",
"email-address-validity-invalid": "Enter a valid email address",
"prefs-tokenwatchlist": "Section heading.\nUsed in [[Special:Preferences]], tab \"Watchlist\".\n{{Identical|Token}}",
"prefs-diffs": "Used in [[Special:Preferences]], tab \"Misc\".",
"prefs-help-prefershttps": "Used as help text for the checkbox in [[Special:Preferences]].\n\nThe checkbox has the label {{msg-mw|Tog-prefershttps}}.\n\nSee example: [[mw:Special:Preferences]].",
+ "prefswarning-warning": "Warning shown (except in Firefox) when attempting to leave [[Special:Preferences]] with unsaved changes.\n\nParameters:\n* $1 - Text of {{msg-mw|saveprefs}}, as <nowiki>{{int:saveprefs}}</nowiki> cannot be used directly.",
"prefs-tabs-navigation-hint": "Hint message that explains the arrow key navigation for the tabs on [[Special:Preferences]] to screenreader users.",
"email-address-validity-valid": "Used as hint for {{msg-mw|changeemail-newemail}} field in [[Special:ChangeEmail]], when the provided E-mail address is valid.",
"email-address-validity-invalid": "Used as warning for {{msg-mw|changeemail-newemail}} field in [[Special:ChangeEmail]], when the provided E-mail address is invalid.",
var $preftoc, $preferences, $fieldsets, $legends,
hash, labelFunc,
$tzSelect, $tzTextbox, $localtimeHolder, servertime,
- $checkBoxes;
+ $checkBoxes, savedWindowOnBeforeUnload;
labelFunc = function () {
return this.id.replace( /^mw-prefsection/g, 'preftab' );
$( '#mw-input-wpsearcheverything' ).change( function () {
$checkBoxes.prop( 'disabled', $( this ).prop( 'checked' ) );
} );
+
+ // Set up a message to notify users if they try to leave the page without
+ // saving.
+ $( '#mw-prefs-form' ).data( 'origdata', $( '#mw-prefs-form' ).serialize() );
+ $( window )
+ .on( 'beforeunload.prefswarning', function () {
+ var retval;
+
+ // Check if anything changed
+ if ( $( '#mw-prefs-form' ).serialize() !== $( '#mw-prefs-form' ).data( 'origdata' ) ) {
+ // Return our message
+ retval = mediaWiki.msg( 'prefswarning-warning', mediaWiki.msg( 'saveprefs' ) );
+ }
+
+ // Unset the onbeforeunload handler so we don't break page caching in Firefox
+ savedWindowOnBeforeUnload = window.onbeforeunload;
+ window.onbeforeunload = null;
+ if ( retval !== undefined ) {
+ // ...but if the user chooses not to leave the page, we need to rebind it
+ setTimeout( function () {
+ window.onbeforeunload = savedWindowOnBeforeUnload;
+ }, 1 );
+ return retval;
+ }
+ } )
+ .on( 'pageshow.prefswarning', function () {
+ // Re-add onbeforeunload handler
+ if ( !window.onbeforeunload ) {
+ window.onbeforeunload = savedWindowOnBeforeUnload;
+ }
+ } );
+ $( '#mw-prefs-form' ).submit( function () {
+ // Unbind our beforeunload handler
+ $( window ).off( '.prefswarning' );
+ } );
+ $( '#mw-prefs-restoreprefs' ).click( function () {
+ // Unbind our beforeunload handler
+ $( window ).off( '.prefswarning' );
+ } );
} );