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.
|Open||Andreg-p||T208758 Extend Popups-Extension to render popups for annotated <math>|
|Open||Andreg-p||T229939 Use wikidata entity selector in OOUI input field|
@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.,
physical law: mass and energy are proportionate measures of the same underlying property of an object
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.
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:
- where can I add the option, that the popup not only considers links but also <math> environments with the qid-attribute?
- 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.
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?
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.
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?
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.