MediaWiki talk:Gadget-popups.js

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia

Minor formatting bug (with code to fix)[edit]

Before proposed change
After proposed change

The current implementation of the parser has a minor bug where if there are formatting marks within the code of a link, that code gets converted to html and then escaped, so that the html code is displayed as text. The text [[Law & Order franchise|''Law & Order'' franchise]] displays as <em>Law & Order</em> franchise instead of Law & Order franchise.

I fixed the issue by having the code parse wiki formatting after the html is escaped instead of before. This way, the formatting marks are converted to html after the html is escaped, rendering the preview as intended. I posted the code at User:Shardsofmetal/popups.js. This diff shows the changes I've made. I've posted screenshots of before and after the change, with a red box around the bug. Could somebody update the file with this change? Thank you, Shardsofmetal 00:32, 20 March 2022 (UTC)Reply[reply]

No time to look at it yet, but that does seem like something that should be checked for XSS problems. —TheDJ (talkcontribs) 12:26, 21 March 2022 (UTC)Reply[reply]
Example article link: Carolyn McCormick. — xaosflux Talk 22:14, 17 April 2022 (UTC)Reply[reply]
 Not done: Please see TheDJ's comment. Izno (talk) 19:39, 3 June 2022 (UTC)Reply[reply]
I'm reactivating my request. I've updated the page at User:Shardsofmetal/popups.js to make this change to the current version of the script (diff between my proposed code and the current code). The last time I made this request, I didn't realize how confusing the diff page was; it made it appear as if I had made many more modifications to the code than I actually had. This time, I've made sure the diff page clearly shows how few modifications I've actually made. I'll restate my proposal because I don't think I was clear enough and detailed enough last time.

Current behavior: The script converts wikitext formatting for italic and bold text (''italic'' and '''bold''') to html (<em>italic</em> and <strong>bold</strong>) before converting wikitext formatting for links into html. When the script converts wikitext formatting for links, it escapes or strips out any html from the article source (for safety reasons). Unfortunately, this means that it's also escaping the html code that the script itself just put there, resulting in the behavior described above and demonstrated in the sreenshot.

Intended behavior: The script escapes or strips html from the article source text (to prevent potential XSS attacks), but does not escape or strip html that the script itself created when parsing wikitext (e.g. converting italic markup to italicized text).

Confirmation that html is still escaped or stripped from links
My proposed change: Converts the wikitext formatting for italic and bold text after converting wikitext formatting for links and escaping or stripping html. This way, the <em></em> and <strong></strong> tags created by the script won't get escaped, while any html in the article source text is still escaped or stripped. (To demonstrate this, I created a test page at User:Shardsofmetal/popupsLinkTest. The page contains 2 links to the "Wikipedia" article with markup to italicize "Wikipedia". The first link uses wikitext and the second uses html. If you're running the version of popups with my proposed change and hover over the link to my test page, you can see that the html is still stripped out of the second link. I've attached a screenshot.)

This proposed change does not introduce any XSS vulnerabilities. None of the code related to escaping html has been modified.

Hopefully this explanation was clear and detailed. Please let me know if there are still any questions or concerns, or if there is anything else I can do get this implemented. Thank you — Shardsofmetal [talk] 00:20, 18 April 2023 (UTC)Reply[reply]
This seems safe to me from an XSS perspective since the only HTML allowed is formatting generated by popups but will give this edit a bit for any comments otherwise. Galobtter (talk) 00:48, 18 April 2023 (UTC)Reply[reply]
 Done Galobtter (talk) 06:02, 24 April 2023 (UTC)Reply[reply]

Expose addTooltip and add completed hook[edit]

Please expose addTooltip function and add completed hook as an extension point for user scripts and other gadgets.

All changes: https://pl.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Popups.js&diff=67169688&oldid=65361823

Hook:

 setupPopups.completed = true;
 mw.hook('userjs.popups.completed').fire(pg);

Tooltip (add comment above and expose below):

	// Add Popups to an anchor Element; popData is optional.
	// Note that the link should be a wiki link.
	function addTooltip(a, popData) {
		if (!isPopupLink(a)) {
			return;
		}
		a.onmouseover = mouseOverWikiLink;
		a.onmouseout = mouseOutWikiLink;
		a.onmousedown = killPopup;
		a.hasPopup = true;
		a.popData = popData;
	}
	pg.fn.addTooltip = addTooltip;

Exposing this function allows enabling popups to custom elements, sidebars etc. Nux (talk) 01:39, 12 May 2022 (UTC)Reply[reply]

 Not done for now: Nux why do you think this is something necessary? Can you provide some actual use cases or proposed changes? It might be more valuable simply to add whatever it is you think should be added to this script rather than extended. Izno (talk) 19:43, 3 June 2022 (UTC)Reply[reply]
@Izno I'm using this on plwiki in custom menu, so I doubt that could be done in a different way then by exposing `addTooltip` function.
I guess another use-case of adding popups to view and history tabs could be done with some popups option. Nux (talk) 20:39, 3 June 2022 (UTC)Reply[reply]
@Izno Note that view and history tabs is now in main content (in V22) so it will get popups anyway. This probably was not intentional... but it work for me, so I'm not complaining 🙂
The use case for custom, dynamic links still remain. Still could use `pg.fn.addTooltip`.
Looking forward to your replay 😉 Nux (talk) 00:52, 14 July 2022 (UTC)Reply[reply]
dismabig fixer (arrows are links)
Here's another use case from the Polish Wikipedia, a gadget that corrects links to disambiguation pages (disFixer tool). The disFixer tool is widely used and originally created by MatmaRex (currently a developer of MW/WMF). This gadget could easily be ported to the English Wikipedia, but the changes to the original Popups are missing. As of this year, disFixer uses the Popups fork to improve links [1]. Since disFixer creates links dynamically, you can't really handle this on the Popups side. Similarly, other gadgets would need a hook (to know that the Popups is ready) and a function to enhance the selected links they create. Nux (talk) 16:52, 25 March 2023 (UTC)Reply[reply]
Still missing this on en.wiki. Any chance to add this here? Is there a technical issue or something I can help with? This has been running on pl.wiki for over a year now. --Nux (talk) 23:53, 10 June 2023 (UTC)Reply[reply]

ReferenceError: api is not defined[edit]

Hi, when I was debugging another script, I happened to face a ReferenceError at #L8367 in pg.fn.modifyWatchlist.

$.when(
    getMwApi().postWithToken('watch', reqData),
    mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']).then(function () {
        return api.loadMessagesIfMissing([messageName]);
    })
).done(function () {
    mw.notify(mw.message(messageName, title).parseDom());
});

This happened when I unwatched a page via the popup's interface. I didn't scrutinize the source code at all but probably there's no variable substitution for api in the function? Developers might want to check it out. --Dragoniez (talk) 11:52, 8 February 2023 (UTC)Reply[reply]

Please replace from line 8366

    mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']).then(function () {
        return api.loadMessagesIfMissing([messageName]);
    })

with

    return getMwApi().loadMessagesIfMissing([messageName]);
This uses the api object fetcher, and removes the loader.using statement for mediawiki.api because that dependency is already enforced at line 7013. —TheDJ (talkcontribs) 14:24, 8 February 2023 (UTC)Reply[reply]
TheDJ: Can we remove that loader.using statement entirely? It looks like mediawiki.jqueryMsg is also enforced at 7016. Writ Keeper  14:57, 8 February 2023 (UTC)Reply[reply]
Good point. I'd missed that. done —TheDJ (talkcontribs) 15:02, 8 February 2023 (UTC)Reply[reply]
Hmm, getting a parsing error complaining about a missing parenthetical that for some reason I can't find. Self-reverted for now. LMK if you can see what I missed. (Also, sidenote: I don't think we can include the "return" or semicolon, since this isn't a standalone line of code, but an argument to a when() function.) Writ Keeper  15:23, 8 February 2023 (UTC)Reply[reply]
  • @TheDJ:, @Writ Keeper: Thank you both. I managed to find some time to look into this, and this issue (per se) can be resolved if we replace the whole API call lines as below:
$.when(
    getMwApi().postWithToken('watch', reqData),
    mw.loader.using(['mediawiki.api', 'mediawiki.jqueryMsg']).then(function () {
        return api.loadMessagesIfMissing([messageName]);
    })
).done(function () {
    mw.notify(mw.message(messageName, title).parseDom());
});

getMwApi().postWithToken('watch', reqData).done(function () {
    mw.notify(mw.message(messageName, title).parseDom());
});

But there's another problem, I looked through the code but loadMessagesIfMissing isn't defined anywhere in the script. This must be why Writ Keeper got a parsing error. But, this function is called in line 5110 too.

function fetchUserGroupNames(userinfoResponse) {
    var queryObj = getJsObj(userinfoResponse).query;
    var user = anyChild(queryObj.users);
    var messages = [];
    if (user.groups) {
        user.groups.forEach(function (groupName) {
            if (['*', 'user', 'autoconfirmed', 'extendedconfirmed', 'named'].indexOf(groupName) === -1) {
                messages.push('group-' + groupName + '-member');
            }
        });
    }
    if (queryObj.globaluserinfo && queryObj.globaluserinfo.groups) {
        queryObj.globaluserinfo.groups.forEach(function (groupName) {
            messages.push('group-' + groupName + '-member');
        });
    }
    return getMwApi().loadMessagesIfMissing(messages);
}

I'm pretty sure we'll need time if we try to fix this too, so could we just temporarily resolve the current issue and look into this one later? I currently don't even know what kind of error this one would spit. Thanks. --Dragoniez (talk) 15:41, 8 February 2023 (UTC)Reply[reply]

No, loadMessagesIfMissing is a function of the mw.Api object, which is Mediawiki-defined and returned by the getMwApi() function. You can find its definition here: https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Api.plugin.messages. I suspect the parsing issue I was seeing was just related to the above-mentioned problem with including the return ...; that was persisting unusually strongly through cache refreshes, since it seems to be working now. I'll reinstate the change shortly, if additional testing bears out. Writ Keeper  15:50, 8 February 2023 (UTC)Reply[reply]
@Writ Keeper: Sorry I guess I looked at the code too quickly. Shoud've noticed that because getMwApi() initializes a mw.Api() instance. The following worked for me without any error in console:
var api = getMwApi();
$.when(
    api.postWithToken('watch', reqData),
    api.loadMessagesIfMissing([messageName])
).done(function () {
    mw.notify(mw.message(messageName, title).parseDom());
});
--Dragoniez (talk) 15:59, 8 February 2023 (UTC)Reply[reply]
Flagging as answered; fix seems to work once return ...; has been removed. Writ Keeper  16:05, 8 February 2023 (UTC)Reply[reply]
I noticed today that using popups to unwatch a page from my watchlist once again shows the brief notification pop-up. That hadn't happened for some considerable time, now it's fixed. Thank you. -- Michael Bednarek (talk) 00:56, 9 February 2023 (UTC)Reply[reply]

Bug report (diff pages): TypeError: Cannot read properties of null (reading 'indexOf')[edit]

I'm seeing around 100 errors a day with the following stack trace on diff pages e.g.https://en.wikipedia.org/w/index.php?diff=1139175290&oldid=1139164047&title=Emily_Ratajkowski

:

at Title.namespaceId https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:49:957 at isInStrippableNamespace https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:53:921 at navlinkTag.getPrintFunction https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:127:213 at navlinkTag.html https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:123:239 at navlinkStringToHTML https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:123:111 at pg.structures.menus.popupTopLinks https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:23:605 at pg.structures.shortmenus.popupTopLinks https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:23:988 at fillEmptySpans https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:64:38 at simplePopupContent https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:6:915 at mouseOverWikiLink2 https://en.wikipedia.org/w/load.php?lang=en&modules=ext.gadget.Navigation_popups&skin=monobook&version=nxu22:6:90

Please let me know if you have any questions. Jon (WMF) (talk) 20:29, 14 February 2023 (UTC)Reply[reply]

Interface-protected edit request on 21 February 2023[edit]

My request is to add the Yiddish redirect code to the redirLists. That is, after line 5679 in the source ("vi: [r, 'đổi'],"), please add the following line:

yi: [R, 'ווייטערפירן'],

אוהב חכמה (talk) 11:40, 21 February 2023 (UTC)Reply[reply]

 Donexaosflux Talk 15:07, 23 February 2023 (UTC)Reply[reply]

rvslots and edit counter fixes[edit]

I've prepped a new version with some minor updates

Thank you. —TheDJ (talkcontribs) 11:38, 12 April 2023 (UTC)Reply[reply]

@TheDJ I only had a moment for a quick check, but I think there's an issue accessing a preview of "history" from within the action menu of a popup? I'll try to confirm later, but wanted to put it out there; I presume an issue parsing rvslots stuff. ~ Amory (utc) 12:50, 12 April 2023 (UTC)Reply[reply]
@Amorymeltzer: Fixed. —TheDJ (talkcontribs) 13:56, 12 April 2023 (UTC)Reply[reply]
 Done. Anyone holler if there're issues. ~ Amory (utc) 14:02, 16 April 2023 (UTC)Reply[reply]

Mouse safe zones for popup menus[edit]

Please add changes to CSS and JS to make menus in popups more stable (mouse out UX aka safe triangle technique).

Two changes:

  • Minor changes in JS JS diff (basically adds a CSS variable).
  • The extra CSS (CSS diff) creates a trapezoid that gives a safe path from the menu title to the list of links. There are also additional margins that will facilitate e.g. hitting the unfollow link.

CSS works without JS changes, but JS makes width of the trapezoid more stable (especially after i18n/l10n). It was my intention to do as much in CSS as possible. You can see the safe triangle technique in a Tweet.

Kind regards, Nux (talk) 00:11, 11 June 2023 (UTC)Reply[reply]

Are you the sole maintainer for this gadget? If not, may want to add some more comments to this code so folks know what's going on. I don't think it's very easy to tell what's going on with that block of CSS just by reading the code. I think a good spot for a big comment that describes how this whole system works ("safe triangle technique") is at the top of the CSS code you're adding. Hope this helps. –Novem Linguae (talk) 04:58, 17 June 2023 (UTC)Reply[reply]
@Novem Linguae well in practice nobody else is changing popups much... But I did add some comments see: pl:Gadget-Popups.css. As written there I'm using a trapezoid guide for the cursor, other CSS rules also got their comments. I haven't changed the old CSS (nor old JS) if that what you are referring to. Popups is generally not well documented (probably to save bytes, which used to matter ~10 years ago). Nux (talk) 09:03, 17 June 2023 (UTC)Reply[reply]
Novem Linguae, Nux - Looking through the code, the JS change is essentially a variable name change with some small code optimization. The CSS looks like just a few small changes to the resulting function of the menus within the pop-up. I... don't see a reason to oppose the changes -  Done. ~Oshwah~(talk) (contribs) 02:41, 25 July 2023 (UTC)Reply[reply]
Thanks. Seems to be working fine :) Nux (talk) 18:45, 25 July 2023 (UTC)Reply[reply]

Turkish Redirect[edit]

Can you please add "YÖNLENDİRME", "yönlendirme", "YÖNLENDİR" and "yönlendir" as Turkish translations of redirect at line 5685? Thanks --ToprakM 17:04, 30 July 2023 (UTC)Reply[reply]

Why are these hardcoded in the first place, instead of being queried from the API? —Tacsipacsi (talk) 00:24, 31 July 2023 (UTC)Reply[reply]
Because the script is from 2004 and the api is from 2007-2009 —TheDJ (talkcontribs) 08:54, 15 August 2023 (UTC)Reply[reply]
I didn’t ask why they have been hardcoded, but why they are hardcoded, now, in 2023, well over a decade after the creation of the action API. Why new and new aliases get hardcoded instead of rewriting it to use the API and making it work in any language. —Tacsipacsi (talk) 21:55, 15 August 2023 (UTC)Reply[reply]
Your approach sounds like the "correct" fix, but would require more coding effort/brainpower than just adding a row to some JSON. It most likely boils down to a lack of volunteer time/effort to refactor that section of code. I would happily review an {{IAER}} using that approach though since I've got that section of code top of mind right now. –Novem Linguae (talk) 23:58, 15 August 2023 (UTC)Reply[reply]
@Novem Linguae:
@@ -5662,56 +5662,6 @@ $(function () {
 		pg.nsTemplateId = 10;
 	}
 
-	function setRedirs() {
-		var r = 'redirect';
-		var R = 'REDIRECT';
-		var redirLists = {
-			//<NOLITE>
-			ar: [R, 'تحويل'],
-			be: [r, 'перанакіраваньне'],
-			bg: [r, 'пренасочване', 'виж'],
-			bs: [r, 'Preusmjeri', 'preusmjeri', 'PREUSMJERI'],
-			bn: [R, 'পুনর্নির্দেশ'],
-			cs: [R, 'PŘESMĚRUJ'],
-			cy: [r, 'ail-cyfeirio'],
-			de: [R, 'WEITERLEITUNG'],
-			el: [R, 'ΑΝΑΚΑΤΕΥΘΥΝΣΗ'],
-			eo: [R, 'ALIDIREKTU', 'ALIDIREKTI'],
-			es: [R, 'REDIRECCIÓN'],
-			et: [r, 'suuna'],
-			ga: [r, 'athsheoladh'],
-			gl: [r, 'REDIRECCIÓN', 'REDIRECIONAMENTO'],
-			he: [R, 'הפניה'],
-			hu: [R, 'ÁTIRÁNYÍTÁS'],
-			is: [r, 'tilvísun', 'TILVÍSUN'],
-			it: [R, 'RINVIA', 'Rinvia'],
-			ja: [R, '転送'],
-			mk: [r, 'пренасочување', 'види'],
-			nds: [r, 'wiederleiden'],
-			'nds-nl': [R, 'DEURVERWIEZING', 'DUURVERWIEZING'],
-			nl: [R, 'DOORVERWIJZING'],
-			nn: [r, 'omdiriger'],
-			pl: [R, 'PATRZ', 'PRZEKIERUJ', 'TAM'],
-			pt: [R, 'redir'],
-			ru: [R, 'ПЕРЕНАПРАВЛЕНИЕ', 'ПЕРЕНАПР'],
-			sk: [r, 'presmeruj'],
-			sr: [r, 'Преусмери', 'преусмери', 'ПРЕУСМЕРИ', 'Preusmeri', 'preusmeri', 'PREUSMERI'],
-			tr: [R, 'YÖNLENDİRME', 'yönlendirme', 'YÖNLENDİR', 'yönlendir'],
-			tt: [R, 'yünältü', 'перенаправление', 'перенапр'],
-			uk: [R, 'ПЕРЕНАПРАВЛЕННЯ', 'ПЕРЕНАПР'],
-			vi: [r, 'đổi'],
-			yi: [R, 'ווייטערפירן'],
-			zh: [R, '重定向'], // no comma
-			//</NOLITE>
-		};
-		var redirList = redirLists[pg.wiki.lang] || [r, R];
-		// Mediawiki is very tolerant about what comes after the #redirect at the start
-		pg.re.redirect = RegExp(
-			'^\\s*[#](' + redirList.join('|') + ').*?\\[{2}([^\\|\\]]*)(|[^\\]]*)?\\]{2}\\s*(.*)',
-			'i'
-		);
-	}
-
 	function setInterwiki() {
 		if (pg.wiki.wikimedia) {
 			// From https://meta.wikimedia.org/wiki/List_of_Wikipedias
@@ -6815,20 +6765,24 @@ $(function () {
 		}
 	}
 
-	function fetchSpecialPageNames() {
+	/**
+	 * Fetch site information.
+	 * @returns {Promise}
+	 */
+	function fetchSiteInfo() {
 		var params = {
 			action: 'query',
 			meta: 'siteinfo',
-			siprop: 'specialpagealiases',
+			siprop: ['specialpagealiases', 'magicwords'],
 			formatversion: 2,
-			// cache for an hour
 			uselang: 'content',
+			// cache for an hour
 			maxage: 3600,
 		};
 		return getMwApi()
 			.get(params)
 			.then(function (data) {
-				pg.wiki.specialpagealiases = data.query.specialpagealiases;
+				pg.wiki.siteinfo = data.query;
 			});
 	}
 
@@ -6890,7 +6844,7 @@ $(function () {
 		var sp = nsRe(pg.nsSpecialId);
 		pg.re.urlNoPopup = RegExp('((title=|/)' + sp + '(?:%3A|:)|section=[0-9]|^#$)');
 
-		pg.wiki.specialpagealiases.forEach(function (specialpage) {
+		pg.wiki.siteinfo.specialpagealiases.forEach(function (specialpage) {
 			if (specialpage.realname === 'Contributions') {
 				pg.re.contribs = RegExp(
 					'(title=|/)' +
@@ -6932,6 +6886,16 @@ $(function () {
 				);
 			}
 		});
+		pg.wiki.siteinfo.magicwords.forEach(function (magicword) {
+			if (magicword.name === 'redirect') {
+				var aliases = magicword.aliases.map(function (alias) { return mw.util.escapeRegExp(alias); });
+				// Mediawiki is very tolerant about what comes after the #redirect at the start
+				pg.re.redirect = new RegExp(
+					'^\\s*(' + aliases.join('|') + ').*?\\[{2}([^\\|\\]]*)(|[^\\]]*)?\\]{2}\\s*(.*)',
+					'i'
+				);
+			}
+		})
 
 		//<NOLITE>
 		var im = nsReImage();
@@ -7039,7 +7003,7 @@ $(function () {
 				'user.options',
 				'mediawiki.jqueryMsg',
 			])
-			.then(fetchSpecialPageNames)
+			.then(fetchSiteInfo)
 			.then(function () {
 				// NB translatable strings should be set up first (strings.js)
 				// basics
@@ -7055,7 +7019,6 @@ $(function () {
 
 				// regexps
 				setRegexps();
-				setRedirs();
 
 				// other stuff
 				setMisc();
Maybe we could even remove pg.wiki.lang as it seems to become unused with this change (hooray, it probably means this was the last hardcoded content language-specific thing!), but I’m not confident enough to do it. Tested on my local, Hungarian-language wiki, with both English and Hungarian redirects. —Tacsipacsi (talk) 18:56, 17 August 2023 (UTC)Reply[reply]
 Done. I added tr: [R, 'YÖNLENDİRME', 'yönlendirme', 'YÖNLENDİR', 'yönlendir'], and tested it. Thanks for the patch. –Novem Linguae (talk) 09:48, 15 August 2023 (UTC)Reply[reply]

Add QID to info line[edit]

Please update the code with the version on User:Chlod/popups.js (compare). This is a requested change that's been requested since 2014 (phab:T243820), and a change as small as this deserves to be done quickly after all this time. Please also delete the userspace .js file when done. Thanks! (cc @Pigsonthewing) Chlod (say hi!) 08:45, 15 August 2023 (UTC)Reply[reply]

 Done. Thanks for the patch! –Novem Linguae (talk) 11:05, 15 August 2023 (UTC)Reply[reply]

List of redirect magic words for each language could use refactoring[edit]

I have no idea why the code in #Turkish Redirect above randomly sprinkles 'r' for 'redirect' or 'R' for 'REDIRECT' into every row. My testing indicates both these keywords work on Turkish Wikipedia. A potential future patch could be to refactor the code to be something like [r, R, ...] on every line. –Novem Linguae (talk) 09:51, 15 August 2023 (UTC)Reply[reply]

I found this pattern in core recently, where this code may have been copy pasted from or at least inspired by. https://gerrit.wikimedia.org/r/c/mediawiki/core/+/952290. There, 0 corresponds to case insensitive and 1 corresponds to case sensitive. r and R in this code may have similar meanings. https://github.com/wikimedia/mediawiki/blob/master/docs/magicword.md. Will need to take a closer look at this. –Novem Linguae (talk) 07:44, 25 August 2023 (UTC)Reply[reply]

MediaWiki:Gadget-navpop.css should be renamed to MediaWiki:Gadget-popups.css[edit]

This gadget uses a second file called MediaWiki:Gadget-navpop.css. Idea: Shouldn't have to look at the gadgets definition file to figure out what this gadget's CSS file is named. It'd probably make more sense for all files related to this gadget to start with MediaWiki:Gadget-popups. So I propose renaming MediaWiki:Gadget-navpop.css to MediaWiki:Gadget-popups.css –Novem Linguae (talk) 10:34, 15 August 2023 (UTC)Reply[reply]

Support. No reason in having this oddity. Chlod (say hi!) 14:48, 18 August 2023 (UTC)Reply[reply]
I’m not opposed to the renaming, but please make sure to maintain backward compatibility. There are probably quite a few people and wikis who load the NavPopups CSS directly rather than as part of the ResourceLoader module, so it’s important that https://en.wikipedia.org/w/index.php?title=MediaWiki:Gadget-navpop.css&action=raw&ctype=text/css continues to load the necessary styles. —Tacsipacsi (talk) 17:22, 19 August 2023 (UTC)Reply[reply]

Does this gadget have a code repository?[edit]

I see some hints in the code that this gadget has a repo somewhere and is compiled with a deploy script. For example // ENDFILE: run.js. Any idea where the repo is? –Novem Linguae (talk) 10:36, 15 August 2023 (UTC)Reply[reply]

Those are still from Lupin. He used some sort of concatenation script on their local machine. We never had access to it. —TheDJ (talkcontribs) 11:21, 15 August 2023 (UTC)Reply[reply]

Docblock cleanup[edit]

Ad [2]

@Novem Linguae: Function and Array are object types and written capitalized. (Although the latter should rarely be used, as generally the element type should be indicated, producing string[], number[], any[] etc. instead of Array.) Only string, null, undefined, unknown, any and primitive types are written lower-case. —Tacsipacsi (talk) 22:00, 15 August 2023 (UTC)Reply[reply]

 Fixed. Thanks for the code review. I am disappointed in my IDE's linters for allowing me to type that and not putting a little red squiggle under it. –Novem Linguae (talk) 23:52, 15 August 2023 (UTC)Reply[reply]
FYI, let f = function() {}; typeof f; in Chrome DevTools console returns "function" not "Function". typeof ['test', 'test'] returns "object" (an "Array" I assume). –Novem Linguae (talk) 13:05, 7 September 2023 (UTC)Reply[reply]

Use native string repetition function[edit]

This gadget uses custom string repetition function. It should be replaced with native String.prototype.repeat() which is significantly faster and well supported by modern browsers. – Ammarpad (talk) 05:20, 20 September 2023 (UTC)Reply[reply]

It seems to be used only for formatting time. So it would probably only help in optimization of the history page preview (if at all significant). Not sure if that is something worth optimizing. You know "premature optimization..." etc Nux (talk) 22:51, 24 September 2023 (UTC)Reply[reply]
I see this as more refactoring than optimizing. I have no objections to the idea. But it needs someone to write and test the patch. –Novem Linguae (talk) 23:42, 24 September 2023 (UTC)Reply[reply]
Refactoring when you loose compatibly, do a lot of work and gain nothing in practice is a bad idea IMHO. When you would start refactoring that you would never finish ;). When you go up the stack you also have a custom `map` function. Nux (talk) 11:50, 25 September 2023 (UTC)Reply[reply]
To be a bit more constructive here... I think a better refactoring effort might be to be to move Popups to Github (e.g. with Wikipedia:Wiki-to-Git). Then do a split to separate files. And then either use e.g. browserify to combine it again. I've been thinking abut this for a while for plwiki, not sure if such update would be accepted here. Nux (talk) 12:19, 25 September 2023 (UTC)Reply[reply]