Page MenuHomePhabricator

Improve addPortletLink function signature to add icon support
Open, Stalled, LowPublic

Description

The addPortletLink method has become a vital function for gadgets to extend MediaWiki functionality, however it has room for improvement.

The function should have better support for icons.

Acceptance criteria

  • Calls using the old function signature addPortletLink(portletId, href, text, [id], [tooltip], [accesskey], [nextnode]) → {HTMLElement|null}static # continue to work
  • A simplified 2 parameter version of the function is provided- addPortletLink(portletId, options) where keys in options correspond with the old function parameters.
  • The options are passed in the util.addPortletLink hook so skins can read them.
  • Documentation is updated and documents that skins may extend options with their own options (for example icons)
  • Vector 2022 is updated to generate icon CSS using mw.util.addCSS

Event Timeline

Jdlrobson-WMF renamed this task from Improve addPortletLink function signature to Improve addPortletLink function signature to add icon support.Apr 3 2026, 6:48 PM
Jdlrobson-WMF updated the task description. (Show Details)

Vector 2022 is updated to generate icon CSS using mw.util.addCSS

I think the expectation should be that the icon will be shown as long as the corresponding oojs-ui.styles.icons-* module (or whatever is its Codex replacement) is loaded (without the need to add your own CSS).

Jdlrobson-WMF changed the task status from Open to Stalled.Apr 6 2026, 5:52 PM

Vector 2022 is updated to generate icon CSS using mw.util.addCSS

I think the expectation should be that the icon will be shown as long as the corresponding oojs-ui.styles.icons-* module (or whatever is its Codex replacement) is loaded (without the need to add your own CSS).

Those styles won't necessarily work with the skin. Vector 2022 and Minerva do not use OOUI they use Codex. It would also mean knowing which ResourceLoader module has the icon needed and would load a lot of CSS in addition to this. This would need some kind of API from ResourceLoader/Codex that generates the URL for the icon to be possible.

Vector 2022 is updated to generate icon CSS using mw.util.addCSS

I've opened T422411: Provide ResourceLoader Codex module for generating icon CSS on the fly to capture the missing need for the existing implementation.

Alternatively, we could rewrite the existing Vector 2022 and Minerva code to no longer use CSS Codex components and instead use Vue.js natively but this would increase the digital footprint of those methods and rely on T311099: Allow on-wiki scripts and gadgets to use Codex icons.

As I noted on https://meta.wikimedia.org/wiki/Talk:Community_Wishlist/W320 the following code essentially does what is being asked here (with hacky CSS generation):

async function addIconCSS( id, icon ) {
	await mw.loader.using( 'mediawiki.api' );
	const api = new mw.Api( {
		userAgent: 'MyScript/1.0.0 (MyTalkPage)'
	} );

	const cdxId = `cdxIcon${icon}`;
	const params = {
		action: 'query',
		list: 'codexicons',
		names: [ cdxId ],
	};

	const data = await api.get( params );
	const iconObj = data.query.codexicons[ cdxId ];
	let iconPath = iconObj.ltr || iconObj.rtl || iconObj;

	const img = `<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20"><g>${iconPath}</g></svg>`;
	mw.util.addCSS(`#${id} .minerva-icon, #${id} .vector-icon {
  mask-image: url(data:image/svg+xml,${encodeURIComponent(img)});
}`);
}

const icon = 'Clock';
const id = `gadget-link-icon-${icon}`;
mw.util.addPortletLink('p-personal', '#', 'hi', id);
addIconCSS( id, icon );
Eejit43 updated the task description. (Show Details)
Eejit43 subscribed.

Change #1306073 had a related patch set uploaded (by LazyShrey; author: LazyShrey):

[mediawiki/core@master] mw.util: Pass options object to util.addPortletLink hook

https://gerrit.wikimedia.org/r/1306073

LazyShrey subscribed.

Claimed this task. I have the patches for both core and Vector ready and will be uploading them to Gerrit shortly!

Change #1306074 had a related patch set uploaded (by LazyShrey; author: LazyShrey):

[mediawiki/skins/Vector@master] Vector: Render icons in portlet links from options

https://gerrit.wikimedia.org/r/1306074

Change #1306073 merged by jenkins-bot:

[mediawiki/core@master] mw.util: Pass options object to util.addPortletLink hook

https://gerrit.wikimedia.org/r/1306073

Jdlrobson-WMF changed the task status from Open to Stalled.Jun 30 2026, 5:27 PM

I'm marking this as stalled as I think we need T422411: Provide ResourceLoader Codex module for generating icon CSS on the fly to address this in a supportable way. I'll leave a review on the remaining open patch by end of week.

Chuiimuii_ofc subscribed.

RoadToWiki board hygiene: moved this task from Completed to Incoming so the board matches Phabricator status (still open/stalled). No change to task status or assignee.