Page MenuHomePhabricator

Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadgets
Closed, DeclinedPublic

Description

Undeclared dependencies to mw.util, mw.notify etc need to be explicitly loaded after the deprecation of wikibits (T122755).

mw.util is probably used in a now-broken way in hundreds of gadgets and common.js. Someone please mwgrep the wikis to see the affected ns8 pages at least. Then we can notify the local administrators and hopefully the global interface editors can help as well.
(If we don't get some speed at fixing this breakage, a revert may be in order.)

Even if it is going to be temporarily reverted, I'd expect that we will have to eventually make these undeclared dependencies explicit.

Suggested fixes

See mw:Help:Locating_broken_scripts, mw:ResourceLoader/Legacy_JavaScript and mw:ResourceLoader/Migration_guide_(users) for more.

For Common.js, a typical fix with mw.loader.using will look like this:

Before
(function() {
  ...
  x = mw.util.getParamValue( 'withJS' ); /* util is used but not loaded */
  ...
}());
After
mw.loader.using(['mediawiki.util']).then(function() {
  ...
  x = mw.util.getParamValue( 'withJS' );
  ...
});

For gadgets, typically the right fix is to add necessary dependencies into the dependencies= option written in MediaWiki:Gadgets-definition. If you are not sure you can continue maintaining the script, you might want to replace it with a reference to the same (or similar), better-maintained script hosted elsewhere: see https://en.wikipedia.org/wiki/Wikipedia:User_scripts#Full_manual_instructions for how to do that.

Related Objects

Event Timeline

whym created this task.May 2 2017, 3:30 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptMay 2 2017, 3:30 AM
whym added a comment.May 2 2017, 3:33 AM

Is there a tag for issues of on-wiki scripts?

DannyH renamed this task from Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadets to Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadgets.May 3 2017, 12:07 AM
kaldari renamed this task from Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadgets to Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadets.May 3 2017, 12:07 AM
kaldari edited projects, added Wikimedia-Hackathon-2017; removed Community-Tech.
Krinkle added a subscriber: Krinkle.May 3 2017, 1:45 AM

Using mwgrep to find pages and customised tourbot to filter page content.

3735 pages match "mw.util" or "mediaWiki.util" in the MediaWiki namespace of public wikis. 3726 of these pages match "mw.util", the remainder uses (only) "mediaWiki.util".

Results from mwgrep: P5362

TitleCount
Total pages matching "mw.util" or "mediaWiki.util" in MediaWiki namespace3735
"Gadget-*"2660
"Guidedtour-*"140
"Group-*"18
"Common", "Vector", "Mobile", or "Monobook" .js416
Other (e.g. Editpage.js, Mainpage.js, Upload.js etc.)641
  • "Gadget-*" - probably doesn't need mw.loader() as they specify ResourceLoader dependencies via MediaWiki:Gadgets-definition instead.
  • "Guidedtour-*" - same, they were loaded by ext.guidedTour.js which already ensures at least mediawiki.util, jquery.cookie, and various other modules.
  • "Group-" - needs it, loaded plainly.
  • "Common", "Vector", "Mobile", or "Monobook" .js - needs it, loaded plainly
  • Other - maybe, maybe not. Some of these are likely old and unused. Others can also be loaded from Common.js inside mw.loader.using() in which case it is fine.

I continued with the 935 (18+426+641) pages that "maybe need mw.loader", including the others that might not need it.

With a modified version of Tourbot, I used the MediaWiki API to fetch the current revision content and match it against this pattern in JavaScript:

/(mediaWiki|mw)\.loader\.(using|load)/

Results from tourbot search:

TypeCount
Total of "maybe needs mw.loader"935
Skipped. (Fishbowl or closed/read-only wiki)12
Skipped. (SyntaxError)11
Maybe problem. (Pattern not matched)428
OK (matched pattern)484

Breakdown of "Maybe problem" (428 pages)

TypeCount
Likely broken ("Common", "Vector", "Mobile", or "Monobook" .js)97
Likely broken ("Group-" .js)5
Other326
mwgrep.util.tourbot-matching-oneline.likely.txt (102 pages)
$ cat .. | grep Skipped | grep 'Does not use' | grep -E '[:/](Common|Vector|Monobook|Mobile|Group-.*).js ' 
MediaWiki:Common.js (afwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (bewiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (bgwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (bgwikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (bgwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (brwikimedia) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (brwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (cawikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (eowiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (etwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (fawikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (fawikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (fawikivoyage) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (fowiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (fywiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (glwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (hrwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (huwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (iswikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (itwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (kbdwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (kowikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (kowikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (kowiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ladwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ltwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (mgwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ndswiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ptwikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ptwikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (shwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (sourceswiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (specieswiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (sqwikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (svwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (thwikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (tlwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (udmwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (ugwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (urwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (yiwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Common.js (zhwikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Group-checkuser.js (itwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Group-Image-reviewer.js (fawiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Group-sysop.js (eswikivoyage) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Group-sysop.js (fawiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Group-sysop.js (ukwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Mobile.js (commonswiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Mobile.js (ruwikivoyage) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Mobile.js (zh_yuewiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (alswiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (amwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (arzwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bclwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (be_x_oldwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bswikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bswikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bswikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bswikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (bswiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (cawiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (cywiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (cywikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (cywiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (dewiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (dvwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (enwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (eswikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (euwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (fawikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (glwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (hiwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (ilowiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (iswiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (itwikiversity) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (itwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (kmwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (lawikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (lbwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (mgwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (miwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (mswiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (nahwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (newikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (nlwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (nlwikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (nowiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (ocwiktionary) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (rowiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (rowikibooks) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (scwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (simplewiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (srwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (suwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (trwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (urwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (viwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (warwiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Monobook.js (zhwikisource) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Vector.js (fawikinews) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Vector.js (huwikiquote) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
MediaWiki:Vector.js (rowiki) | Skipped (Does not use mw.loader or mediaWiki.loader). Loading next subject...
Nirmos renamed this task from Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadets to Find and fix undeclared dependencies to mw.util, mw.notify etc of on-wiki scripts and gadgets.May 3 2017, 1:52 AM
Nemo_bis added a comment.EditedMay 3 2017, 8:11 AM

Thanks a lot, Krinkle.

Is there a tag for issues of on-wiki scripts?

Yes, Wikimedia-General-or-Unknown

"Gadget-*" - probably doesn't need mw.loader() as they specify ResourceLoader dependencies via MediaWiki:Gadgets-definition instead.

They should specify dependences, but in most cases don't.

Is there a tag for issues of on-wiki scripts?

Yes, Wikimedia-General-or-Unknown

Reading-Web-Local-Wiki-Issues would be more specific.

Is there a tag for issues of on-wiki scripts?

Yes, Wikimedia-General-or-Unknown

Reading-Web-Local-Wiki-Issues would be more specific.

Not according to the description, but let's continue in https://www.mediawiki.org/wiki/Talk:Reading/Web#phabricator:tag.2FReading-Web-Local-Wiki-Issues

Elitre added a subscriber: Elitre.May 3 2017, 12:54 PM
He7d3r added a subscriber: He7d3r.May 5 2017, 12:43 AM
MtDu added a subscriber: MtDu.May 8 2017, 10:56 AM

Sorry, I don't quite understand how to fix this. Is there documentation for this that could help me understand it? I see the example edit, but I don't quite understand what it's doing syntactically.

I'll be attending the hackathon as a first timer, and am just perusing the workboard. :) Thanks!

@MtDu Probably a smaller example would be something like this: this. CMIIW

whym updated the task description. (Show Details)May 8 2017, 11:12 AM
whym updated the task description. (Show Details)
whym added a comment.May 8 2017, 11:15 AM

@MtDu Just added some code examples into the description.

whym updated the task description. (Show Details)May 8 2017, 11:24 AM
Krinkle updated the task description. (Show Details)May 9 2017, 7:50 PM
Krinkle updated the task description. (Show Details)
Krinkle updated the task description. (Show Details)
whym updated the task description. (Show Details)May 12 2017, 7:24 AM

We need help with this report in Russian Wikinews: https://ru.wikinews.org/?oldid=498970

@Renessaince: The top of this task and latest https://be-tarask.wikipedia.org/wiki/MediaWiki:MessageQuery.js should provide some clues.
https://be.wikisource.org/wiki/MediaWiki:PageNumbers.js either welcomes the latest changes from https://wikisource.org/wiki/MediaWiki:PageNumbers.js , or (way better) completely removing all its code and replacing it with a mw.loader.load call to wikisource.org, as it is an exact copy of a 2012 version (apart from two lines). Please see https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#Keep_gadgets_central

I added the mediawiki.util dependency for some 488 gadgets from Krinkle's list across all wikis those which lacked "ResourceLoader" option and/or any dependency statement at all. In some rare cases, the dependency had been declared in the meanwhile (example) but it doesn't harm to be extra careful.

I'll do a second pass to see whether many gadgets are left whose options are a bit more complex and then I'll try to give a look at the case mentioned above.

whym updated the task description. (Show Details)Jun 1 2017, 2:02 PM
Huji awarded a token.Jun 3 2017, 5:49 AM
Huji added a subscriber: Huji.
Nemo_bis triaged this task as High priority.Jun 3 2017, 2:20 PM

From Krinkle's list I found (and hopefully fixed) some 200 more gadgets with undeclared mediawiki.util dependency, several of which were enabled by default. At least a handful wikis had their JavaScript completely "shut down" for all users but should now be fixed.

As a next step, I'll go through the wikis of the list to see which give severe errors in the console.

Elitre awarded a token.Jun 5 2017, 6:35 PM

Thanks for doing the needful.

Aklapper lowered the priority of this task from High to Normal.Nov 26 2017, 1:19 PM
Pcoombe removed a subscriber: Pcoombe.Dec 22 2017, 1:59 PM
Krinkle removed a subscriber: Krinkle.May 16 2018, 4:48 PM

Hi. Per @Nemo_bis's comment at https://commons.wikimedia.org/wiki/MediaWiki_talk:InterProject.js#Broken_JavaScript I'm reporting this here.

At metawiki I'm getting this webconsole error in safemode, which is preventing various things from working properly.

VM109:266 Uncaught SyntaxError: Invalid or unexpected token
    at domEval (load.php?lang=en&modules=startup&only=scripts&safemode=1&skin=vector:12)
    at load.php?lang=en&modules=startup&only=scripts&safemode=1&skin=vector:18

which someone helped me track down to https://commons.wikimedia.org/wiki/MediaWiki:InterProject.js but we don't know how to fix.

(All userscripts removed, all gadgets disabled, chromium 73 on Mint linux. Cache hard-disabled in devtools. Not reproducible in firefox. Not reproducible in incognito window. Not reproducible at other wikis.)

Aklapper closed this task as Declined.Jun 26 2019, 9:08 AM
Aklapper added a subscriber: TBolliger.

On-wiki content like user scripts, gadgets, templates, custom CSS are local features and managed independently on each wiki. Phabricator is used for MediaWiki, MediaWiki extensions, or server configuration, or by developers and teams to organize what they plan to work on. As @TBolliger archived the Community-Tech-fixes project on this task (which means that the Community-Tech team does not plan to work on this task) I am declining this task.

This is a matter to discuss and fix on the local wiki and not handled in Phabricator until https://phabricator.wikimedia.org/T121470 gets solved.

See https://www.mediawiki.org/wiki/Help:Locating_broken_scripts how you can find out why exactly a gadget is broken.
See https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users) and https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript how you can fix that broken code.

Restricted Application removed a subscriber: Liuxinyu970226. · View Herald TranscriptJun 26 2019, 9:08 AM