Vector: Move 'editwarning' feature from Vector extension
authorrahul21 <rahul14m93@gmail.com>
Sun, 31 Mar 2013 21:55:52 +0000 (03:25 +0530)
committerTimo Tijhof <krinklemail@gmail.com>
Wed, 10 Apr 2013 18:40:08 +0000 (20:40 +0200)
* Created a new Resource Loader module
* Created an entry for the RL module in the Resources.php
* Added messages to languages/MessagesEn.php and languages/MessagesQqq.php
* Called the new RL module from the EditPage.php
* Added required entries in the messages.inc, DefaultSettings.php

Corresponding change in the Vector extension: I164f17255bc927

Bug: 46514
Change-Id: I7bdbd09f4083ccb316156307400ccfacdfec79e1

RELEASE-NOTES-1.22
includes/DefaultSettings.php
includes/EditPage.php
includes/Preferences.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc
resources/Resources.php
resources/mediawiki.action/mediawiki.action.edit.editWarning.js [new file with mode: 0644]

index 06947e1..c24cd7d 100644 (file)
@@ -16,6 +16,11 @@ production.
 * (bug 44525) mediawiki.jqueryMsg can now parse (whitelisted) HTML elements and attributes.
 * (bug 33454) Language::sprintfDate now has a timezone parameter, and supports
   the "eIOPTZ" formatting characters.
+* EditWarning: A warning is shown when an editor leaves the edit form without
+  saving (enabled by default, users can opt-out via the 'useeditwarning'
+  preference). This feature was moved from the Vector extension, and is now part
+  of core for all skins. Take care when upgrading that you don't use an older
+  version of the Vector extension as this feature may conflict.
 
 === Bug fixes in 1.22 ===
 
index 53df457..7b6e9a7 100644 (file)
@@ -3693,6 +3693,7 @@ $wgDefaultUserOptions = array(
        'watchlisthidepatrolled' => 0,
        'watchmoves' => 0,
        'wllimit' => 250,
+       'useeditwarning' => 1,
 );
 
 /** An array of preferences to not show for the user */
index 96a57b4..86a7a77 100644 (file)
@@ -1890,6 +1890,11 @@ class EditPage {
                if ( $wgUser->getOption( 'uselivepreview', false ) ) {
                        $wgOut->addModules( 'mediawiki.action.edit.preview' );
                }
+
+               if ( $wgUser->getOption( 'useeditwarning', false ) ) {
+                       $wgOut->addModules( 'mediawiki.action.edit.editWarning' );
+               }
+
                // Bug #19334: textarea jumps when editing articles in IE8
                $wgOut->addStyle( 'common/IE80Fixes.css', 'screen', 'IE 8' );
 
index 8edf60a..8766ad3 100644 (file)
@@ -818,6 +818,13 @@ class Preferences {
                        'section' => 'editing/advancedediting',
                        'label-message' => 'tog-uselivepreview',
                );
+
+               $defaultPreferences['useeditwarning'] = array(
+                       'type' => 'toggle',
+                       'section' => 'editing/advancedediting',
+                       'label-message' => 'tog-useeditwarning',
+               );
+
        }
 
        /**
index 500488e..76dba58 100644 (file)
@@ -682,6 +682,7 @@ XHTML id names.
 'tog-showhiddencats'          => 'Show hidden categories',
 'tog-noconvertlink'           => 'Disable link title conversion', # only translate this message to other languages if you have to change it
 'tog-norollbackdiff'          => 'Omit diff after performing a rollback',
+'tog-useeditwarning'             => 'Warn me when I leave an edit page with unsaved changes',
 
 'underline-always'  => 'Always',
 'underline-never'   => 'Never',
@@ -1492,6 +1493,8 @@ It already exists.',
 'content-failed-to-parse'          => 'Failed to parse $2 content for $1 model: $3',
 'invalid-content-data'             => 'Invalid content data',
 'content-not-allowed-here'         => '"$1" content is not allowed on page [[$2]]',
+'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.',
 
 # Content models
 'content-model-wikitext'   => 'wikitext',
index 0abf42e..e003569 100644 (file)
@@ -223,6 +223,7 @@ This option means "underline links as in your user skin or your browser", there
 
 {{Gender}}
 {{Identical|Browser default}}',
+'tog-useeditwarning' => 'Caption of the editwarning preference, displayed on the right side of the checkbox',
 
 # Font style option in Special:Preferences
 'editfont-style' => 'Used in [[Special:Preferences]], tab Editing. {{Gender}}',
@@ -1603,6 +1604,7 @@ See also:
 'content-not-allowed-here' => 'Error message indicating that the desired content model is not supported in given localtion.
 * $1 - the human readable name of the content model: {{msg-mw|Content-model-wikitext}}, {{msg-mw|Content-model-javascript}}, {{msg-mw|Content-model-css}} or {{msg-mw|Content-model-text}}
 * $2 - the title of the page in question',
+'editwarning-warning' => 'Warning message that is displayed when a user moves to an other page without saving his changes',
 
 # Content models
 'content-model-wikitext' => 'Name for the wikitext content model, used when decribing what type of content a page contains.
index 64ffc09..1a0ff8a 100644 (file)
@@ -72,6 +72,7 @@ $wgMessageStructure = array(
                'tog-showhiddencats',
                'tog-noconvertlink',
                'tog-norollbackdiff',
+               'tog-useeditwarning',
        ),
        'underline' => array(
                'underline-always',
@@ -695,6 +696,7 @@ $wgMessageStructure = array(
                'content-failed-to-parse',
                'invalid-content-data',
                'content-not-allowed-here',
+               'editwarning-warning',
        ),
        'contentmodels' => array(
                'content-model-wikitext',
index 0db3e20..5332b26 100644 (file)
@@ -737,6 +737,12 @@ return array(
        'mediawiki.action.view.rightClickEdit' => array(
                'scripts' => 'resources/mediawiki.action/mediawiki.action.view.rightClickEdit.js',
        ),
+       'mediawiki.action.edit.editWarning' => array(
+               'scripts' => 'resources/mediawiki.action/mediawiki.action.edit.editWarning.js',
+               'messages' => array(
+                       'editwarning-warning',
+               ),
+       ),
        // Alias for backwards compatibility
        'mediawiki.action.watch.ajax' => array(
                'dependencies' => 'mediawiki.page.watch.ajax'
diff --git a/resources/mediawiki.action/mediawiki.action.edit.editWarning.js b/resources/mediawiki.action/mediawiki.action.edit.editWarning.js
new file mode 100644 (file)
index 0000000..cfe9762
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Javascript for module editWarning
+ */
+( 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( '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 ) {
+                                       window.onbeforeunload = savedWindowOnBeforeUnload;
+                               }
+                       } );
+
+               // Add form submission handler
+               $( '#editform' ).submit( function () {
+                       // Unbind our handlers
+                       $( window ).off( '.editwarning' );
+               } );
+       } );
+
+}( mediaWiki, jQuery ) );
+