User talk:Enterprisey/script-installer

Feature request: generate code that matches {{subst:iusc}}
Here's my common.js right now.

importScript( 'User:Enterprisey/script-installer.js' ); // Backlink: User:Enterprisey/script-installer.js importScript('User:Enterprisey/easy-brfa.js'); // Backlink: User:Enterprisey/easy-brfa.js importScript('User:Enterprisey/cv-revdel.js'); // Backlink: User:Enterprisey/cv-revdel.js importScript('User:Enterprisey/reply-link.js'); // Backlink: User:Enterprisey/reply-link.js importScript('User:Enterprisey/talk-tab-count.js'); // Backlink: User:Enterprisey/talk-tab-count.js importScript('User:Enterprisey/user-tabs-on-contribs.js'); // Backlink: User:Enterprisey/user-tabs-on-contribs.js

Does that bug you? It bugs me. Would it be possible to change script-installer to match {{subst:iusc}}'s output? (For that matter, is there a reason it doesn't just generate that subst in the first place? DRY and all that.) Gaelan 💬✏️ 09:39, 24 February 2019 (UTC)
 * , is this still an issue? I checked your common.js and my common.js and couldn't see what you're talking about - I'm probably not understanding your comment. Enterprisey (talk!) 06:28, 13 October 2019 (UTC)
 * Oh, spacing inside the parentheses. Huh. Yeah, the subst would be fine. I don't feel very strongly about this. I guess I'll consider adding spaces. Enterprisey (talk!) 04:19, 26 January 2021 (UTC)
 * As of 2024, the gadget is not putting spaces inside parentheses. Judging from the lack of comments on this page, I don't think most users mind. Probably should leave as is. – Novem Linguae (talk) 17:48, 7 May 2024 (UTC)
 * Counter-proposal: Template talk:Install user script. —⁠andrybak (talk) 20:58, 15 June 2024 (UTC)

Global
It would be neat if this script was extended to allow installing scripts on global.js, too. ~ ★ nmaia d 01:05, 15 September 2020 (UTC)
 * Status: I have no plans to work on this, but would be happy to mentor someone if they wanted to work on it themselves. Enterprisey (talk!) 23:53, 13 August 2021 (UTC)

TODO: Bulk deletion support
With checkboxes. Enterprisey (talk!) 04:10, 26 January 2021 (UTC)


 * — 𝐆𝐮𝐚𝐫𝐚𝐩𝐢𝐫𝐚𝐧𝐠𝐚 (talk) 23:41, 26 May 2021 (UTC)
 * Status: I have no plans to work on this, but would be happy to mentor someone if they wanted to work on it themselves. Enterprisey (talk!) 23:53, 13 August 2021 (UTC)

id vs data-
I don't think relying on IDs for getting script paths is a good idea as it results in invalid HTML if the same path appears more than once per page. Shouldn't it use a  attribute? Nardog (talk) 23:18, 8 April 2021 (UTC)

scriptManager
It would be helpful if you added a function allowing you to add scripts using scriptManager's syntax. &#8213; Qwerfjkl  &#124; 𝕋𝔸𝕃𝕂 (please use&#32; on reply) 13:53, 23 May 2021 (UTC)
 * Agreed. — Guarapiranga (talk) 23:50, 26 May 2021 (UTC)
 * Status: I have no plans to work on this, but would be happy to mentor someone if they wanted to work on it themselves. Enterprisey (talk!) 23:53, 13 August 2021 (UTC)

Lusc instead of iusc
This script still seems to be using Iusc, rather than Lusc, which I understand to be the preferred method. , would it be possible to update that? &#123;{u&#124; Sdkb  }&#125;  talk 03:47, 23 November 2021 (UTC)
 * Any update on this?  (which iusc) uses has been deprecated for a while now. See  ―sportzpikachu  my talk  contribs  10:45, 10 December 2021 (UTC)
 * I plan to get to this at some point, but it's not urgent; there's still no good official replacement ("Gadgets 3.0" or whatever number they're on now). So it would just be for the slight performance benefit. Enterprisey (talk!) 04:42, 11 December 2021 (UTC)
 * Strong oppose. There was some misinformation going around a year or two ago that iusc was deprecated, but this had no basis in fact. See Template:Install user script for more info. I strongly prefer iusc because it is much more readable. – Novem Linguae (talk) 17:52, 7 May 2024 (UTC)
 * I switched all my scripts to use Lusc in 2021 after I was told that it would significantly improve page loading speed, and at the time it seemed to do so. Is that no longer the case?  Sdkb  talk 18:06, 7 May 2024 (UTC)
 * Interesting. I haven't looked into the performance angle of this. – Novem Linguae (talk) 18:45, 7 May 2024 (UTC)

Various to-dos
Now that T300743 is fixed, I can list the other to-do items that I noticed while looking for XSS issues. These are all suggestions for future development that you can take or leave as you see fit. Best — Mr. Stradivarius  ♪ talk ♪ 13:33, 7 February 2022 (UTC)
 * The gadget should check the content model of script pages before installing them, and only install ones with a content model of JavaScript. In theory, not checking this would allow an attacker to add JavaScript code to a wikitext page in a trusted user's userspace (which anyone can edit), and then trick the victim into installing the attacker's code while the victim believes it is written by the trusted user. In practice, this attack is stopped by MediaWiki setting the X-Content-Type-Options header to "nosniff", which prevents loading scripts from pages that don't have a MIME type of "text/javascript". This could be a problem in very old browsers though, so it would be worth fixing.
 * Import.fromJs is broken for scripts with double or single quotes in them (e.g. ). The script trims the first quote character and everything after it, which means it tries to install e.g.   instead. Fixing this would mean parsing the string with a JavaScript parser instead of with regex - unfortunately, I'm not aware of an easy way of doing that without installing third-party libraries, so this could be a lot of work.
 * The cookie attributes of the open_script_installer need fixing. Firefox was giving the following warning in the console: Cookie “open_script_installer” will be soon rejected because it has the “SameSite” attribute set to “None” or an invalid value, without the “secure” attribute. To know more about the “SameSite“ attribute, read https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite.
 * There are some missing translation strings: see the latter half of the diff of the Chinese translation to see where they are. They also use different pipe and bracket characters, so those might be worth including as well. The mw.Message class might be worth a look into for this.

unable to uninstall autoFormatter & cleanDiff
i am unable to uninstall both autoFormatter & cleanDiff on common.js. can you please look into it. <_> jindam, vani (talk) 13:56, 27 December 2022 (UTC)


 * Links: meta:User:TMg/autoFormatter, de:Benutzer:TMg/cleanDiff.js. These are both non-English Wikipedia user scripts, which is probably why this gadget didn't work. – Novem Linguae (talk) 17:55, 7 May 2024 (UTC)

Recognize Full Protection
@Enterprisey Currently, the script claims that AutoEd/complete.js is insecure, in spite of the full protection. Could support be added? Aaron Liu (talk) 16:56, 13 September 2023 (UTC)

Should script-installer add userscript pages to the watchlist?
Working on userscripts sometimes requires discussion. Because script-installer is a gadget, this talk page is relatively active, but this is not true for all userscripts. In a recent case, I posted on the talk page of the author, because the script didn't have an existing talk page (both documentation and the code talk pages don't exist at the time of writing). However, in another case I created a talk page corresponding to the script's documentation page and pinged the author.

Technically, due to backlinks generated by automatic script installation, I could figure out, but pinging or messaging them would be way too much spam, which is disruptive.

What if script-installer automatically added/removed the pages (documentation and .js) of a userscript being installed/uninstalled to the watchlist? This would keep the users informed of any updates that might affect them, and maybe encourage their participation in discussions.

On the other hand, such automatic meddling with the watchlist might annoy some users. —⁠andrybak (talk) 13:11, 4 June 2024 (UTC)
 * Andrybak, it could be added as a default-on preference that can be configured in the common.js/skin.js page, like nav popups has. — Qwerfjkl  talk  16:24, 4 June 2024 (UTC)
 * Is the proposal to automatically add to your watchlist any user script installed with this gadget? I wouldn't personally be interested in that. I've installed around 50 user scripts, I think, and I don't have a reason for them to be on my watchlist. Please correct me if I'm misunderstanding. – Novem Linguae (talk) 16:39, 4 June 2024 (UTC)
 * Your understanding of the proposal is correct. With Qwerfjkl's preference idea, it will be possible to disable this functionality. —⁠andrybak (talk) 16:52, 4 June 2024 (UTC)

I have implemented this proposal in my sandbox: Special:Diff/1231540064/1231548208. During installation, the gadget will automatically add the source code page (example: User:Shubinator/DYKcheck.js) and the documentation page (example: User:Shubinator/DYKcheck) to the watchlist. During uninstallation, the gadget will automatically remove the pages from the watchlist. The customization of this automatic watching/unwatching feature can be done via two new options: There are two options rather than one, because there are use-cases for all four combinations: What do you think? —⁠andrybak (talk) 22:27, 28 June 2024 (UTC)
 * 1) the default is both automatic watching and automatic unwatching are enabled – for users who want to keep track only of scripts they currently have installed
 * 2) disable only watching for people who don't want scripts on their watchlists (≈ Novem Linguae's use-case)
 * 3) disable only unwatching for people who want to keep tabs on scripts that they've uninstalled, but, for example, might want to install in the future, when it shows up in their watchlist
 * 4) disable both watching and unwatching for people who want to control their watchlist manually (current status quo)


 * Talk page watchers, is anyone else interested in this feature? I do not think this should default to on without consensus, and maybe not even be included at all without consensus (since if this were to be mostly unused, it would increase technical debt) – Novem Linguae (talk) 22:31, 28 June 2024 (UTC)
 * Novem Linguae, I can't imagine ever using something like this, but I'm probably in the minority when it comes to using scripts. — Qwerfjkl  talk  21:00, 29 June 2024 (UTC)
 * I would be strongly opposed to making it the default (opt-out). Script users often don't understand (or forget over time) which script is responsible for which part of their site experience, and adding the script/doc to their watchlists may overburden (and eventually discourage) script authors when something goes wrong. Instead lead them to WP:VPT, where help (e.g. forking) is more likely to be found. Nardog (talk) 01:31, 30 June 2024 (UTC)

Confusing history of importScript
Due to some confusing discussions around functions  and , I have attempted to reconstruct the events, which lead to the confusion.

I've considered different places for this discussion. The most automated way of installing script nowadays is the installer gadget, so I selected this talk page. —⁠andrybak (talk) 12:27, 7 June 2024 (UTC)

Timeline of importScript

 * 2008: Brooke Vibber (aka Brooke Vibber (WMF)) adds function  to file wikibits.js in commit 36b1931: (bug 13232) importScript, importStylesheet funcs available to custom JS
 * Referenced ticket: 13232, aka T15232. This Git commit is also known as SVN commit rSVN35064.
 * 2010: adds   at the page ResourceLoader/Legacy JavaScript (mw:Special:Permalink/344964) to a long table:
 * 2011: TheDJ says at enwiki Village pump discussion "importScript &gt; mw.loader.load" (underlining for emphasis mine):
 * 2012: At talk page of "ResourceLoader/Legacy JavaScript", in mw:Topic:Qgo3q6e0hvae1dpj Krinkle (aka Timo Tijhof (WMF)) says:
 * Per result of this discussion, User:קיפודנחש adds the following text to the page "ResourceLoader/Legacy JavaScript":
 * Referenced tickets are T27845 and T29281.
 * 2015
 * On 2015-04-13, Schnark marks the function as deprecated in the source code in commit 5c5e090 (aka 203293) with a very detailed commit message:
 * The [1] link is to RL/LJS (redirect to ResourceLoader/Legacy JavaScript), which at the time of writing (2015-08-13) was mw:Special:Permalink/1687750, quote:
 * Note the switch from Bugzilla links to Phabricator links compared to aforementioned 2012's version of the same text.
 * On 2015-04-23, ten days later, Matma Rex reverts this change in commit 8eb99c9 (aka 206078):
 * 2016: Users KPu3uC B Poccuu and V111P disagree about status of the deprecation at Template talk:Install user script.
 * 2018
 * On 2018-01-26, merged the page ResourceLoader/Legacy JavaScript into ResourceLoader/Migration guide (users) in a series of edits. The result of the merge was mw:Special:Permalink/2701322.
 * On 2018-12-03, Ahecht creates an edit request and Galobtter declines it a couple of days later at Template talk:Install user script
 * 2019: Franklin Yu joins the discussion at Template talk:Install user script with
 * Franklin Yu based this reply on this revision of ResourceLoader/Migration guide (users)
 * 2021
 * On 2021-01-26, Izno says at enwiki Village pump:
 * Izno based this reply on this revision of ResourceLoader/Migration guide (users)
 * On 2021-12-10 Sportzpikachu says in a discussion of enwiki's script-installer gadget:
 * 2022
 * On 2022-08-05, in commit 51155b0 (aka 820828) moves the function   from wikibits.js to mediawiki.base.js, quote:
 * Accordingly, Krinkle removes  from the aforementioned table of deprecated functions with edit summary: importScript has never been deprecated, no warnigns, source explicilty states otherwise, no intention to remove.
 * On 2022-09-01, in commit 0ff333e (aka 828663 and 831217) writes:
 * On 2022-10-29, MacFan4000 adds the corresponding release note for MediaWiki 1.39.0, which was released at the end of November (underlining mine):
 * 2024: Novem Linguae responds to the same discussion of enwiki's script-installer gadget about two and a half years after the discussion started:

Feel free to edit this timeline if you find mistakes, anything relevant turns up, or to improve formatting. —⁠andrybak (talk) 12:27, 7 June 2024 (UTC)
 * Added Template talk:Install user script. —⁠andrybak (talk) 12:35, 7 June 2024 (UTC)
 * Added Gerrit links corresponding to the existing Phabricator links for commits. —⁠andrybak (talk) 18:24, 7 June 2024 (UTC)
 * Added quote from 2022-09-01 commit. —⁠andrybak (talk) 20:16, 7 June 2024 (UTC)
 * Would it be helpful to color code the timeline? Something like or ❌ for situations when the person thought the function was deprecated and ✅ for when they didn't. —⁠andrybak (talk) 13:29, 7 June 2024 (UTC)

Discussion – Confusing history of importScript
It seems that most of the confusion was caused by the discrepancies between three sources of information: source code, ResourceLoader/Legacy JavaScript, and ResourceLoader/Migration guide (users). Hopefully this will clear up any confusion and clarify people were confused. Let me know, if there are any other discussions.

Courtesy pings to other participants of discussions and tickets: He7d3r, Skizzerz, Gary, Mdowdell. —⁠andrybak (talk) 12:27, 7 June 2024 (UTC)
 * , the up-to-date information is at Template:Install user script (Special:Permalink/1197700514). —⁠andrybak (talk) 13:00, 7 June 2024 (UTC)
 * What if we added a note to the page ResourceLoader/Migration_guide_(users), similar to Template:Install user script? —⁠andrybak (talk) 13:49, 7 June 2024 (UTC)
 * More courtesy pings for participants of the 2021 VPT discussion: Sdkb, Enterprisey, Berchanhimez, Jon (WMF), Jonesey95, CaptainEek, GhostInTheMachine, Ladsgroup, xaosflux, SD0001. —⁠andrybak (talk) 13:07, 7 June 2024 (UTC)
 * That's a lot of pings. Does this issue need all this attention? I feel it has been resolved for a year or two. – Novem Linguae (talk) 13:34, 7 June 2024 (UTC)
 * Maybe it doesn't. I'm trying to ensure that the misinformation doesn't spread. For me personally, the starting point was Izno's 2021 comment (i.e. I was thinking it was deprecated), so this wall of text started as a draft for a message on his talk page asking for clarification, because I couldn't find what he was referring to about MediaWiki 1.29. I also had a vague memory of your Special:Diff/1222746631, but I failed to find it for a long time during the investigation. —⁠andrybak (talk) 13:49, 7 June 2024 (UTC)
 * Thanks @andrybak for putting together the very detailed history. At the time I added that comment I thought importScript had been deprecated (don't remember where I got that from tbh), but @Novem Linguae has already clarified that above. However I do agree with @Novem Linguae that there isn't much left to do regarding importScript vs mw.loader.load. ―sportzpikachu  my talk contribs  14:20, 7 June 2024 (UTC)
 * I'm still curious whether there's any performance difference between the two options. If not, importScript is certainly cleaner.  Sdkb  talk 15:48, 7 June 2024 (UTC)
 * There is no performance difference (and there never was). Both functions use exactly the same mechanism for loading a script. Furthermore, if the same script is ed twice, it only loads once – which is not the case while using mw.loader.load, so in a way importScript is faster. –  SD0001  (talk) 06:05, 8 June 2024 (UTC)
 * That is an impressive history. Nice detective work. – Jonesey95 (talk) 01:34, 11 June 2024 (UTC)
 * importScript is not deprecated but it will be. Seeing from the patches such as 206078 and 203293 the intent is clear. Further use will make the migration harder in the future. Ladsgroupoverleg 18:06, 7 June 2024 (UTC)
 * Ladsgroup, the Gerrit links you've provided correspond to the items for year 2015 in the timeline above – I've used slightly different view via Phabricator*. Note the chronological order of these two patches:
 * Apr 14, 2015 203293 "wikibits: Mark importScript/importStylesheet utilities as deprecated"
 * Apr 23, 2015 206078 "wikibits: Un-deprecate importScript and importStylesheet // Per discussion on T95964. No suitable replacement exists yet."
 * Hope this helps. —⁠andrybak (talk) 18:18, 7 June 2024 (UTC)
 * importScript has major code readability advantages over mw.loader.load. I definitely hope it is never deprecated. If it comes up in phab or gerrit I plan to share my opinion.
 * The author of 203293 mentioned above later said For local imports, call importScript. This is not, and never was, deprecated. For cross-wiki and other less trivial use cases, call mw.loader.load, which makes me wonder if there is still an intent to deprecate it. – Novem Linguae (talk) 19:36, 7 June 2024 (UTC)
 * I've added another relevant commit to the timeline, which mentions Gadgets 3.0 (T36958), and suggests that  is here to stay for quite a long time.
 * For context, the ticket for Gadgets 2.0 – T31272: is still in status "Open", because it seems to be waiting on T153339, T125582, T31398, and T110014. However, a lot of other subtasks of T31272 are already implemented. T31272 also links to mw:Extension:Gadgets/Roadmap, which is marked as obsolete, which is confusing. The latest comments under T31272 are from April 2024 with consideration to integrate Gadgets 2.0 into an even bigger project – Growth/Community configuration (T323811), but this integration doesn't seem to have happened – the gadgets are only mentioned in T323811 under "Possible usecases". —⁠andrybak (talk) 20:33, 7 June 2024 (UTC)
 * The undeprecation patch is a decade old and mentions "no suitable replacement exists" - which still holds true. It's not like it will be deprecated until a replacement exists - which arguably is Gadgets 3 (T36958). – SD0001  (talk) 06:10, 8 June 2024 (UTC)
 * The undeprecation patch is a decade old and mentions "no suitable replacement exists" - which still holds true. It's not like it will be deprecated until a replacement exists - which arguably is Gadgets 3 (T36958). – SD0001  (talk) 06:10, 8 June 2024 (UTC)

"Normalize" function breaks CSS imports
Edit Jack who built the house (talk) 15:50, 13 July 2024 (UTC)


 * Looking at documentation of function mw.loader.load, it seems that just avoiding spaces inside the quoted 'string' or "string" of the parameter could be enough: Special:Diff/1234315858.
 * A more radical, more hacky approach is to remember which quotation marks—single  or double  —were used and check if the part of the match, where we're expecting a singular parameter, includes the remembered quotation mark: Special:Diff/1231549277/1234730968. —⁠andrybak (talk) 18:54, 13 July 2024 (UTC)