(bug 35082) addPortletLink incorrectly adds to mutiple <ul> tags
authorTimo Tijhof <ttijhof@wikimedia.org>
Thu, 7 Jun 2012 21:06:49 +0000 (23:06 +0200)
committerTimo Tijhof <ttijhof@wikimedia.org>
Mon, 2 Jul 2012 20:19:29 +0000 (22:19 +0200)
* cleaned up tags <ul> creation (no need to create it and then
  find() it. Might as well grab a hold of it before insertion).

* Fixed bug by adding ".eq( 0 )"

* Added unit test for it
  (which fails without the fix in mediawiki.util.js)

Change-Id: I51e9053292f03c1b833db0df2fb1b40f1eaf8b1a

RELEASE-NOTES-1.20
resources/mediawiki/mediawiki.util.js
tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js

index 3a373ff..798e8de 100644 (file)
@@ -124,9 +124,9 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 35572) Blocks appear to succeed even if query fails due to wrong DB structure
 * (bug 31757) Add a word-separator between help-messages in HTMLForm
 * (bug 30410) Removed deprecated $wgFilterCallback and the 'filtered' API error.
-* (bug 32604) Some messages needs escaping of wikitext inside username
+* (bug 32604) Some messages needs escaping of wikitext inside username.
 * (bug 36537) Rename wfArrayToCGI to wfArrayToCgi for consistency with wfCgiToArray.
-* (bug 25946) The message on the top of Special:RecentChanges is now displayed
+* (bug 25946) The message on the top of Special:RecentChanges is now displayed.
   in user language instead of content language.
 * (bug 35264) Wrong type used for <ns> in export.xsd
 * (bug 24985) Use $wgTmpDirectory as the default temp directory so that people
@@ -138,6 +138,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
   that don't have stylesheets.
 * (bug 36812) Special:ActiveUsers "Hide bots" should hide users from any group
   having the "bot" user right, instead of just the default "bot" user group.
+* (bug 35082) mw.util.addPortletLink incorrectly adds link to mutiple <ul> tags.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index 9202d2e..541c77a 100644 (file)
                                        return null;
                                }
                                // Select the first (most likely only) unordered list inside the portlet
-                               $ul = $portlet.find( 'ul' );
+                               $ul = $portlet.find( 'ul' ).eq( 0 );
 
                                // If it didn't have an unordered list yet, create it
                                if ( $ul.length === 0 ) {
+
+                                       $ul = $( '<ul>' );
+
                                        // If there's no <div> inside, append it to the portlet directly
                                        if ( $portlet.find( 'div:first' ).length === 0 ) {
-                                               $portlet.append( '<ul></ul>' );
+                                               $portlet.append( $ul );
                                        } else {
                                                // otherwise if there's a div (such as div.body or div.pBody)
                                                // append the <ul> to last (most likely only) div
-                                               $portlet.find( 'div' ).eq( -1 ).append( '<ul></ul>' );
+                                               $portlet.find( 'div' ).eq( -1 ).append( $ul );
                                        }
-                                       // Select the created element
-                                       $ul = $portlet.find( 'ul' ).eq( 0 );
                                }
                                // Just in case..
                                if ( $ul.length === 0 ) {
index d396b04..86beb5f 100644 (file)
@@ -141,20 +141,33 @@ test( '$content', function() {
  * one element can have a given id. 
  */
 test( 'addPortletLink', function () {
-       var pTestTb, vectorTabs, tbRL, tbMW, $tbMW, tbRLDM, caFoo;
-       expect(7);
+       var pTestTb, vectorTabs, tbRL, cuQuux, $cuQuux, tbMW, $tbMW, tbRLDM, caFoo;
+       expect( 8 );
 
        pTestTb = '\
        <div class="portlet" id="p-test-tb">\
+               <h5>Toolbox</h5>\
                <ul class="body"></ul>\
        </div>';
+       pCustom = '\
+       <div class="portlet" id="p-test-custom">\
+               <h5>Views</h5>\
+               <ul class="body">\
+                       <li id="c-foo"><a href="#">Foo</a></li>\
+                       <li id="c-barmenu">\
+                               <ul>\
+                                       <li id="c-bar-baz"><a href="#">Baz</a></a>\
+                               </ul>\
+                       </li>\
+               </ul>\
+       </div>';
        vectorTabs = '\
        <div id="p-test-views" class="vectorTabs">\
                <h5>Views</h5>\
                <ul></ul>\
        </div>';
 
-       $('#qunit-fixture').append(pTestTb, vectorTabs);
+       $( '#qunit-fixture' ).append( pTestTb, pCustom, vectorTabs );
 
        tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
                'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' );
@@ -170,6 +183,15 @@ test( 'addPortletLink', function () {
        equal( $tbMW.closest( '.portlet' ).attr( 'id' ), 'p-test-tb', 'Link was inserted within correct portlet' );
        equal( $tbMW.next().attr( 'id' ), 't-rl', 'Link is in the correct position (by passing nextnode)' );
 
+       cuQuux = mw.util.addPortletLink( 'p-test-custom', '#', 'Quux' );
+       $cuQuux = $(cuQuux);
+
+       equal(
+               $( '#p-test-custom #c-barmenu ul li' ).length,
+               1,
+               'addPortletLink did not add the item to all <ul> elements in the portlet (bug 35082)'
+       );
+
        tbRLDM = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/RL/DM',
                'Default modules', 't-rldm', 'List of all default modules ', 'd', '#t-rl' );