Page MenuHomePhabricator

XTools ArticleInfo should fire on wikipage.content after it finishes
Closed, ResolvedPublicBUG REPORT

Description

The XTools ArticleInfo gadget/script doesn't run mw.hook('wikipage.content').fire(...) after modifying the DOM. This prevents some scripts from being able to act on changes made by ArticleInfo. In particular, this happens the first time ArticleInfo queries a username (which is slower than subsequent queries). While it's possible for scripts to detect the changes with a MutationObserver, it seems like the intent of the hook is to keep things simple for script developers.

Steps to replicate the issue (include links if applicable):

  • On English Wikipedia, load a user page in safemode (e.g., https://en.wikipedia.org/wiki/User:Jimbo_Wales?safemode=1).
  • Open the Developer Tools JavaScript console.
  • Paste this and hit enter to run both statements together: mw.loader.load('https://www.mediawiki.org/w/index.php?title=XTools/ArticleInfo.js&action=raw&ctype=text/javascript'); importScript('User:Novem Linguae/Scripts/UserHighlighterSimple.js');

What happens?:

  • If XTools hasn't been run on a page/user recently, it's generally slower, so UserHighlighterSimple.js will fail to see the added elements, and the username part of "created by: Jimbo Wales" won't be highlighted in pink. If you reload the page and rerun the scripts, it will usually be pink on subsequent runs.
  • (If it doesn't reproduce, try a page/user less likely to have been queried recently in XTools.)

What should have happened instead?:

ArticleInfo should properly notify other gadgets/scripts that it has changed the wiki page contents. For the above example, the UserhighlighterSimple script would highlight the username as pink the first time.

Other information (browser name/version, screenshots, etc.):

I'm using a Chromium-based browser.

While this is noted as a "TODO" at the bottom of https://en.wikipedia.org/wiki/User:Novem_Linguae/Scripts/UserHighlighterSimple.js, it seems like the fix should be done in ArticleInfo.

Event Timeline

DanielQ updated the task description. (Show Details)
MusikAnimal subscribed.

@DanielQ @Novem_Linguae Done with mw:Special:Diff/6421280 / a866a35.

Note that it looks like UserHighlighterSimple.js reprocesses the entire page every time wikipage.content is fired. For performance reasons, it should probably go off of the $content element returned by the hook to process only content that changed.

PS – re line 323 "TODO: hook for after visual editor edit is saved?": I think you may be looking for the postEdit hook. That doesn't narrow it down to just VE, but will cover any scenario where postEdit is fired from a AJAX-based edit (i.e. HotCat), which isn't limited to VE.


I'm moving this to "pending deployment" as the commit isn't there yet and thus https://xtools.wmcloud.org/articleinfo-gadget.js is outdated, but the gadget has been updated.

I made some updates, and that postEdit hook works great. Thank you for that!

Switching to $content is not a simple fix because the user script only highlights links that have certain parent elements. Might be hard to check for parent elements such as #article a if $content only contains some of the page's elements. But I will add a code comment about it.

MusikAnimal moved this task from Pending deployment to Complete on the XTools board.