This is a
failed proposal.
Consensus for its implementation was not established within a reasonable period of time. If you want to revive discussion, please use
the talk page or initiate a thread at
the village pump. |
Superseded by WP:Gadgets#Template gadgets
On-demand gadgets are gadgets that are loaded on pages with content meeting some specific condition.
There are a lot of usecases for gadgets that load conditionally based on the content of a page. The condition could be the presence of a template, a category, a parser tag, or an HTML class attribute. We only need to support one kind of condition since anything that adds a template can be easily changed to also add a category or parser tag or a div with a class, and vice-versa.
“ | Community developers tend to know well what functionality is needed, but should not be required to produce a production-quality code from the start. | ” |
— m:User:Yurik/From Dream to Reality |
Today, Kartographer and Graph extensions provide interactive maps and graphs in Wikipedia. We should empower the community to build more such interactive features. The on-demand gadget system provides an efficient way to load such gadgets only where required. Many features in MediaWiki are first tried out as local scripts or gadgets before they mature into extensions.
“ | Interactive content should illustrate and enhance textual articles. It is not the main attraction | ” |
— mw:User:Bawolff/Interactive rich media |
“ | Embrace that every page starts with basic HTML and CSS, and that JavaScript adds optional layers that may or may not arrive. | ” |
— wikitech:MediaWiki Engineering/Guides/Frontend performance practices#General approach |
When on-demand gadgets are used in mainspace, they:
This is proposed to be implemented with the following code in MediaWiki:Gadget-ondemand.js:
mw.hook('wikipage.content').add($content =>
$content.find('.load-gadget').each((_, e) =>
mw.loader.load('ext.gadget.ondemand-' + e.dataset.gadget)
)
);
The above gadget is then registered as default in MediaWiki:Gadgets-definition:
* ondemand [ ResourceLoader | default | hidden ] | ondemand.js
The "hidden" qualifier can be also be skipped. Doing so enables a user to opt-out from all on-demand gadgets.
An equivalent snippet can also be used in MediaWiki:Common.js and MediaWiki:Mobile.js in lieu of adding a default gadget.
Sample usage (within a template, which can then be used on pages):
<div class=load-gadget data-gadget=xyz>
</div>
Presence of such an html element triggers the gadget with name ondemand-xyz
to load.
The gadget ondemand-xyz should be registered as hidden to hide it from preferences:
* ondemand-xyz [ ResourceLoader | hidden ] | ondemand-xyz.js
This should not be marked default as it will be internally loaded via ondemand gadget.
New on-demand gadgets affecting mainspace content should have community consensus demonstrated through an RfC or a discussion at an appropriate village pump.
On-demand gadgets for use outside mainspace may be enabled after a consensus at a relevant project talk page or a broader discussion, depending on the nature of the gadget.
In ALL cases, code in on-demand gadgets MUST be reviewed by at least one user (other than the author) with js-3 or higher proficiency. The code reviewer should be familiar with typical JS vulnerabilities such as XSS and ReDoS, and have demonstrable experience with JavaScript.
Names of maintainers should be listed in the gadget header. Maintainers should ensure that the gadget continues to function despite the changes occurring in the core MediaWiki software and in browsers.
Inactive maintainers should be replaced with active ones. Gadgets that fail to attract new maintainers should be disabled.
<gadget name="xyz"/>
(
phab:T241524). This is an ideal solution. It can also provide enhanced tracking capabilities (backlinks, tracking category). But the patch has been stuck in code review for years.This is a
failed proposal.
Consensus for its implementation was not established within a reasonable period of time. If you want to revive discussion, please use
the talk page or initiate a thread at
the village pump. |
Superseded by WP:Gadgets#Template gadgets
On-demand gadgets are gadgets that are loaded on pages with content meeting some specific condition.
There are a lot of usecases for gadgets that load conditionally based on the content of a page. The condition could be the presence of a template, a category, a parser tag, or an HTML class attribute. We only need to support one kind of condition since anything that adds a template can be easily changed to also add a category or parser tag or a div with a class, and vice-versa.
“ | Community developers tend to know well what functionality is needed, but should not be required to produce a production-quality code from the start. | ” |
— m:User:Yurik/From Dream to Reality |
Today, Kartographer and Graph extensions provide interactive maps and graphs in Wikipedia. We should empower the community to build more such interactive features. The on-demand gadget system provides an efficient way to load such gadgets only where required. Many features in MediaWiki are first tried out as local scripts or gadgets before they mature into extensions.
“ | Interactive content should illustrate and enhance textual articles. It is not the main attraction | ” |
— mw:User:Bawolff/Interactive rich media |
“ | Embrace that every page starts with basic HTML and CSS, and that JavaScript adds optional layers that may or may not arrive. | ” |
— wikitech:MediaWiki Engineering/Guides/Frontend performance practices#General approach |
When on-demand gadgets are used in mainspace, they:
This is proposed to be implemented with the following code in MediaWiki:Gadget-ondemand.js:
mw.hook('wikipage.content').add($content =>
$content.find('.load-gadget').each((_, e) =>
mw.loader.load('ext.gadget.ondemand-' + e.dataset.gadget)
)
);
The above gadget is then registered as default in MediaWiki:Gadgets-definition:
* ondemand [ ResourceLoader | default | hidden ] | ondemand.js
The "hidden" qualifier can be also be skipped. Doing so enables a user to opt-out from all on-demand gadgets.
An equivalent snippet can also be used in MediaWiki:Common.js and MediaWiki:Mobile.js in lieu of adding a default gadget.
Sample usage (within a template, which can then be used on pages):
<div class=load-gadget data-gadget=xyz>
</div>
Presence of such an html element triggers the gadget with name ondemand-xyz
to load.
The gadget ondemand-xyz should be registered as hidden to hide it from preferences:
* ondemand-xyz [ ResourceLoader | hidden ] | ondemand-xyz.js
This should not be marked default as it will be internally loaded via ondemand gadget.
New on-demand gadgets affecting mainspace content should have community consensus demonstrated through an RfC or a discussion at an appropriate village pump.
On-demand gadgets for use outside mainspace may be enabled after a consensus at a relevant project talk page or a broader discussion, depending on the nature of the gadget.
In ALL cases, code in on-demand gadgets MUST be reviewed by at least one user (other than the author) with js-3 or higher proficiency. The code reviewer should be familiar with typical JS vulnerabilities such as XSS and ReDoS, and have demonstrable experience with JavaScript.
Names of maintainers should be listed in the gadget header. Maintainers should ensure that the gadget continues to function despite the changes occurring in the core MediaWiki software and in browsers.
Inactive maintainers should be replaced with active ones. Gadgets that fail to attract new maintainers should be disabled.
<gadget name="xyz"/>
(
phab:T241524). This is an ideal solution. It can also provide enhanced tracking capabilities (backlinks, tracking category). But the patch has been stuck in code review for years.