I've noticed that you can apparently import a local script and make it global. How do you do that?
Extension talk:GlobalCssJs/Flow
You can pass the raw URL of the script to mw.loader.load
in your global JavaScript. For example, I load in m:User:Pppery/global.js using mw.loader.load("https://en.wikipedia.org/w/index.php?action=raw&title=User:Pppery/no-ooui-contribs.js&ctype=text/javascript")
.
This post was hidden by Pppery (history)
So what I'm seeing here is that you need the "&action=raw" and "&ctype=text/javascript". Is this how it's done?
Well, that's how I do it at least, and it works for me. If you want a more detailed explanation, you should probably ask at Project:Support desk or w:Wikipedia:Village pump (technical), since this talk page is fairly low traffic and I only noticed your post via recent changes patrol.
The help docs are at Help:Extension:GlobalCssJs. Looking at examples used by other active users is generally the best way to learn. :)
Quote from the article:
"Functions like <code>importScript</code> will not work as those use the local wiki, not the global one."
I cannot seem to figure out the meaning of this sentence.
Can someone help?
best regards,
--~~~~
First, you are talking in the wrong thread, or for the wrong page, since the quotation is occurring on Help:Extension:GlobalCssJs.
Second, the grammar is not pretty indeed, could be read as "nor the global one", but actually means: An importScript() call will refer to the local wiki currently in use, not to a page with this name on Meta wiki, which is usually not intended.
Third, it says that using global resources, you are encouraged to use full URL including project domain, if it shall be shared among all wikis, since importScript() calls are related to pages on current local wiki.
The Help talk:Extension:GlobalCssJs page redirects here.
I've tried to fix the sentence using an adaptation of your wording. If you can make it better, please do!
See Phabricator T63748. I can confirm that it works in what's currently shipping.
@Legoktm: Is there an ability to exclude wikis? For instance, I wish to exclude English Wikisource from my global rollout, as I use other tools there and addition of global.js causes issues. I thought that the script configuration looked to sectionalise what was rolled where, however, I see that the output of onEveryWiki() is additive. Thanks.
You can wrap your global.js in:
if ( mw.config.get("wgDBname") !== "enwikisource" ) {
// Whatever JavaScript you want to run on all wikis but enwikisource
}
hmm, for me this doesn't work...
Can you expand on how it's not working?
@Legoktm: Please take a look at my global.js; I tried to disable my personal popups.js on Wikidata and edittop.js on ruwiki and enwiki, but both these scripts continue to be loaded everytime on the specified wikis.
Ah, found, fixed, works. If for wikisource it's necessary to specify long DB name (i.e.: "enwikisource"), for wikipedias it's necessary to specify short DB name (for example "enwiki").
Would it not make a lot more sense to load a users' global scripts from its home wiki, as designated in Special:CentralAuth? I am rarely on meta, so requiring users to store their global code there seems overly complicated.
Nope. Or at least this is something I wouldn't be able to see as an improvement until CentralAuth has a way to set your home wiki. MediaWiki.org is my home wiki in terms of edits and user rights and overall activity, but CA thinks my home wiki is test.wikipedia.org, where I have a whopping nine (!) edits and some user rights. So no, I wouldn't want to have my global CSS & JS stored on test.wikipedia.org; Meta in the context of WMF wikis makes total sense to me as it's a central place for coordination.
Yes, what Jack said. CentralAuth has some unreliable criteria with which it picks a home wiki, and it's really only used to figure out who wins the account. Also, from a security perspective it is much safer to only allow meta admins to edit your global scripts, as opposed to any testwiki admin :/.
+1
Hi. At es.wikibooks I've noticed the following:
- 04:42 7 sep 2014 Maintenance script (discusión | bloquear) borró Usuario:Makecat/common.js (Deleting JavaScript page on user request due to deployment of mw:Help:Extension:GlobalCssJs) (ver/restaurar)
I wonder if those who have dozens of crosswiki .css/.js pages such as me can also "order" that script to perform the cleanup or is just reserved for users with higher levels of access in the DB. If possible, how is it done? - I have translated some system messages regarding this on betawiki, but I can't figure out how to run that cleanup.
Best regards.
That was a script that was run server-side by Krinkle and myself during the initial migration. I'd recommend you file a request with m:Synchbot and Pathoschild can delete them for you.
Thanks for you reply. Isn't the script working anymore then? I filed both a request on Meta for your script and Pathoschild's one. Best regards.
It probably still works but had issues with being blocked by the AbuseFilter, and was generally less flexible than Pathoschild's script was, which is why I've been letting him take care of it.
@Legoktm: Is there a possibility to add a link to special pages, which changes for every wiki? With local js I used to link to "https://it.wikivoyage.org/wiki/Special:UnconnectedPages", "https://it.wikiquote.org/wiki/Special:UnconnectedPages" etc. How can I do now with global js? Does it exist something like "http://LOCALWIKI/wiki/Special:UnconnectedPages", so if I'm on it.quote it will link to https://it.wikiquote.org/wiki/Special:UnconnectedPages, if I'm on en.voy it will link to https://en.wikivoyage.org/wiki/Special:UnconnectedPages etc.?
You can use:
var url = "https:" + mw.config.get('wgServer') + "/wiki/Special:UnconnectedPages";
And use the url
variable wherever you need it.
mw.util.getUrl
returns a relative URL, but it should suffice for your purposes.
Example:
mw.util.getUrl('Special:UnconnectedPages')
Using my superpower, I guessed that you enabled the "collegamenti personali" gadget on the Italian Wikipedia. Unfortunately, it doesn't work on Meta-Wiki, but you can still use the standard mw.util.addPortletLink
function:
mw.util.addPortletLink( 'p-navigation', mw.util.getUrl('Special:UnconnectedPages'), 'Pagine non connesse', 'unconnected-pages' );
@Ricordisamoa: Thank you so much, it does work! Regarding the "collegamenti personali" gadget, do you mean I can delete the line from my global.js?
There are no older topics