Extension talk:Gadgets

Jump to navigation Jump to search

About this board

Previous discussion was archived at Extension talk:Gadgets/Archive on 2012-01-06.

How to have this code on a wiki page using Gadgets?

Farvardyn (talkcontribs)


How can I have this code script on a mediawiki page using Gadgets? Not on header or footer, I mean just within the content of a page, how can I have this?


<div id="15068716388"><script type="text/JavaScript" src="https://www.aparat.com/embed/aWf7R?data[rnddiv]=15068716388&data[responsive]=yes"></script></div>
Jeblad (talkcontribs)

You can't without whitelisting the script tag, and that will not happen on Wikimedia sites.

Reply to "How to have this code on a wiki page using Gadgets?"

Loading Remote Definition File For All Users

Jabowery (talkcontribs)

Over at Wikipedia, the Navigation popups instructions for "Installation on remote MediaWiki installations, or via your global.js" provide instructions only on loading for a single user. How can one load it for all users? Placing the recommended js in the remote wiki's "MediaWiki:Gadget-popups.js" has no effect. That recommended js is:

// [[Wikipedia:Tools/Navigation popups]]
PerfektesChaos (talkcontribs)

The path with MediaWiki:Gadget is one good starting point, but needs to be a bit more elaborated.

There are two approaches:

  1. Activate (by default) for all users, but offer the capability to switch off (for registered users) or on.
  2. Activate with almost no escape for all (desktop) users: MediaWiki:Common.js (not longer used here, for sake of first approach).

The first approach is much more flexible and user friendly; see MediaWiki:Gadgets-definition as an example and Extension:Gadgets.

For an external Wiki please be sure that this extension is installed.

Reply to "Loading Remote Definition File For All Users"

Conditional loading in definitions, depending on action, namespace, etc.

Od1n (talkcontribs)

Gadgets are often wrapped with conditional execution tests, like (made-up example):

if ( mw.config.get( 'wgNamespaceNumber' ) === 14
|| mw.config.get( 'wgAction' ) === 'history'
|| mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Contributions' ) {

    mw.loader.using( 'oojs-ui', function () {
        // gadget code
    } );


Note the above avoids loading the heavy OOUI when it's not used.

However, if you have the following definition line:

MyGadget [ResourceLoader|dependencies=oojs-ui] | MyGadget.js

… then OOUI will be loaded on each and every page.

Therefore, it could be helpful to implement additional definition options, that would load the gadget only on given namespaces/actions/specialpages/etc., like:

MyGadget [ResourceLoader|dependencies=oojs-ui|namespaces=14,>=0,Category,categorie|actions=diff,edit,history,view|specialpages=all/any,Contributions,whatlinkshere] | MyGadget.js
PerfektesChaos (talkcontribs)

I do support this request.

If I recall correctly, some other conditions like user group have been added in recent years, and similar wishes for namespace condition and action condition came up multiple times.

Perhelion (talkcontribs)
Reply to "Conditional loading in definitions, depending on action, namespace, etc."

About gadgets using multiple css/js files with different conditions

SolidBlock (talkcontribs)

Can I definite a gadgrt like this (if I were admin): a gadget using a.css, b.css and c.css. It displays for all users, but gadget-b.css only works for Vector users and c.css only works for Monobook users?

קיפודנחש (talkcontribs)

i do not know the answer to the question as phrased, but i think the same goal can be achieved rather simply:

each of the skins' bodies declares a class, e.g., for vector, it's "skin-vector" and so on and so forth.

you can define a single css for the gadget, and precede each of the rules (or rather, each of the rules which are "skin specific") with .skin_XXX, so each of those rules in your unified css, will apply to specific skin only.

i understand this is not what you asked, exactly, but if i understood correctly what you are trying to do, i think "my" solution is simple and straightforward.


PerfektesChaos (talkcontribs)

There is a way to specify that the entire gadget is considered only if the current skin matches this or that particular one.

However, this was not your question. You want to run the gadget for every skin, but load particular resources depending on current skin.

Well, the current skin is known to the JS gadget, and depending on that you may load different CSS pages by mw.loader.load(). However, CSS definitions then arrive quite late and might change the first presentation in an undesirable way.

The suggestion made before is better: Load one common CSS resource from the first beginning, and distinguish by classes .skin-vector those rules which are not appropriate for all skins.

Dinoguy1000 (talkcontribs)

Alternatively, you could split your gadget into a single common gadget and skin-specific gadgets (so for your example you would end up with three gadgets), which would avoid the load timing issues of PerfektesChaos' suggestion. However, it would then require your users to enable separate gadgets for the same functionality (or require you to set multiple gadgets to active by default and maybe hidden depending on what you're after).

So again, the suggestion to use skin-specific classes in a single CSS file is the best option here.

SolidBlock (talkcontribs)

Using class selector ".skin-vector" is OK, but not convenient. But body class doesn't include usergroups. Maybe I can use JavaScript.

PerfektesChaos (talkcontribs)

With JavaScript you can do nearly everything, but at the risk of en:FOUC.

It is almost impossible to wait until CSS has been loaded and is in effect, then beginning to insert your HTML elements.

There are classes depending on user groups, like sysop or not anonymous, but IIRC they need to be defined by project. German Wikipedia can limit CSS visible to sysop only, e.g. a block user button which is meaningless for everybody else, or do not offer user preferences to anonymous users.

Another approach would be to use the ostracised inline style="" and create HTML elements only under certain conditions and provide specific CSS. Such inline style is present together with the element and does not depend on style sheets arriving later. By smart programming they allow centralised maintenance like class rules.

Reply to "About gadgets using multiple css/js files with different conditions"
Minilexikon (talkcontribs)

I'm a coding guy from several wikis at FANDOM (formerly known as Wikia). FANDOM is running MediaWiki v1.19 (what a shame), so it's technically able to use the Gadgets extension. I was wondering when I did an api request to get all my activated gadgets, what query.gadgets.metadata.settings.shared means. Is it something like the current "dependencies" option?

Thanks in advance!

Reply to ""shared" in metadata"

What are "system messages"?

Johnywhy (talkcontribs)
Ciencia Al Poder (talkcontribs)
Reply to "What are "system messages"?"

Possibility to load from interwiki

Minilexikon (talkcontribs)
Jeblad (talkcontribs)
He7d3r (talkcontribs)
Reply to "Possibility to load from interwiki"

Gadget definition namespace?

Pcj (talkcontribs)

What is the Gadget definition namespace for? I noticed there's nothing in the manual for it (and it's not even being used on Wikipedia). So what is it for?

He7d3r (talkcontribs)
Reply to "Gadget definition namespace?"
Summary by Iniquity


Iniquity (talkcontribs)

Hello, I want to use


instead of


But this code doesnt work.

He7d3r (talkcontribs)
Reza1615 (talkcontribs)

Is it possible to add option that we can set some of the gadgets only for IP and not confirmed and when they will registered it will dis-activated.

Subfader (talkcontribs)

For anons: make them standard JS and check for javascript globals in the DOM (above body).

קיפודנחש (talkcontribs)

close, but this won't create the desired effect exactly - what the OP asked for would allow for registered users to "opt-in", while your solution does not. however, this is the closest i can think of with a single script.

alternatively, you could play a little variation on the above: call the gadget directly from common.js under the condition "mw.user.anonymous()", and make the gadget non-default.

Subfader (talkcontribs)

He wants it active for anons and inactive for loggedin users = no gadget.

Krinkle (talkcontribs)

I'd recommend do making it as a gadget to allow optimized loading of it as well as internalization. Simply make it a normal gadget that doesn't have [default] but does have [ResourceLoader]. And from MediaWiki:Common.js (as קיפודנחש suggested), call mw.loader.load('gadget.YOUR_GADGET_ID') under a conditional:

mw.loader.using('medawiki.user', function() {
    if (mw.user.anonymous()) {
He7d3r (talkcontribs)

For the record: the mw.loader.load can also be in a default gadget hidden from preferences with the "|rights=hidden" hack (example) or with the native "hidden" option from the next version of the gadgets extension.

Edokter (talkcontribs)

Someone with proper insight should properly document the [hidden] parameter.

Saper (talkcontribs)

Be aware of typos, here's a working version of the code above:

mw.loader.using('mediawiki.user').done(function() {
    if (mw.user.isAnon()) {
Reply to "New feature"