Alex Monk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/67253


Change subject: Revert "Delete the editWarning feature"
......................................................................

Revert "Delete the editWarning feature"

This reverts commit 233ddc84d82eaba7ae28b2dff747c61adf0a1837.

This commit was done (in master) because the feature was getting added to core, 
but it didn't get into the 1.21 core release, so restore it to Vector REL1_21.

Bug: 49228
Change-Id: I236086380cf7520d156b491661086bfefa0cb129
---
M Vector.hooks.php
M Vector.i18n.php
M Vector.php
A modules/ext.vector.editWarning.js
4 files changed, 79 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Vector 
refs/changes/53/67253/1

diff --git a/Vector.hooks.php b/Vector.hooks.php
index 50cec46..8d28f61 100644
--- a/Vector.hooks.php
+++ b/Vector.hooks.php
@@ -31,6 +31,20 @@
                'collapsibletabs' => array(
                        'modules' => array( 'ext.vector.collapsibleTabs' ),
                ),
+               'editwarning' => array(
+                       'preferences' => array(
+                               // Ideally this would be 'vector-editwarning'
+                               'useeditwarning' => array(
+                                       'type' => 'toggle',
+                                       'label-message' => 
'vector-editwarning-preference',
+                                       'section' => 'editing/advancedediting',
+                               ),
+                       ),
+                       'requirements' => array(
+                               'useeditwarning' => true,
+                       ),
+                       'modules' => array( 'ext.vector.editWarning' ),
+               ),
                'expandablesearch' => array(
                        'requirements' => array( 'vector-simplesearch' => true 
),
                        'modules' => array( 'ext.vector.expandableSearch' ),
diff --git a/Vector.i18n.php b/Vector.i18n.php
index 2c4e4b4..160c387 100644
--- a/Vector.i18n.php
+++ b/Vector.i18n.php
@@ -16,6 +16,9 @@
        'vector-desc' => 'Enhances the user interface when using the Vector 
skin',
        'vector-collapsiblenav-preference' => 'Enable collapsing of items in 
the sidebar in Vector skin',
        'vector-collapsiblenav-more' => 'More languages',
+       '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.',
+       'vector-editwarning-preference' => 'Warn me when I leave an edit page 
with unsaved changes',
        'vector-simplesearch-search' => 'Search',
        'vector-simplesearch-containing' => 'containing...',
        'vector-noexperiments-preference' => 'Exclude me from feature 
experiments',
diff --git a/Vector.php b/Vector.php
index a7e2467..4dc1232 100644
--- a/Vector.php
+++ b/Vector.php
@@ -19,6 +19,7 @@
 $wgVectorFeatures = array(
        'collapsiblenav' => array( 'global' => true, 'user' => true ),
        'collapsibletabs' => array( 'global' => true, 'user' => false ),
+       'editwarning' => array( 'global' => false, 'user' => true ),
        // The follwing are experimental and likely unstable - use at your own 
risk
        'expandablesearch' => array( 'global' => false, 'user' => false ),
        'footercleanup' => array( 'global' => false, 'user' => false ),
@@ -91,6 +92,12 @@
                        'jquery.delayedBind',
                ),
        ),
+       'ext.vector.editWarning' => $vectorResourceTemplate + array(
+               'scripts' => 'ext.vector.editWarning.js',
+               'messages' => array(
+                       'vector-editwarning-warning',
+               ),
+       ),
        'ext.vector.expandableSearch' => $vectorResourceTemplate + array(
                'scripts' => 'ext.vector.expandableSearch.js',
                'styles' => 'ext.vector.expandableSearch.css',
diff --git a/modules/ext.vector.editWarning.js 
b/modules/ext.vector.editWarning.js
new file mode 100644
index 0000000..e128fd4
--- /dev/null
+++ b/modules/ext.vector.editWarning.js
@@ -0,0 +1,55 @@
+/*
+ * Edit warning for Vector
+ */
+( function ( mw, $ ) {
+       $(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' );
+               });
+       });
+
+}( mediaWiki, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/67253
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I236086380cf7520d156b491661086bfefa0cb129
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Vector
Gerrit-Branch: master
Gerrit-Owner: Alex Monk <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to