Page MenuHomePhabricator

Add support for templates in definitions
Open, Needs TriagePublicFeature

Description

As a template and gadget developer, I'd like to be able to load a specific gadget when a specific template is used.

Often, a gadget will implement or expand the functionality of a template (see some examples). Currently, this is being done by having the template add a category, and then load the gadget when the category is found, using the "categories" option in the gadgets definition (introduced by this change). However, this often leads to the creation of otherwise useless and cryptic categories (see for example these 17 categories in eswiki). Since the most frequent use for the "categories" option turned out to be loading a gadget when a certain template is used, it should be possible to skip the middleman and load the gadget directly.

Event Timeline

Change #1114712 had a related patch set uploaded (by Sophivorus; author: Sophivorus):

[mediawiki/extensions/Gadgets@master] Add support for templates in definitions

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

This issue is actually solved already by the categories feature.

Under certain circumstances a transluded template may or may not throw a hidden category, which will cause gadget loading.

Many templates could share the identical trigger category, and not every translusion does result in output for which the gadget is meaningful.

Experienced staff may list hidden categories, and make transparent what is happening on this page. Innocent readers do not see any amount of hidden categories.

Well, the only gadget so far that is loaded by multiple templates is Calculator.js
All others are limited to a single template and are loaded unconditionally.
Sure, we could keep creating those middleman categories, but I don't see why can't we add the "templates" option too for when it's more appropriate (which currently is most times).
Also, in third-party wikis (like appropedia.org) some templates with associated scripts are used in thousands of pages, so loading them via categories creates huge unnecessary categories that pollute the categorylinks table and sometimes the job queue too. This may eventually happen in Wikimedia wikis, when one of these gadgets becomes really popular.
For example, I'm thinking on creating a gadget that extends {{Citation needed}} so that when clicked, it opens a UI where the user may enter a reference, and then saves the changes behind scenes. If I succeed, this would imply the creation of a category with 500K+ pages in enwiki.

unnecessary categories that pollute the categorylinks table

One category per gadget family – how many gadgets do you expect? Do you have any idea how many categories are just now “polluting” English Wikipedia? I never noticed any complaint nor server crash.

Your code as provided by patch does show that it is not trivial and the system becomes more and more complicated, without really needed.

BTW, this does not go for “templates” but for any transcluded page, including modules and anything else. I fail to see precise definitions and explanations or syntax definition.

I never noticed any complaint nor server crash.

Not on enwiki, but T343131: Commons database is growing way too fast is such a complaint.

I would categorically prefer a task like this to be implemented and have previously argued it when discussion of category templates was at hand (perhaps not on Phab?). Categories are almost always going to be a middleman in the context of these kinds of limited gadgets, and all the category gadgets on enwiki are closely associated to a handful of templates.

when one of these gadgets becomes really popular.

WikiMiniAtlas is now loaded via category gadget, and that goes along with every invocation of the coordinates template, which is a few million pages on en.

As communities have started referring to category-triggered gadgets as "template gadgets", it seems to make sense to actually make them template-triggered. A category may or may not be required. When the template is used in interface messages, it's actually harmful to use a category as that causes views that use the interface message (even special pages, forms, etc) to oddly have the #catlinks footer.

It's still a suboptimal solution compared to T241524, however.

Change #1243823 had a related patch set uploaded (by Sophivorus; author: Sophivorus):

[mediawiki/extensions/Gadgets@master] Add support for templates in definitions

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

Change #1243823 abandoned by Sophivorus:

[mediawiki/extensions/Gadgets@master] Add support for templates in definitions

Reason:

Duplicate of https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Gadgets/+/1114712

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