Page MenuHomePhabricator

Make it easier to add TemplateStyles from a module
Open, Needs TriagePublic

Description

Currently, adding TemplateStyles from a lua module requires including the following in the returned value:

mw.getCurrentFrame():extensionTag( 'templatestyles',  '', { src = 'Module:Script doc auto/styles.css' } )

or with named args:

mw.getCurrentFrame():extensionTag{ name = 'templatestyles', args = { src = 'Module:Script doc auto/styles.css' } }

We could add a Lua library in TemplateStyles to simplify it down to:

mw.ext.templatestyles.add( 'Module:Script doc auto/styles.css' );

(name up for bikeshedding, add is probably a bit misleading as it implies a side-effect-causing void function, when in reality it returns the extension tag)

While viewing the module, there's currently no easy way to navigate to the TemplateStyles page. A function like the above also enables SyntaxHighlight to make the link clickable similar to require(), mw.loadData() and mw.loadJsonData().

Event Timeline

This was not a factor when that task was declined, so I think it merits re-evaluation.

A function like the above also enables SyntaxHighlight to make the link clickable similar to require(), mw.loadData() and mw.loadJsonData().

Personally i think this is such a common thing to do, that a standard wrapper makes sense, but i don't feel strongly about it one way or another.

Adding CodeMirror tag since auto-linking could likely be applied to it too, similar to the suggestion for SyntaxHighlight (see T419335: Add CodeMirror auto-linking where missing).

MusikAnimal subscribed.

Adding CodeMirror tag since auto-linking could likely be applied to it too, similar to the suggestion for SyntaxHighlight (see T419335: Add CodeMirror auto-linking where missing).

Pardon my ignorance; Is it safe to assume that syntax like { src = 'Namespace:Foobar' } would always refer to the page title Namespace:Foobar?

Otherwise, it may make more sense to wait until we have the new mw.ext.templatestyles.add() method to bring CodeMirror into it. The new syntax would also make it more easy to add autocompletion when typing the page title such that only sanitized-css titles are suggested.

Adding CodeMirror tag since auto-linking could likely be applied to it too, similar to the suggestion for SyntaxHighlight (see T419335: Add CodeMirror auto-linking where missing).

Pardon my ignorance; Is it safe to assume that syntax like { src = 'Namespace:Foobar' } would always refer to the page title Namespace:Foobar?

Otherwise, it may make more sense to wait until we have the new mw.ext.templatestyles.add() method to bring CodeMirror into it. The new syntax would also make it more easy to add autocompletion when typing the page title such that only sanitized-css titles are suggested.

Yes, I was envisioning that we'd only add the auto-linking capability once the new method is introduced. Sorry I wasn't more clear about that!

A function like the above also enables SyntaxHighlight to make the link clickable similar to require(), mw.loadData() and mw.loadJsonData().

Although I agree with having a simpler way to add styles since it’s such a common thing, I should note that currently all of those aren’t links either.

A function like the above also enables SyntaxHighlight to make the link clickable similar to require(), mw.loadData() and mw.loadJsonData().

Although I agree with having a simpler way to add styles since it’s such a common thing, I should note that currently all of those aren’t links either.

Not in CodeMirror, no, but the OP was talking about SyntaxHighlight, not CodeMirror. See https://en.wikipedia.org/wiki/Module:Lua_banner#L-2 for an example of this linking in the wild.

Change #1298903 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/TemplateStyles@master] Add lua library to add TemplateStyles from modules

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

Change #1298905 had a related patch set uploaded (by SD0001; author: SD0001):

[integration/config@master] Zuul: [TemplateStyles] Add Scribunto phan dependency

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

Change #1298908 had a related patch set uploaded (by SD0001; author: SD0001):

[mediawiki/extensions/SyntaxHighlight_GeSHi@master] links: Add link to page passed in mw.ext.templatestyles()

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

Change #1298905 merged by jenkins-bot:

[integration/config@master] Zuul: [TemplateStyles] Add Scribunto phan dependency

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

Ah, it doesn’t support cases like https://ru.wikipedia.org/wiki/Модуль:Вложенный_список#L-10 or https://ru.wikipedia.org/wiki/Модуль:NumberOf#L-376 which is why I thought it’s not currently implemented. Apologies.

I created T428952 for this.