Page MenuHomePhabricator

Display popups for annotated <math> tags
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 show a popup of some information from Wikidata, such as the description in the language $wgContLang.

  • As a preliminary step, we have implemented a special page that is shown, if one clicks on annotated math tags.
  • We have developed a demo that uses the popup extension to display that information in the popups extension https://gerrit.wikimedia.org/r/c/527547. However, this code can not be merged in its current shape.
  • Update the API to generate the content of the popup in HTML format independent of the mechanism that will be used to display the popup.
  • Decide if the Popups extension is best suitable for our use case or if we should consider alternatives.

Details

Related Gerrit Patches:
mediawiki/extensions/Popups : masterAdd popup support for annotated math
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

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)

Physikerwelt renamed this task from Extend Popups-Extension to render popups for annotated <math> to Display popups annotated <math> tags.Dec 11 2019, 6:31 PM
Physikerwelt updated the task description. (Show Details)
Physikerwelt renamed this task from Display popups annotated <math> tags to Display popups for annotated <math> tags.Dec 11 2019, 6:42 PM
Physikerwelt updated the task description. (Show Details)Dec 11 2019, 6:47 PM

To me, it sounds most reasonable to switch the API as outlined in T240458 as the next step. From there we can decide if we continue with the popups extension or just use a custom solution. This could then start as a gadget or beta feature. I liked tippy a lot, which I used for a research project. But the API is very handy and its really easy to implement.

,

TheDJ added a subscriber: TheDJ.Jan 13 2020, 3:02 PM

@Physikerwelt following up from our email, here is some design feedback:

Visual treatment on links
Imagine you are reading this section and you would like to see definitions for the equations. Some equations you can hover and the preview will appear, others will not show a preview because they have not been linked. The math equations that are linked should have some kind of visual treatment that indicates to people that you can hover over it and a preview will appear. I understand that you do not want to turn all math equations blue. Is there some other treatment you could explore here?

Interactivity
This goes along with the point above — when someone is hovering over a linked math equation there should be some visual indication (aside from the cursor changing) that the link is being hovered. As you can see with normal blue links when they are hovered an underline appears. This gives valuable feedback to the person using the website about what is happening, or what will happen if they click.

Layout of preview
Where can I see the latest example of how the preview will look? I've found this image on T239357 but I'm not sure if that's accurate.

@Physikerwelt following up from our email, here is some design feedback:
Visual treatment on links
Imagine you are reading this section and you would like to see definitions for the equations. Some equations you can hover and the preview will appear, others will not show a preview because they have not been linked. The math equations that are linked should have some kind of visual treatment that indicates to people that you can hover over it and a preview will appear. I understand that you do not want to turn all math equations blue. Is there some other treatment you could explore here?
Interactivity
This goes along with the point above — when someone is hovering over a linked math equation there should be some visual indication (aside from the cursor changing) that the link is being hovered. As you can see with normal blue links when they are hovered an underline appears. This gives valuable feedback to the person using the website about what is happening, or what will happen if they click.

Those two issues are important, but I think independet of the popup. I would move them to a seperate issue, ok?

Layout of preview
Where can I see the latest example of how the preview will look? I've found this image on T239357 but I'm not sure if that's accurate.

Yes. This is the current proposal.

@Physikerwelt ok, is there a separate task that exists? I think we should think of the visual treatment on links and interactivity as design requirements for this feature.

@alexhollender the two issues on the link are independent of the goodwill of the page preview team. We can just fix these drawbacks of the current implementation. For the popup itself, we need a commitment of the page preview team to that feature. Therefore I suggest we fix the hard things first and decide on an implementation plan for the popup feature. Or do you have other thoughts? I think it is important to join forces and move together in the same direction.

Andreg-p updated the task description. (Show Details)Mon, Feb 10, 10:57 AM

@alexhollender yes the picture is up to date.
I updated the picture in the issue description also.

The design is experimental. I split the textual description and the mathematical components and organized the components as a table on the right. It might look a bit squeezed.

If you have any suggestions about the design, we can easily change that.

Physikerwelt moved this task from Backlog to Next Up on the Page-Previews board.Tue, Feb 18, 8:55 AM