Page MenuHomePhabricator

Add 'target' anchor attribute in mediawiki.util.js addPortletLink function
Closed, DeclinedPublic


Please add the ability to add 'target' (i.e. 'target=_blank') on addPortletLink in mediawiki.util.js, useful in gadgets where links are added, for example in sidebar. As of MediaWiki 1.25.1 this isn't possible AFAIK.

Event Timeline

Bennylin created this task.Nov 4 2015, 1:53 PM
Bennylin raised the priority of this task from to Needs Triage.
Bennylin updated the task description. (Show Details)
Bennylin added a project: MediaWiki-JavaScript.
Bennylin added a subscriber: Bennylin.
Restricted Application added subscribers: StudiesWorld, Aklapper. · View Herald TranscriptNov 4 2015, 1:53 PM
Me_iwan added a subscriber: Me_iwan.Nov 4 2015, 2:00 PM

Thanks for reporting this!
Would you fancy taking a look at the code and giving this a try? You are very welcome to use developer access to submit a patch as a Git branch directly into Gerrit.

Aklapper set Security to None.
Krinkle closed this task as Declined.Sep 17 2018, 11:07 PM
Krinkle added a subscriber: Krinkle.

Thanks for using addPortletLink, but I'm deciding to decline this feature request.

Adding a built-in options for all possible attributes would make the method slower and more complicated to use. There is no special behaviour needed to set the target attribute. Having an option for it in addPortletLink() would mean we add more code to every page load for all users, without adding value.

It is already possible to set custom attributes by using the return value from addPortletLink(). For example:

var myLink = mw.util.addPortletLink( 'p-tb', '', 'Example' );
myLink.setAttribute('role', 'presentation');

// Or
var myLink = mw.util.addPortletLink( 'p-tb', '', 'Example' );
$(myLink).find('a').attr('target', '_blank');

I hope that works for you. If you find problems with this, please file a new task with the problem. Thanks!