Last modified: 2012-06-07 21:07:20 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T37082, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 35082 - mw.util.addPortletLink incorrectly adds link to mutiple <ul> tags
mw.util.addPortletLink incorrectly adds link to mutiple <ul> tags
Status: RESOLVED FIXED
Product: MediaWiki
Classification: Unclassified
JavaScript (Other open bugs)
1.18.x
All All
: Low normal (vote)
: 1.20.0 release
Assigned To: Krinkle
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-03-09 14:10 UTC by Amalthea
Modified: 2012-06-07 21:07 UTC (History)
3 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments

Description Amalthea 2012-03-09 14:10:48 UTC
mediaWiki.util.addPortletLink incorrectly adds the created portlet link to all uw tags in a portlet.

For most skins, addPortletLink uses the following logic to decide where to add the newly created link:

// Select the first (most likely only) unordered list inside the portlet
$ul = $portlet.find( 'ul' );

.find('ul') does of course find /all/ unordered list tags in the portlet element.

This can be problematic for utilities that place further unordered lists in the portlet to create submenus.
While doing that might not be directly supported by MediaWiki, I don't see there's ever a cause to add a portlet link multiple times.
Assuming that the jQuery filter function ".first()" is deterministic and works as I think it does, I assume that changing the aforementioned line to
  $ul = $portlet.find( 'ul' ).first();
would fix the issue without breaking functionality that anybody relies on (or should rely on). Judging by the comment that was the intended behavior in the first place.


Steps to reproduce:
  wgUserGroups.push("sysop"); //to convince easyblock to show up
  importScriptURI('//en.wikipedia.org/w/index.php?action=raw&ctype='+
                  'text/javascript&title=User:Animum/easyblock.js');
  //wait till import finished before executing the next line
  mw.util.addPortletLink( "p-cactions", "#", "TEST" );

-> the 'TEST' item is both in the "p-cactions" menu and in each of easyblock's submenus.
Comment 1 Krinkle 2012-03-10 14:19:57 UTC
Yes, this is a valid bug. I've reproduced it with the following on en.wikipedia.org: 

// "easyblock.js" is sysop-only
mw.config.get( 'wgUserGroups' ).push( 'sysop' );
$.getScript('//en.wikipedia.org/w/index.php?title=User:Animum/easyblock.js&action=raw&ctype=text/javascript',
    function () {
        mw.util.addPortletLink( 'p-cactions', '#', 'TEST' );
    }
);

I suggest fixing it by using ".children( 'ul' ).eq(0)" instead of ".find( 'ul' )"
Comment 2 Krinkle 2012-06-07 21:07:20 UTC
Went with .find( 'ul' ).eq( 0 ), because it can be inside a sub <div> (like in Vector), so children() wouldn't find it.


Change-Id: I51e9053292f03c1b833db0df2fb1b40f1eaf8b1a

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links