Page MenuHomePhabricator

Extend Popups-Extension to render popups for annotated <math>
Open, LowPublic

Description

The container element of <math> may contain a "data-qid" attribute that refers to a Wikidata element (see Change 471772). We want to use the Popups-Extension to show a popup of some information from Wikidata, such as the description in the language $wgContLang.

Details

Related Gerrit Patches:
operations/mediawiki-config : masterEnable links from math formulae on beta
mediawiki/extensions/Math : masterDelete Wikibase repository dependency in Math extension
mediawiki/extensions/Math : masterAdd special page and API endpoint that show information from math Wikibase items
mediawiki/extensions/Popups : masterAdd popup support for annotated math

Event Timeline

Andreg-p created this task.Nov 5 2018, 6:37 PM
Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 5 2018, 6:37 PM

@Andreg-p: Just to clarify and avoid misunderstandings: You plan to work on fixing this (as you set yourself as task assignee)?

Jdlrobson triaged this task as Low priority.Nov 6 2018, 12:18 AM
Physikerwelt added a comment.EditedNov 6 2018, 10:13 AM

@Aklapper as far as I understand @Andreg-p is motivated to work on that. I hope the documentation of the popups extension is good enough so that Andre is capable to generate popups for mathematical formula.
In the first step @Andreg-p adds the attribute qid to the math tag which is propagated to a data-qid to the dom.
In a subsequent step the popups extension / gadget should pick up this data-qid to fetch semantic information from wikidata.
For instance for <math qid=Q35875>E=mc^2</math> should generate a language dependent popup that fetches information from Q35875 e.g.,

mass–energy equivalence
physical law: mass and energy are proportionate measures of the same underlying property of an object
Parts:

I hope the main part of the project work is to develop the template what data to fetch from Wikidata and what to display. Hopefully the popups gadget/extension can be used to take care of the technical aspects of the formatting and browser specific solutions. Moreover, I hope that there is already code from Wikidata that can be used to get information from Wikidata.

@Andreg-p can you prepare a list of questions you have to the maintainers of the popup/wikibase extension respectively? Moreover, can you prepare some examples / mockups / screenshots how the popups should look like.

@Aklapper Yes, it's not really a fix but kind of an extension we (@Physikerwelt) and I are planning to accomplish.

As suggested by @Physikerwelt, I thought it might be a good option to extend the existing Popups-Extension (Mediawiki-Extensions-Popups). But since it is quite big, I would like to get a hint where I should start to implement changes in the extension. More precisely:

  1. where can I add the option, that the popup not only considers links but also <math> environments with the qid-attribute?
  2. where is the best place to implement the logic of building the Popup content?

I think it would be nice to get an overview of the structure of the extension.

For a better understanding of the goal, I created an image:

I choose the German version of the article, just to show that extracted information should also match the article language.

I needed to create a Title object from a special page. The popup extension I'm using use the javascript API. So I need an object of mw.Title (https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.Title) from a special page. However, I'm not able to generate the right Title... Does somebody know how to do it?

Thanks for the help!

@MaxSem : @Andreg-p managed to display a static page when hovering over equations; he also got the Wikidata id from the math extension. Now the missing piece is to display the content of a special page or an API endpoint that receives the Wikidata id as a parameter and returns the wikitext to be displayed.

I was able to detect the problems that avoid visualizing special pages.
The type of special pages is previewTypes.TYPE_GENERIC but the code currently only supports the cases in line 135 in src/ui/renderer.js.

If I treat special pages as a normal page, another problem appears. The mw.Api.get method (see mw.Api) is used in line 36 in src/gateway/mediawiki.js to fetch the data from mediawiki. However, the used method do not fetch the data with extracted text for special pages.

Does somebody know if I need to handle the get method differently for special pages to retrieve the information?

@Aklapper do you have an idea who could be able to help here?

@thiemowmde do have an idea why we cannot fetch text via TextExtracts from special pages? I want to visualize as special page in a popup but the result from mw.Api.get does not return text from special pages.

Another update.
After I requested some help from the #wikimedia-tech IRC channel it seems to be better not to use special pages to fetch the data from wikidata but extend the popups extension so that it performs the fetch from wikidata by its own. The problem is that special pages do not contain "text" in a sense that the TextExtracts extension can extract this text. The mods in the IRC channel mentioned changing the TextExtracts extension would be a major re-engineering effort. Since the popups extension handles page previews and reference previews differently already, it would make sense to just add a special case for wikidata previews to the extensions. It's questionable if the popups extension should handle math specific content, but it seems to be the best option we have.

Physikerwelt updated the task description. (Show Details)Jul 9 2019, 12:22 PM
cscott added a subscriber: cscott.Jul 16 2019, 4:24 PM

To expand on @Tgr's suggestion -- once the RESTBase page summary endpoint for wikidata items (T111231) is complete, it ought to be straightforward to use popups to display the appropriate summary for the linked wikidata item.

In the interim, adding some throwaway code that handled math-specific content specially as @Andreg-p said in his last comment, seems a reasonable way to get to a working proof-of-concept.

Hi everybody, I'm close to a prototype now. I created an extra API endpoint in the math extension and send requests to this endpoint if the user hovers over annotated math in the Popups extension.

Currently, I'm fetching the data just from Wikidata.org. Of course I should fetch the data directly from wikibase.
However, I cannot really find an appropriate way to do so. The Data access guide explains the endpoints, or mediawiki API calls. But there is nothing that tells me how to fetch the data directly from the wikibase via PHP.

Should I use the API endpoints from wikibase? I think the endpoints should not be used internally... Also in this case, I would call another API just from my API request in the math extensions, which seems a bit stupid also.

I have two specific problems with wikibase. How do I get the object that carries the information (such as label, properties, descriptions, etc.) and how can I access the information in the next step. I found the ItemContent.php class. But I don't know how to get the object and furthermore if this ItemContent actually carries labels, descriptions and so on, I don't know how to get them. The class does not provide methods for the info. Also, by the way, what's the difference between EntityContent and ItemContent?

Change 527547 had a related patch set uploaded (by AndreG-P; owner: AndreG-P):
[mediawiki/extensions/Popups@master] Add popup support for annotated math

https://gerrit.wikimedia.org/r/527547

Change 527556 had a related patch set uploaded (by AndreG-P; owner: AndreG-P):
[mediawiki/extensions/Math@master] Added support for popups for annotated math

https://gerrit.wikimedia.org/r/527556

It's not good that in order to add popups support for a particular extension (Math in this case) the Popups extension itself needs to be modified, and know about that extension. There should really be a public API for registering extra popups functionality, c.f. https://www.mediawiki.org/wiki/Manual:Extension_registration#Attributes

It's not good that in order to add popups support for a particular extension (Math in this case) the Popups extension itself needs to be modified, and know about that extension. There should really be a public API for registering extra popups functionality, c.f. https://www.mediawiki.org/wiki/Manual:Extension_registration#Attributes

I agree with you at 100%! However, we need to start from what's available. Currently, our goal is to push as much functionality to the math extension as possible and keep changes to the popup extension minimal.

MaxSem removed a subscriber: MaxSem.Sep 4 2019, 5:05 PM

It's not good that in order to add popups support for a particular extension (Math in this case) the Popups extension itself needs to be modified, and know about that extension. There should really be a public API for registering extra popups functionality, c.f. https://www.mediawiki.org/wiki/Manual:Extension_registration#Attributes

I agree with you at 100%! However, we need to start from what's available. Currently, our goal is to push as much functionality to the math extension as possible and keep changes to the popup extension minimal.

Perhaps, although this might be a good use case for defining what such a plugin system would look like.

Jdlrobson changed the task status from Open to Stalled.Oct 2 2019, 10:35 PM
Physikerwelt added a comment.EditedOct 3 2019, 12:16 PM

@Andreg-p what is the status here? I had the impression that this is almost done.

Andreg-p changed the task status from Stalled to Open.Oct 18 2019, 8:20 AM

Change 527556 merged by jenkins-bot:
[mediawiki/extensions/Math@master] Add special page and API endpoint that show information from math Wikibase items

https://gerrit.wikimedia.org/r/527556

Change 551180 had a related patch set uploaded (by Physikerwelt; owner: Physikerwelt):
[operations/mediawiki-config@master] Enable links from math formulae on beta

https://gerrit.wikimedia.org/r/551180

Change 551215 had a related patch set uploaded (by AndreG-P; owner: AndreG-P):
[mediawiki/extensions/Math@master] Delete Wikibase repository dependency in Math extension

https://gerrit.wikimedia.org/r/551215

Change 551215 merged by jenkins-bot:
[mediawiki/extensions/Math@master] Delete Wikibase repository dependency in Math extension

https://gerrit.wikimedia.org/r/551215

Change 551180 merged by jenkins-bot:
[operations/mediawiki-config@master] Enable links from math formulae on beta

https://gerrit.wikimedia.org/r/551180

Mentioned in SAL (#wikimedia-operations) [2019-11-19T07:33:31Z] <mobrovac@deploy1001> Synchronized wmf-config/CommonSettings-labs.php: Enable math links in Beta - T208758 (duration: 00m 53s)