jenkins-bot has submitted this change and it was merged.

Change subject: Vector: Move 'editwarning' feature from Vector extension
......................................................................


Vector: Move 'editwarning' feature from Vector extension

* 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
---
M RELEASE-NOTES-1.22
M includes/DefaultSettings.php
M includes/EditPage.php
M includes/Preferences.php
M languages/messages/MessagesEn.php
M languages/messages/MessagesQqq.php
M maintenance/language/messages.inc
M resources/Resources.php
A resources/mediawiki.action/mediawiki.action.edit.editWarning.js
9 files changed, 87 insertions(+), 0 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 06947e1..c24cd7d 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -16,6 +16,11 @@
 * (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 ===
 
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index 53df457..7b6e9a7 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -3693,6 +3693,7 @@
        'watchlisthidepatrolled' => 0,
        'watchmoves' => 0,
        'wllimit' => 250,
+       'useeditwarning' => 1,
 );
 
 /** An array of preferences to not show for the user */
diff --git a/includes/EditPage.php b/includes/EditPage.php
index 96a57b4..86a7a77 100644
--- a/includes/EditPage.php
+++ b/includes/EditPage.php
@@ -1890,6 +1890,11 @@
                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' );
 
diff --git a/includes/Preferences.php b/includes/Preferences.php
index 8edf60a..8766ad3 100644
--- a/includes/Preferences.php
+++ b/includes/Preferences.php
@@ -818,6 +818,13 @@
                        'section' => 'editing/advancedediting',
                        'label-message' => 'tog-uselivepreview',
                );
+
+               $defaultPreferences['useeditwarning'] = array(
+                       'type' => 'toggle',
+                       'section' => 'editing/advancedediting',
+                       'label-message' => 'tog-useeditwarning',
+               );
+
        }
 
        /**
diff --git a/languages/messages/MessagesEn.php 
b/languages/messages/MessagesEn.php
index 500488e..76dba58 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -682,6 +682,7 @@
 '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 @@
 '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',
diff --git a/languages/messages/MessagesQqq.php 
b/languages/messages/MessagesQqq.php
index 0abf42e..e003569 100644
--- a/languages/messages/MessagesQqq.php
+++ b/languages/messages/MessagesQqq.php
@@ -223,6 +223,7 @@
 
 {{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 @@
 '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.
diff --git a/maintenance/language/messages.inc 
b/maintenance/language/messages.inc
index 64ffc09..1a0ff8a 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -72,6 +72,7 @@
                'tog-showhiddencats',
                'tog-noconvertlink',
                'tog-norollbackdiff',
+               'tog-useeditwarning',
        ),
        'underline' => array(
                'underline-always',
@@ -695,6 +696,7 @@
                'content-failed-to-parse',
                'invalid-content-data',
                'content-not-allowed-here',
+               'editwarning-warning',
        ),
        'contentmodels' => array(
                'content-model-wikitext',
diff --git a/resources/Resources.php b/resources/Resources.php
index 0db3e20..5332b26 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -737,6 +737,12 @@
        '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
index 0000000..cfe9762
--- /dev/null
+++ b/resources/mediawiki.action/mediawiki.action.edit.editWarning.js
@@ -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 ) );
+

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I7bdbd09f4083ccb316156307400ccfacdfec79e1
Gerrit-PatchSet: 21
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Rahul21 <[email protected]>
Gerrit-Reviewer: Alex Monk <[email protected]>
Gerrit-Reviewer: Daniel Friesen <[email protected]>
Gerrit-Reviewer: Isarra <[email protected]>
Gerrit-Reviewer: Krinkle <[email protected]>
Gerrit-Reviewer: Matmarex <[email protected]>
Gerrit-Reviewer: Rahul21 <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to