Preferences: Fix issues from 6d3c65b5b0
authorGeoffrey Mon <geofbot@gmail.com>
Sun, 2 Aug 2015 00:03:57 +0000 (00:03 +0000)
committerSn1per <geofbot@gmail.com>
Thu, 3 Sep 2015 21:45:21 +0000 (21:45 +0000)
* Use .mw-preferences-messagebox instead of .successbox to
  avoid conflicts with other Special pages using '.successbox'
  as a class and so that the new class can be used to check
  for messages to replace with notifications
* Add logic to check for messages to replace using the new
  aforementioned class
* Use Html::rawElement and Html::element instead of Xml::tags
  to add the non-JS successbox
* Re-added <p> tags around non-JS successbox message that were
  accidentally ommitted in the original patch

Bug: T19496
Change-Id: I990667aa114d8201516bee6cb2ad22994de53c6c

includes/specials/SpecialPreferences.php
resources/src/mediawiki.special/mediawiki.special.preferences.css
resources/src/mediawiki.special/mediawiki.special.preferences.js

index f2a315e..4b75e5f 100644 (file)
@@ -50,10 +50,13 @@ class SpecialPreferences extends SpecialPage {
 
                if ( $this->getRequest()->getCheck( 'success' ) ) {
                        $out->wrapWikiMsg(
-                               Xml::tags(
+                               Html::rawElement(
                                        'div',
-                                       array( 'class' => 'successbox', 'id' => 'mw-preferences-success' ),
-                                       '$1'
+                                       array(
+                                               'class' => 'mw-preferences-messagebox successbox',
+                                               'id' => 'mw-preferences-success'
+                                       ),
+                                       Html::element( 'p', array(), '$1' )
                                ),
                                'savedprefs'
                        );
index 0e71d30..8fb9a47 100644 (file)
@@ -20,7 +20,7 @@
        zoom: 1;
 }
 
-/* When JS is enabled, .successbox is replaced with a mw.notification */
-.successbox {
+/* When JS is enabled, .mw-preferences-messageboxes are replaced with mw.notifications */
+.mw-preferences-messagebox {
        display: none;
 }
index 893db98..7f13f29 100644 (file)
@@ -1,4 +1,3 @@
-
 /*!
  * JavaScript for Special:Preferences
  */
@@ -86,18 +85,23 @@ jQuery( function ( $ ) {
                }
        }
 
-       // If there is a #mw-preferences-success box and javascript is enabled, use a slick notification instead!
-       if ( $( '#mw-preferences-success' ).length ) {
-               notif = mediaWiki.notification.notify( mediaWiki.message( 'savedprefs' ), { autoHide: false } );
-               $( '#preftoc, .prefsection' ).one( 'change keydown mousedown', function () { // 'change' event not reliable!
-                       if ( notif ) {
-                               notif.close();
-                       }
-               } );
+       // Check for messageboxes (.successbox, .warningbox, .errorbox) to replace with notifications
+       if ( $( '.mw-preferences-messagebox' ).length ) {
+               // If there is a #mw-preferences-success box and javascript is enabled, use a slick notification instead!
+               if ( $( '#mw-preferences-success' ).length ) {
+                       notif = mediaWiki.notification.notify( mediaWiki.message( 'savedprefs' ), { autoHide: false } );
+                       // 'change' event not reliable!
+                       $( '#preftoc, .prefsection' ).one( 'change keydown mousedown', function () {
+                               if ( notif ) {
+                                       notif.close();
+                                       notif = null;
+                               }
+                       } );
 
-               // Remove now-unnecessary success=1 querystring to prevent reappearance of notification on reload
-               if ( history.replaceState ) {
-                       history.replaceState( {}, document.title, document.URL.replace( /&?success=1/, '' ) );
+                       // Remove now-unnecessary success=1 querystring to prevent reappearance of notification on reload
+                       if ( history.replaceState ) {
+                               history.replaceState( {}, document.title, location.href.replace( /&?success=1/, '' ) );
+                       }
                }
        }