Page MenuHomePhabricator

[SPIKE] How do we efficiently detect when the NavPopups gadget is enabled?
Closed, ResolvedPublic

Description

Ronseal.


Both T151058: Allow users who have navigational popups to use hovercards and the Page Previews settings behaviour require knowing when the NavPopups gadget is enabled.

Currently (in the master branch) we check whether the window.pg namespace has been created every time the user interacts with a preview-friendly link. This avoids polling at the expense of rigidity.

T151058 requires that we detect whether or not the user has enabled the gadget, which we have no way of doing without loading the entire codebase and waiting for the user to interact with a link.

How can we efficiently detect when the NavPopups gadget is enabled?


Ideas

  • Test whether the ext.gadgets.Navigation_popups RL module is in the "ready" state, i.e.
function isNavPopupsEnabled() {
  var module = mw.loader.moduleRegistry['ext.gadget.Navigation_popups'];

  return module && [ "loading", "loaded", "ready" ].indexOf( module.state ) !== -1; 
}

Event Timeline

phuedx created this task.Jan 4 2017, 11:55 AM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptJan 4 2017, 11:55 AM
ovasileva triaged this task as High priority.Jan 4 2017, 4:22 PM
ovasileva added a project: Readers-Web-Backlog.
ovasileva moved this task from To Triage to Upcoming on the Readers-Web-Backlog board.
pmiazga added a subscriber: pmiazga.EditedJan 4 2017, 5:55 PM

We can pass conflictsWithNavPopupsGadget as js variable :
@see https://gerrit.wikimedia.org/r/#/c/330432/1/includes/PopupsGadgetsIntegration.php

There is already a PHP logic within popups codebase to check if navPopups widget is defined and available

phuedx closed this task as Resolved.Jan 4 2017, 6:09 PM
phuedx claimed this task.
bmansurov added a subscriber: bmansurov.EditedJan 4 2017, 7:27 PM

I think the hardcoded popups gadget name "Navigation_popups" will only work on some wikis, possibly on enwiki only. This needs double checking. The quickest way I assume is to change the local wiki language and see if that code works.

phuedx reopened this task as Open.Jan 5 2017, 12:07 PM

@bmansurov: I think you're right. The "Navigation_popups" string comes from the MediaWiki:Gadgets-definition on the wiki, e.g. on en.wikipedia.org and mediawiki.org both define the "Navigation_popups" gadget but de.wikipedia.org defines the "navigation-popups" gadget.

So gadget names and sources can vary per-wiki. The former makes server-side checks difficult and the latter makes client-side checks difficult.

Notes from talking about this with @bmansurov, @jhobs, and @ovasileva:

The solution that @bmansurov came up with before (testing window.pg !== undefined) is Resilient/Timely Enough™

Other possible solutions that were discussed:

  • Contact wiki admins and plead with them to name gadgets consistently across wikis.
  • Hard-code the list of unique NavPopups gadget names and check if the user has enabled one of them.
  • Make all instances of the NavPopups gadget emit a notification that they've been loaded.
pmiazga added a comment.EditedJan 9 2017, 5:22 PM

@phuedx we can also put a config variable conlicts_with_gadget -> and put nav_popups gadget there. As Gadget is client-side only it's pretty difficult to check gadget existence in PHP

phuedx closed this task as Resolved.Jan 9 2017, 6:44 PM

@pmiazga: As discussed, a config variable with the name of the gadget is the most flexible/least brittle solution that allows both the server and the client to know when the user has the gadget enabled.

To handle those (power) users that've enabled the gadget via user scripts will be handled by a help message under the "Enable" radio. @ovasileva is going to add this as an AC to T151058: Allow users who have navigational popups to use hovercards .