Rahul21 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/56881
Change subject: Merged the 'editwarning' component of Vector extension into the
Vector skin
......................................................................
Merged the 'editwarning' component of Vector extension into the Vector skin
-Added the vector specific script to vector.js
-Made changes in languages/MessagesEn.php to account for the error message and
for the preference.
Bug: 46514
Change-Id: I7bdbd09f4083ccb316156307400ccfacdfec79e1
---
M languages/messages/MessagesEn.php
M skins/vector/vector.js
2 files changed, 59 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/81/56881/1
diff --git a/languages/messages/MessagesEn.php
b/languages/messages/MessagesEn.php
index d3f1327..2e42eae 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -1308,7 +1308,9 @@
'summary-preview' => 'Summary preview:',
'subject-preview' => 'Subject/headline preview:',
'blockedtitle' => 'User is blocked',
-'blockedtext' => "'''Your username or IP address has been
blocked.'''
+'blockedtext' => "'''Your username or IP address has been
blocked.'''",
+'vector-editwarning-warning' => 'Leaving this page may cause you to lose any
changes you have made.
+If you are logged in, you can disable this warning in the "Editing" section of
your preferences.''
The block was made by $1.
The reason given is ''$2''.
@@ -1935,6 +1937,7 @@
'prefs-displaysearchoptions' => 'Display options',
'prefs-displaywatchlist' => 'Display options',
'prefs-diffs' => 'Diffs',
+'vector-editwarning-preference' => 'Warn me when I leave an edit page with
unsaved changes',
# User preference: e-mail validation using jQuery
'email-address-validity-valid' => 'E-mail address appears valid',
diff --git a/skins/vector/vector.js b/skins/vector/vector.js
index 4427d9a..38d481d 100644
--- a/skins/vector/vector.js
+++ b/skins/vector/vector.js
@@ -18,4 +18,58 @@
$el.removeClass( 'vectorMenuFocus' );
} );
} );
-} );
+
+/*
+ * Edit warning for Vector
+ */
+
+ $(document).ready( function () {
+ // Check if EditWarning is enabled and if we need it
+ if ( $( '#wpTextbox1' ).length === 0 ) {
+ return true;
+ }
+ // Get the original values of some form elements
+ $( '#wpTextbox1, #wpSummary' ).each( function () {
+ $(this).data( 'origtext', $(this).val() );
+ });
+ var savedWindowOnBeforeUnload;
+ $( window )
+ .on( 'beforeunload.editwarning', function () {
+ var retval;
+
+ // Check if the current values of some form
elements are the same as
+ // the original values
+ if (
+ mw.config.get( 'wgAction' ) == 'submit'
||
+ $( '#wpTextbox1' ).data(
'origtext' ) != $( '#wpTextbox1' ).val() ||
+ $( '#wpSummary' ).data(
'origtext' ) != $( '#wpSummary' ).val()
+ ) {
+ // Return our message
+ retval = mw.msg(
'vector-editwarning-warning' );
+ }
+
+ // 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.editwarning', function () {
+ // Re-add onbeforeunload handler
+ if ( window.onbeforeunload == null ) {
+ window.onbeforeunload =
savedWindowOnBeforeUnload;
+ }
+ } );
+
+ // Add form submission handler
+ $( '#editform' ).submit( function () {
+ // Unbind our handlers
+ $( window ).off( '.editwarning' );
+ });
+ });
+});
--
To view, visit https://gerrit.wikimedia.org/r/56881
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7bdbd09f4083ccb316156307400ccfacdfec79e1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Rahul21 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits