MediaWiki talk:AFC-add-project-tags.js

Latest comment: 1 year ago by Xaosflux in topic Compatibility with Vector 2022

Move to MW request edit

Please move this page to MediaWiki:AFC-add-project-tags.js so that it can be loaded via mw:Snippets/Load JS and CSS by URL. Would be useful for Wikipedia:WikiProject Articles for creation/Add WikiProject tags to work.

This can be used to simplify the instructions in {{AFC submission}} under "Improving the odds of a speedy review" header (which are presently very hard for newbies to follow). But first, this pseudo-special-page needs to be functional before we can think about the next steps.

This will result in edits like this (the "assisted" word in edit summary will link to the MW script page.)

Pinging Enterprisey for a code review? (just so that everyone can be convinced that this script won't trigger mining of bitcoins or the like). – SD0001 (talk) 20:09, 1 September 2020 (UTC)Reply

@SD0001: I'm not loving having a new mediawiki js page that is then calling back to a userspace json page calling itself a js page. (User:Theo's Little Bot/afchwikiproject.js), the owner of which appears to be very inactive - is that part needed (can it be ported to a community managed page)? — xaosflux Talk 00:58, 3 September 2020 (UTC)Reply
In principle I agree. But User:Theo's Little Bot/afchwikiproject.js is used across the AFCH gadget, User:Enterprisey/draft-sorter.js, User:SD0001/draft-sort-burst.js, and toolforge:apersonbot/pending-subs. It makes sense for all these scritps/tools to get the wikiproject list from a single location to reduce maintenance overhead. If you're willing to move the page to projectspace and edit the gadget, go right ahead! But it isn't really urgent and probably better to do later after some discussion. – SD0001 (talk) 15:41, 3 September 2020 (UTC)Reply
For posterity, it has the json contentmodel, despite the ".js" in the page title. That's misleading, and I'd move it, but I'd have to also modify the scripts that use it, which might be a bit of a hassle. Enterprisey (talk!) 09:32, 25 December 2020 (UTC)Reply
  Done @SD0001: sorry for the delay on this one, I've moved it in to mediawiki space for you. If you have updates, please drop edit requests here and they will be handled by patrolling int-admins. — xaosflux Talk 15:32, 19 September 2020 (UTC)Reply

Update edit

Please sync with User:SD0001/AFC-add-project-tags2.js (compare)

Ok, so this script is popular! The original code was actually written in a hurry; this update brings a number of usability improvements:

  • The name of the draft page gets auto-filled with the name of the draft page from which the user is coming (it's stored in the URL query string).
  • If a selected wikiproject tag already existed on the talk page, it won't be added again.
  • A UI glitch which causes the vector navigation bars to show up above the dropdown is fixed.
  • Now using Wikipedia:WikiProject_Articles_for_creation/WikiProject_templates.json instead of User:Theo's Little Bot/afchwikiproject.js. This page isn't in userspace and more up-to-date. NOTE: this json page should probably be protected as well – at least semi – but extconf or template protection is I guess wiser.

SD0001 (talk) 11:11, 29 December 2020 (UTC)Reply

  Done — Martin (MSGJ · talk) 23:12, 29 December 2020 (UTC)Reply

Interface-protected edit request on 29 March 2021 edit

Hello, the current code of the script unfortunally contains a bug that rules out userspace drafts. Currently, when Users attempt to add WikiProject Tags to a draft residing in userspace, the script will fail in line 105-107. If the script is used to add WikiProject tags to something that isn't residing in draftspace, the value for subjectpage will always be undefined for pages not residing in draftspace. All the user gets is an erronous message that the page doesn't exist, while it yust has been filtered out a few code lines before. Therefore, I propose to change

			var subjectpage = data.query.pages.filter(function(pg) {
				return pg.ns === 118
			})[0];

to

			var subjectpage = data.query.pages.filter(function(pg) {
				return pg.ns === 118||pg.ns===2 //userspace drafts have a namspace id of 2
			})[0];

And as well:

			var talkpage = data.query.pages.filter(function(pg) {
				return pg.ns === 119;
			})[0];

to

			var talkpage = data.query.pages.filter(function(pg) {
				return pg.ns === 119|| pg.ns===3;//userspace draft talk pages have a namespace id of 3
			})[0];

Victor Schmidt (talk) 20:50, 29 March 2021 (UTC)Reply

@SD0001: any concerns? — xaosflux Talk 01:08, 30 March 2021 (UTC)Reply
I'm not SD0001, but I have a code review concern (and its fairly minor) - you should be consistent about the spacing in the new code. The first replacement has no space after ||, and a space before the comment, while the second replacement has a space after ||, and no space before the comment. Personally, I would prefer to have spaces both before and after ||, as well as before the comment, but regardless of what is used it should be consistent. Thanks, --DannyS712 (talk) 02:25, 30 March 2021 (UTC)Reply
Indeed a bug as userspace drafts are accounted for in the earlier part of the code but not here. I would suggest changing pg.ns === 118 in the first snippet to pg.ns % 2 === 0 and pg.ns === 119 in the latter snippet to pg.ns % 2 === 1 – this accurately captures the intent of telling whether it's a subject page or talk page. Anyway, this is a minor point as Victor Schmidt's code will also work just as well (and yeah let's make the spacings consistent as DannyS712 says). – SD0001 (talk) 06:13, 30 March 2021 (UTC)Reply
  Not done @Victor Schmidt: see feedback above. — xaosflux Talk 14:45, 6 April 2021 (UTC)Reply

Compatibility with Vector 2022 edit

The UI appears to be somewhat broken broken in Vector 2022 due to line 48-66 which adds the UI elements under every progessive button (Vector 2022 makes the language selector a progressive button, which leads the UI to be duplicated in the header). Due to this, I'd suggest changing line 48 from

$('.mw-ui-progressive').parent().replaceWith(

to

$('.mw-parser-output .mw-ui-progressive').parent().replaceWith(

to narrow down the specific element being selected.

Ping @SD0001 as the maintainer? of the script.

Regards, Sohom Datta (talk) 05:47, 18 January 2023 (UTC)Reply

LGTM. Thanks for catching this. – SD0001 (talk) 18:53, 18 January 2023 (UTC)Reply
  Donexaosflux Talk 01:38, 19 January 2023 (UTC)Reply