MediaWiki talk:Gadget-popups.js

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

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]

 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]
@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]
@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]
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]
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]
 Not done this request is stale, and multiple other changes have been implemented that would have forked the version. Also, it doesn't appear to be uncontroversial. If you wish to proceed please continue the discussion and make a sandbox of the current version and your proposed diff again (you can just put it at Special:MyPage/Gadget-popups-sandbox.js for example. — xaosflux Talk 03:15, 8 October 2023 (UTC)[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]

 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]
Why are these hardcoded in the first place, instead of being queried from the API? —Tacsipacsi (talk) 00:24, 31 July 2023 (UTC)[reply]
Because the script is from 2004 and the api is from 2007-2009 —TheDJ (talkcontribs) 08:54, 15 August 2023 (UTC)[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]
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]
@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]
 Not done as to the additional request being made. @Tacsipacsi: this page appears to have changed since this was initiated. The current version has been mirrored to User:Tacsipacsi/MediaWiki:Gadget-popups-sandbox.js. Please make the change you want there, test, then reactivate the edit request above and comment below when ready. — xaosflux Talk 14:38, 8 October 2023 (UTC)[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]

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]

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]

Support. No reason in having this oddity. Chlod (say hi!) 14:48, 18 August 2023 (UTC)[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]
@Tacsipacsi. Would replacing MediaWiki:Gadget-navpop.css with importStylesheet('MediaWiki:Gadget-popups.css'); be an acceptable solution? –Novem Linguae (talk) 20:47, 7 December 2023 (UTC)[reply]
@Novem Linguae: Apart from it not working, yes. 🙂 You try to put JavaScript in a CSS file, which of course won’t work, but a working solution along these lines would be acceptable. Please also make sure to use absolute URLs because many – probably even most – affected imports are not on the English Wikipedia (importStylesheet uses a URL relative to the wiki it’s executed on, not to the wiki it’s defined on, which would be wrong). —Tacsipacsi (talk) 15:25, 8 December 2023 (UTC)[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]

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]

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]

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]
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]
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]
If both behave identically, using internal functions is always better than writing your own. 1) More standardized so more readable. 2) Less lines of code. 3) More performant. –Novem Linguae (talk) 19:33, 1 December 2023 (UTC)[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]
I'd be open to this if this page gets more activity. With current activity levels though, moving to GitHub may just result in the GitHub being neglected and the versions getting out of sync. And also adds deploy complexity. https://github.com/wikimedia-gadgets/ would be a good spot for this if popups development gets more active (more folks working on this would justify the added complexity of an off-site repo). –Novem Linguae (talk) 19:36, 1 December 2023 (UTC)[reply]
 Not done this doesn't appear to be a ready-to-go release, and may need additional discussion as well. Please prepare a current version to proposed version in a sandbox, such as at Special:MyPage/Gadget-popups-sandbox.js for the proposed code. IF this section is just to discuss strategies and proposals of course you may continue the discussion below. Best regards, — xaosflux Talk 03:17, 8 October 2023 (UTC)[reply]

Live preview refactor[edit]

@Novem Linguae I've done another round of refactoring and have ended up with this diff. The salient highlights are:

  • Removed the custom wikitext parsing engine at wiki2html() and replaced it a call to the parsing API
  • Removed defaultPopupsContainer() and replaced it with a lookup to #mw-content-text (since that is the stable way to identify where the content starts)
  • Refactored the generateLink() to not use raw HTML manipulation

Sohom (talk) 22:37, 5 December 2023 (UTC)[reply]

You shouldn't remove `defaultPopupsContainer`. You should add new selector on top of the selectors, not remove fallbacks. You've also removed `popupOnlyArticleLinks` options by removing `defaultPopupsContainer`. I use popus on e.g. history tab. Nux (talk) 23:28, 5 December 2023 (UTC)[reply]
I've added back the function in my version, the updated diff should be this (lmk if you find any other issues). That being said, I did test the refactoring on quite a few cases (including the history tab, edit and preview usecases) and did not find any noticable difference in behaviour with #mw-content-text. Sohom (talk) 23:45, 5 December 2023 (UTC)[reply]
Thanks. I like the idea behind the changes. So I hope you don't mind me looking over your shoulder, but this is a popular gadget, which I'm also using :). Some thoughts upon review:
  1. `.bind( this )` is not needed most of the time. The `this` keyword is not used inside of most calls to `makePreview`.
  2. `APIimagepagePreviewHTML` doesn't have the same flow. At least looking at the code after `if (typeof content === 'string')` is another if (not else if). So `return ret;` below will not be correct (probably, quite likely).
  3. `APIsharedImagePagePreviewHTML` is in `pg.fn`, so it is exposed to other gadgets and user scripts (possibly scripts on meta.wiki). Not sure if you can just change it from a synchronous function to async. I would at least expose the Promise.
  4. This is mostly nit picking, but I think `// STARTFILE: livepreview.js` should be preserved. I still hope some bold dev, with admin rights, will one day cut the code to files ;).
In any case, I think large changes like this should go through beta process. Even if the code would mostly be equivalent, there might be some cases that are not easy to test. Nux (talk) 00:10, 6 December 2023 (UTC)[reply]
@Sohom Datta I also noticed I think you've missed how htmlGenerator is used. Seems like showAPIPreview shouldn't work. Seems to expect non-async function. Nux (talk) 00:34, 6 December 2023 (UTC)[reply]
@Nux No issues, in fact the more issues we find the better :)
  • I've gone ahead and fixed the issue with APIimagepagePreviewHTML (lmk if there are any issues)
  • I did a global search for APIsharedImagePagePreviewHTML and the only instances are popup clones, so I'm assuming this should be fine.
  • I've added // STARTFILE: livepreview.js though, only the wrapper wiki2html function remains.
  • I've removed the unnecessary .bind( this ) calls :)
Regarding the beta process, I'm happy to wait a while for y'all to test and review the code. I'll put up a post at WP:VPT and WP:IANB to solicit more beta testers/people who might want to review the code :) Sohom (talk) 00:56, 6 December 2023 (UTC)[reply]
For anyone willing to betatest this, please disable the gadget in your settings and add the following to your common.js
importStylesheet( 'MediaWiki:gadget-navpop.css' );
importScript('User:Sohom_Datta/popups.js');
Sohom (talk) 01:05, 6 December 2023 (UTC)[reply]
The gadget definition is
Navigation_popups[ResourceLoader|dependencies=mediawiki.api,mediawiki.user,mediawiki.util,user.options,mediawiki.jqueryMsg|type=general]|popups.js|navpop.css
So we probably need something more like this for testing, right? ("w:" added so that this works on testwiki)
mw.loader.using(['mediawiki.api', 'mediawiki.user', 'mediawiki.util', 'user.options', 'mediawiki.jqueryMsg']).then(function() {
	importScript('w:User:Sohom_Datta/popups.js');
	importStylesheet('w:MediaWiki:Gadget-navpop.css');
});
Novem Linguae (talk) 06:16, 6 December 2023 (UTC)[reply]
Very nice work. Getting rid of the 769 lines of InstaView code (which is some of the smellier code in the codebase, with one letter variable names, for (; remain(); ), etc.) is definitely a maintainability win.
May I suggest splitting this into three patches? Want to diff out the "Removed the custom wikitext parsing engine at wiki2html() and replaced it a call to the parsing API" in a new section and tag it with {{IAER}}? Smaller patches spaced out over time means easier testing, and easier to tell what caused bugs if this talk page starts getting bug reports. –Novem Linguae (talk) 07:43, 6 December 2023 (UTC)[reply]
One thing this will complicate might be section previews. Take for instance formal tone. We also have to think about other content models like User:TheDJ/common.css and analyze a bit the performance for very big pages, with something like Barack Obama. —TheDJ (talkcontribs) 08:29, 6 December 2023 (UTC)[reply]
@TheDJ Section previews appears to work similarly to how it worked previously. User:TheDJ/common.css does fail, but it does so on the old navpopups code as well (we should fix that in a later request?). Barack Obama seems fine since Navpopups truncates the preview to only show a small portion of the wikitext before it reaches the preview code. There is some additional latency since we are moving to a API call from a synchronous parsing of HTML, but overall it should be a performance win if we are parsing long peices of wikitext since we are keeping the main thread free instead of busy parsing multiple bytes of wikitext :) Sohom (talk) 10:48, 6 December 2023 (UTC)[reply]

Create a GitHub repo?[edit]

I guess if Sohom is going to be submitting complex patches like the above, it might be time to think about moving to a GitHub repo. I'm still not completely sold on it, but wanted to start a discussion. Here's some of my thoughts: User:Novem Linguae/Essays/Pros and cons of moving a gadget to a repo. –Novem Linguae (talk) 08:00, 6 December 2023 (UTC)[reply]

gitlab.wikimedia.org —TheDJ (talkcontribs) 08:16, 6 December 2023 (UTC)[reply]
I would add copyright to pros. Most of the time, I see patches applied, admins don't use the name of the person who authored the patch. Most of the time, patches are small, but for bigger patches, that might be copyvio. I assume when exporting one would use Wikipedia:Wiki-to-Git or similar to preserve authors :) (at least authors applying patches). And then when you do pull requests the authors are automatically preserved.
Also to pros I would add blame. Use that very often to figure when and why particular code was added. Making blame work after splitting to files might be a bit hard on git (no built in copy function). But there are ways to do that with a bit of branch and merge magic. Nux (talk) 10:35, 6 December 2023 (UTC)[reply]
I would definitely support a repository. Amongst other things, it will allow for much better code review. Another nice feature would be the ability to migrate to a sane linting system and potentially migrating to using the ResourceLoader package file system in the future (instead of one big huge 8000 line file).
I don't have any issues with eithier Wikimedia Gitlab or Github (as long as Gerrit is not considered), though it might be worthwhile to ask for a specific repos/gadgets namespace in Gitlab if we want to do it longterm :) Sohom (talk) 11:35, 6 December 2023 (UTC)[reply]
How will visibility concerns be addressed? Where will changes be discussed? Will the .js code overleaf always be the live code? -- Michael Bednarek (talk) 12:37, 6 December 2023 (UTC)[reply]
@Michael Bednarek I don't think there are any visibility issues as such, the code needs to be onwiki and in plaintext for the gadget to be able to run at all regardless of whether we use a single huge file or multiple small files with the packagefile directive. Regarding the code review process, it would happen primarily on the platform Gitlab/Github similar to how the Twinkle code review model currently works. Sohom (talk) 14:47, 6 December 2023 (UTC)[reply]
While code review would happen on GitLab, reporting bugs and requesting features could continue to happen here on Wikipedia, as issues are intentionally disabled on gitlab.wikimedia.org. (I prefer gitlab.wikimedia.org to GitHub to keep the code in-house and make it easier to link Git users to Wikipedia users.) —Tacsipacsi (talk) 15:28, 8 December 2023 (UTC)[reply]

Refactor parsing of wikitext[edit]

Per the above discussion, the following changes [2] are proposed :) Sohom (talk) 11:02, 6 December 2023 (UTC)[reply]

This is just the "Removed the custom wikitext parsing engine at wiki2html() and replaced it a call to the parsing API" part of your above code, and not the other two items, correct? Also, what is a good test procedure for this? –Novem Linguae (talk) 11:15, 6 December 2023 (UTC)[reply]
Yep, it is only that wrt to testing,
mw.loader.using(['mediawiki.api', 'mediawiki.user', 'mediawiki.util', 'user.options', 'mediawiki.jqueryMsg']).then(function() {
	importScript('w:User:Sohom Datta/parsingchange-popups.js');
	importStylesheet('w:MediaWiki:Gadget-navpop.css');
});
should work :) Sohom (talk) 11:17, 6 December 2023 (UTC)[reply]
For testing, I meant, what modules should we be clicking to exercise this part of the code? :) –Novem Linguae (talk) 11:31, 6 December 2023 (UTC)[reply]
Oh, okay :) Since this is the preview module, anything that shows a preview would work (articles, userpages, images). I've put together a set of links at User:Sohom_Datta/sandy-box in case you want to test it out :) Sohom (talk) 11:55, 6 December 2023 (UTC)[reply]
Sandy box. Love that. Haha. In my testing, I found two differences between the old and the new.
  1. Templates now render, instead of displaying the wikicode. You can see this in your sandy box image examples. I think this is a feature not a bug. I think folks will like this. checkY
  2. Headings now have [ edit | edit section ] links that they didn't have before. And they are showing up a bit too big. I think they are the same size as the headings rather than body text. I think this should either be shrunk or hidden before we deploy this patch. This may involve changing MediaWiki:Gadget-navpop.css. ☒N
  3. Now that the other patch was merged, needs a rebase. ☒N
Novem Linguae (talk) 20:27, 7 December 2023 (UTC)[reply]
I won’t like if templates are rendered. Templates are not rendered for a reason: how templates making heavy use of parameters happen to render on their own page doesn’t say much about what they’re really are. They are oftentimes even partly or entirely <includeonly>d, so parts are left out from the preview. Couldn’t the namespace condition moved to before making the API request, so that the request is sent only for non-template pages, continuing to display template wikitext verbatim? —Tacsipacsi (talk) 15:37, 8 December 2023 (UTC)[reply]
I intend to take another stab at this next week, it seems to be fairly complicated to have templates not be rendered, I will see if we can maybe only the show the documentation somehow. Sohom (talk) 15:59, 15 December 2023 (UTC)[reply]

Article title hyperlinks in previews are black, not blue[edit]

Steps to reproduce: 1) vector 2010, not tested on other skins, 2) turn off navigation popups in Special:Preferences gadgets, 3) add the below code to User:abc/common.js, 4) hover over a valid article. What happens? Article title link is black. What should happen instead? Article title link is blue.

mw.loader.using(['mediawiki.api', 'mediawiki.user', 'mediawiki.util', 'user.options', 'mediawiki.jqueryMsg']).then(function() {
	importScript('w:User:Sohom Datta/parsingchange-popups.js');
	importStylesheet('w:MediaWiki:Gadget-navpop.css');
});

Looking at the code for .popup_mainlink a { color: #000; }, I think the devs intend for it to be black everywhere.

In the situation above, there are two CSS styles competing with each other. In one situation, .popup_mainlink a { color: #000; } wins out over the other styles. In the other situation, a:link, .mw-parser-output a.extiw, .mw-parser-output a.external, .vector-menu-portal .vector-menu-content li a { color: rgb(0,0,238); } wins out over the other styles.

Anyway, I think we should pick one color, then get it to be used consistently. Whether it's blue or black. I'm leaning blue.

I'm also curious why loading it as a non-gadget changes the CSS order of precedence, even though the two sets of selectors are identical. Perhaps there's a bug in the load code above? –Novem Linguae (talk) 20:37, 7 December 2023 (UTC)[reply]

Other talk page, and Phabricator[edit]

Looks like this gadget has another talk page at Wikipedia talk:Tools/Navigation popups, and also a tag on Phabricator. Just an FYI for folks who only know about this page. I only discovered these today. –Novem Linguae (talk) 08:20, 30 December 2023 (UTC)[reply]

History preview failed[edit]

can we change:

return 'History preview failed :-(';

to something like:

return popupString('History preview failed :-(');

for localization purpose? valepert (talk) 10:22, 31 January 2024 (UTC)[reply]

Want to sandbox it somewhere and make sure it works? Then tag this with {{IAER}}? Also, searching for "preview failed" reviews 5 spots we could apply this pattern to. –Novem Linguae (talk) 10:29, 31 January 2024 (UTC)[reply]
I made some test here, without CSS, and hovering "hist" on this page. I hope it's enough to evaluate the change. --valepert (talk) 13:57, 31 January 2024 (UTC)[reply]
@Valepert. Don't forget to tag this with {{IAER}} when it's ready to go. Also please provide a steps to test, and a diff of what you changed. This makes it easy for the reviewer. –Novem Linguae (talk) 22:36, 28 February 2024 (UTC)[reply]
please change "'History preview failed :-('" with "popupString('History preview failed')", adding "'History preview failed': 'History preview failed :-('," before "last:".
see diff.
step to test:
  1. visit Special:Contributions/2A02:C7F:745F:6400:69E1:8FB2:A675:2199
  2. hovering on "hist" of "100%" page
  3. expected message: "History preview failed :-("
--valepert (talk) 22:57, 28 February 2024 (UTC)[reply]
Implemented, thanks valepert. However, two things of note: first, there are a ton more error messages that are not similarly isolated. Second, I notice there's an unrelated bug in your example, where the % in the article title display is being unnecessarily URI-encoded, which breaks the link to the article itself. Writ Keeper  14:03, 29 February 2024 (UTC)[reply]

Feature request: Show Block reason[edit]

Is it possible to add the most recent block log entry (for currently blocked users) into the popup? Similar to how MediaWiki:Gadget-markblocked.js puts the reason in the tooltip. I have both scripts enabled, and it does strikethrough the username but Popups overrides the markblocked tooltip for blocked editors so I can't see the block reason without navigating away from the page I'm on to check the block log. I'd try building it myself based on the markblocked gadget, but my Javascript knowledge is very limited. The WordsmithTalk to me 21:11, 28 February 2024 (UTC)[reply]

Certain user permissions (extended confirmed, global renamer) not showing[edit]

Usually when you hover over a username, popups shows all their local permissions in regular text, and all their global permissions in italics. However, I've noticed a couple permissions are not showing up. In particular, extended confirmed (local) and global renamer (global). I propose fixing these two, and doing an audit to make sure there's not any other permissions being missed. If there's some hard-coded list in the code somewhere, I propose switching to something that is not hard-coded so that new permissions can be reliably detected without code modifcations. –Novem Linguae (talk) 04:13, 16 April 2024 (UTC)[reply]

I believe extendedconfirmed is an intentional omission. (No opinion in whether it should be.) Global renamer is, technically speaking, a local right on Meta, not a global right. See e.g. Special:CentralAuth/Tamzin. As a global renamer, I'd definitely find it useful to have that included here, but I'd think it'd require an extra API call just for that check? -- Tamzin[cetacean needed] (they|xe) 04:21, 16 April 2024 (UTC)[reply]
Yeah, looks like global renamer is local to meta and would require its own API call. Good find, thank you. –Novem Linguae (talk) 04:36, 16 April 2024 (UTC)[reply]
There could be a case for a no-permissions global group for global renamers, similar to VRT permissions agents, but I guess that would be a matter for Meta. -- Tamzin[cetacean needed] (they|xe) 04:38, 16 April 2024 (UTC)[reply]
"I believe extendedconfirmed is an intentional omission." correct. there are several groups (not permissions btw) that are filtered out because almost everyone has them. —TheDJ (talkcontribs) 08:22, 16 April 2024 (UTC)[reply]

eslint-config-wikimedia autofixes[edit]

In a sandbox, I ran the official wikimedia javascript linter on the popups code. Here's the diff.

  • ran eslint-config-wikimedia autofixes
    • extends { "wikimedia/client/es6", "wikimedia/jquery", "wikimedia/mediawiki" }
    • excluding
      • controversial ones such as space-in-parens and max-len
      • no-var (changing var to let/const). this would be fine to do since Grade A support is on ES6 now, but will save for a future patch
      • unicorn/prefer-string-slice. I'm not sure the suggested .slice( 0, Math.max( is more readable/better than the existing .substring(
      • some rules that weren't auto-fixing well when I manually reviewed the code
    • including rules such as comma-dangle, no-unneeded-ternary, no-useless-concat, operator-linebreak, semi-style, unicorn/prefer-date-now, dot-notation, jsdoc/check-tag-names, jsdoc/check-types, and others
  • removed some comments

Will self-merge in a couple days if no objections.

Note to self: Manually test a bit on testwiki before deploying. –Novem Linguae (talk) 06:36, 25 April 2024 (UTC)[reply]

I really dislike the "comma-dangle": "never" setting, it makes subsequent diffs less readable (and accounts for a large part of the current diff as well). Could you change it to only-multiline (or always-multiline if you prefer) and revert your changes that removed trailing commas? Thanks in advance!
Also, I don’t see any reference to this ESLint rule set in the code. Could you add a comment (even if not machine-readable) that informs future maintainers what they should lint the code with? —Tacsipacsi (talk) 19:41, 26 April 2024 (UTC)[reply]