User talk:EpochFail/ArticleQuality-system.js

From Meta, a Wikimedia project coordination wiki

TypeError[edit]

@EpochFail and Ladsgroup: when I run pages in debug mode, I get the following error caused by this script:

TypeError: mw.Api is not a constructor

I see that the code does not use mw.loader.using( ['mediawiki.api'] ), which would guarantee that the code is not run until mw.Api is available; as an example, compare with en:User:TheDJ/signatureChecker.js

Would you mind add the using statement to this code, to make the error go away? Huji (talk) 01:03, 5 February 2019 (UTC)[reply]

Hi Huji! I'm not 100% sure where to put the loader.using call because we don't directly instantiate the ArticleQuality class inside of the main system js. Instead, it gets instantiated with configuration on each wiki we load the system from. E.g. see en:User:EpochFail/ArticleQuality.js and eu:User:EpochFail/ArticleQuality.js. So I have decided to wrap the whole definition of ArticleQuality in the main system.js otherwise we'd have to repeat the dependency in each instantiation. I think this will work as intended. What wiki are you working from? --EpochFail (talk) 21:02, 5 February 2019 (UTC)[reply]
@EpochFail: fawiki; and your change did not make the error go away. But your comment made me realize that I should also verify that our local script calls the correct dependencies. Turns out, it didn't, so I added it and now the error is gone. Perhaps undo your change here, and let me see if the error reappears (it shouldn't)? 23:39, 5 February 2019 (UTC)

Help installing[edit]

Hello, I'm trying to get the gadget that gives me an article quality rating based on analysing the text with ORES... is this the right tool? I'm having terrible trouble trying to get it installed. Is it as simple as trying to use importScript() on my Wikipedia User/vector.js page? Is there some up to date documentation I have missed? Any help appreciated, cheers — Jonathanischoice (talk) 23:25, 8 November 2019 (UTC)[reply]

Five minutes later - here's the answer, and thanks for your very nifty tool! It's ArticleQuality-loader.js that we need. Jonathanischoice (talk) 23:46, 8 November 2019 (UTC)[reply]
Hi! I'm new to the Wikimedia ecosystem and am confused on how to go about installing this script. I see that @Jonathanischoice: has mentioned ArticleQuality-loader.js, but I'm not able to track that down. Any help would be greatly appreciated!--A username can have spaces? (talk) 23:57, 18 January 2021 (UTC)[reply]
I am also confused. Do I need to edit something on this page?: https://en.wikipedia.org/wiki/User:EMsmile/vector.js I think I've done it once before but it's a long time ago so I have forgotten. EMsmile (talk) 09:35, 31 August 2022 (UTC)[reply]
On the wiki you'd like to enable the script, add importScript("User:EpochFail/ArticleQuality.js") to your common.js page. For me, on English Wikipedia, this is en:User:EpochFail/common.js. --EpochFail (talk) 15:57, 31 August 2022 (UTC)[reply]
Thanks! EMsmile (talk) 09:02, 1 September 2022 (UTC)[reply]

Scores for old revisions[edit]

@EpochFail: When someone follows a permanent link to an old version, or an old diff, the script shows the score for the latest version of the page, instead of the revision which is shown. What do you think about replacing mw.config.get('wgCurRevisionId') by mw.config.get('wgRevisionId'), so the system presents ORES scores for the specific revision users are seeing? Helder 11:39, 28 April 2020 (UTC)[reply]

Oooh! I looked into this in the past and I couldn't find something that would work like that. wgRevisionId is a gret idea. --EpochFail (talk) 16:14, 28 April 2020 (UTC)[reply]
Done in Special:Diff/20021929 --EpochFail (talk) 16:26, 28 April 2020 (UTC)[reply]

Uncaught TypeError for deleted revisions[edit]

@EpochFail: When I open https://pt.wikipedia.org/w/index.php?title=Aresta&action=history and run the script, I get the following error:

index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript&_=1589883394693:260 Uncaught TypeError: Cannot read property 'probability' of undefined
    at ArticleQuality.computeWeightedSum (index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript&_=1589883394693:260)
    at ArticleQuality.renderHistoryScore (index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript&_=1589883394693:341)
    at ArticleQuality.<anonymous> (index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript&_=1589883394693:352)
    at fire (load.php?lang=pt&modules=ext....&version=w6uv8:125)
    at Object.fireWith [as resolveWith] (load.php?lang=pt&modules=ext....&version=w6uv8:126)
    at Object.deferred.<computed> [as resolve] (load.php?lang=pt&modules=ext....&version=w6uv8:129)
    at ArticleQuality.<anonymous> (index.php?title=User:EpochFail/ArticleQuality-system.js&action=raw&ctype=text/javascript&_=1589883394693:294)
    at fire (load.php?lang=pt&modules=ext....&version=w6uv8:125)
    at Object.fireWith [as resolveWith] (load.php?lang=pt&modules=ext....&version=w6uv8:126)
    at Object.deferred.<computed> [as resolve] (load.php?lang=pt&modules=ext....&version=w6uv8:129)

This is caused by the line .done(function(scoreDoc){dfd.resolve(scoreDoc[this.modelName].score)}.bind(this)) inside oresScore, when scoreDoc gets the following value:

{
	"articlequality": {
		"error": {
			"message": "TextDeleted: Text deleted (datasource.revision.text)",
			"type": "TextDeleted"
		}
	}
}

due to the deleted edit made by 191.253.130.73. Helder 10:39, 19 May 2020 (UTC)[reply]

Uncaught TypeError for deleted pages[edit]

When I access this page, which contains links to pages that were deleted, I get

Uncaught TypeError: data.query.pages[0].revisions is undefined

I've fixed this in my copy with this change. Helder 14:17, 10 July 2020 (UTC)[reply]

Done Thank you! Sorry it took me so long to fix. --EpochFail (talk) 23:09, 29 September 2020 (UTC)[reply]

Your revert on User:EpochFail/ArticleQuality-system.js[edit]

Here there! Your recent revert on https://meta.wikimedia.org/w/index.php?title=User:EpochFail/ArticleQuality-system.js&oldid=prev&diff=20492048 has led to the throwing JavaScript errors again in our production log.

You mentioned that my edit broke your script, but I'm not sure how, so could you expand? What error were you seeing?

Note your code is broken as it's essentially the same as:

mw.loader.using(['mediawiki.api']).done();
callback()

When really what you want is

mw.loader.using(['mediawiki.api']).done(callback);

The problem with doing this is that mw.Api will not be defined until the done handler is executed. When using "done" you must pass a function, not an immediately invoked function -as that will be immediately invoked.

Note, "done" is also a deprecated method and I would suggest using "then" instead. https://stackoverflow.com/questions/5436327/jquery-deferreds-and-promises-then-vs-done may be helpful.


I think the following may work better for you:

(function($, mw){
   mw.loader.using(['mediawiki.api']).done(function () {
      ...
   });
})(jQuery, mediaWiki)


Jon (WMF) (talk) 20:59, 29 September 2020 (UTC)[reply]

Hey Jon! Indeed, it looks like your modification forgot to pull jQuery and mediaWiki into the context so the script no longer executed. Essentially, after your change, window.ArticleQuality was undefined! I got some user reports that the script was broken soon after your change so I reverted it. I haven't had the time to look into it yet, but I think your proposed change looks fine. It shouldn't have executed the code until mediawiki.api had loaded so that was definitely a mistake -- that it seems no one noticed until now. --EpochFail (talk) 21:13, 29 September 2020 (UTC)[reply]
I just ran an experiment and found that then() didn't work as expected so I switch back to done() and things worked again. How strange! I can demonstrate that then() works by running mw.loader.using(['mediawiki.api']).then(function(){console.log("then is happening")}) in my console! I'll need to experiment more later. --EpochFail (talk) 21:24, 29 September 2020 (UTC)[reply]
Weird... $ and window and mw should be globally available. Your existing code looks fine and so far no errors.. :) Jon (WMF) (talk) 22:35, 29 September 2020 (UTC)[reply]

Extract from indicators[edit]

Adding this to indicators makes it appear on the right side, instead of the left side. It is unbalanced, and baroque. This should be OUTSIDE the indicators. -Theklan (talk) 20:23, 27 January 2022 (UTC)[reply]

URLs with "undefined"[edit]

Hi User:EpochFail!

I believe this edit needs a follow-up to pass li.attr('data-mw-revid') to formatScoreHeader. Otherwise we get history entries with URLs like this

[https://ores.wikimedia.org/v3/scores/enwiki/undefined/articlequality 1.98]

Helder 15:51, 2 March 2024 (UTC)[reply]