Page MenuHomePhabricator

Implement wikidata entity selector in OOUI input field
Closed, ResolvedPublic

Description

In the current draft of the Special Page

Screenshot_2019-08-06 Wikidata Information of Mathematical Items - Math Beta (en)(1).png (242×579 px, 11 KB)

(source http://beta.math.wmflabs.org/w/index.php/Special:MathWikidata)

the Wikidata input field has no auto-completion feature.
Based on my experience from
https://github.com/ag-gipp/node-codemirror-wikidata
I have the feeling that it should be rather easy to enable autocompletion for Wikidata entries.

Update: This has been implemented and deployed. However, the current approach

https://en.wikipedia.org/wiki/Special:MathWikibase

does not work and shows the following error:

Skipped unresolvable module ext.math.wikibase.scripts
Unknown module: jquery.wikibase.entityselector

Event Timeline

Physikerwelt renamed this task from Use wikidata autocompletion information field in wikidata OOUI input field to Use wikidata entity selector in OOUI input field.Aug 6 2019, 4:35 PM

@Physikerwelt an autocompletion on wiki data IDs? I would understand if we allow textual inputs here and then activate auto-completion based on the words. Such as "mass-energy" and the first suggestion would be "equivalence". But I cannot imagine an auto-completion just based on the IDs. The only use case I can imagine is that the auto-completion only shows IDs that actually contain mathematical expressions. But I have no clue how to implement that now.

@Andreg-p I mean this selector

grafik.png (1×1 px, 92 KB)

I think @hoo might now if this can be used in your form.

Please have a look at jQuery.wikibase.entityselector (can be loaded via the jquery.wikibase.entityselector RL module). I didn't test it, but that should just work.

Thank you for the hint. Patch set 5 should include all necessary changes to close this task: https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Math/+/527556/

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

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 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

from the JS console in https://www.mediawiki.org/wiki/Special:MathWikibase

Error: "Unknown module: jquery.wikibase.entityselector"

I checked, and the module "jquery.wikibase.entityselector" still exists. But it might be that it is not loaded by default any more. You need to request it, either via "dependencies" in the definition of your ResourceLoader module, or via $parserOutput->addModules( … ) in your PHP code, or via mw.loader.using( … ) in your JavaScript code. Without knowing much about your code, I assume the last option would be the best.

@thiemowmde Thank you. The problem is, I thought I did that already. I load the modules in the special page:
https://github.com/wikimedia/mediawiki-extensions-Math/blob/master/src/SpecialMathWikibase.php#L64

		$output->addModules( [ 'ext.math.wikibase.scripts' ] );

And the module is defined in Math's extension extension.json:
https://github.com/wikimedia/mediawiki-extensions-Math/blob/668892f33b118e1d3970e2ff73ea64dbfaf8eb3d/extension.json#L148-L153

		"ext.math.wikibase.scripts": {
			"scripts": "ext.math.wikibase.js",
			"dependencies": [
				"jquery.wikibase.entityselector"
			]
		},

That looks right.

It might be that the module is not available on a client any more, only in a Repository context. However, when I look at the code it looks like it should always be available. Maybe @Ladsgroup or somebody else currently working on Wikibase can have a look?

Well, that module is part of the WikibaseView extension, which we don’t load on client wikis – I don’t think this has changed recently, at least it’s also the case on English Wikipedia, which is currently running Wikibase code from 4/5 November (1.35.0-wmf.5).

Edit: ah, the thing that changed recently would be this:

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

Well, that module is part of the WikibaseView extension, which we don’t load on client wikis – I don’t think this has changed recently, at least it’s also the case on English Wikipedia, which is currently running Wikibase code from 4/5 November (1.35.0-wmf.5).

I guess the code is still deployed. Is there a way to manually load the module for the specialpage?

Edit: ah, the thing that changed recently would be this:

This explains why we don't see it in our local dev setup.

I don't see that there is anything that can be done from within the math extension.

I am seeing similar problems on test.wikidata.org

wikidata.png (873×1 px, 163 KB)

Also T228641 might be related.

I am seeing similar problems on test.wikidata.org

wikidata.png (873×1 px, 163 KB)

Also T228641 might be related.

Test wikidatawiki is a repo so it should not be related to this.

I am not sure how to move forward here. @Esanders, do you have a hypothesis? What might be the problem here? I think the approach to use $output->addModules and specify the dependencies there is not fundamentally incorrect as outlined here
https://phabricator.wikimedia.org/T229939#5699422 but maybe the loader does not load all dependencies recursively? Or are other sources for the problem more likely?

@thiemowmde do you have by chance any idea how we can make progress here? I simply don't know what to do next.

As far as I understand the issue is that whatever method you choose to load a module, it only works when the module is known, i.e. it is registered in the extension registration. The jquery.wikibase.entityselector module is part of WikibaseView. I had a closer look, and the official way to load it is currently via wfLoadExtension( 'extension-repo.json" ), i.e. it is loaded together with the WikibaseRepo extension registration. Is WikibaseRepo loaded every time the Math code that needs the module runs? According to https://en.wikipedia.org/wiki/Special:Version it is not – and probably shouldn't.

One possibly way forward is to move the module from WikibaseRepo to WikibaseClient. I'm not sure how hard this is, because everything it depends on would need to move as well.

Another way forward might be to extract the module into an entirely separate codebase with it's own extension registration.

@thiemowmde The code is only executed when a user visits the special page. Maybe loading the WikibaseRepo code entirely would make sense since communication with the wikibase repo is required to figure out which entries exist. If the module would be factored out that would be (as I understand) a major change in the Wikibase software architecture. I think the cost for that would not warrent the effort.

No, please don’t load WikibaseRepo on Client wikis. Client and Repo are separate extensions for a reason.

I am still confused. Are there no other situations where one needs to select a Wikidata item in Wikipedia? For instance, if one wants to connect a page with its Wikibase item. At one time there was an "add links" button that you could click and then a js popup came. Now it redirects to wikibase on beta https://en.wikipedia.beta.wmflabs.org/wiki/Selenium_Echo_link_test_0.9941241391257276_0.9941241391257276

However, besides there must be uses of that.

@Physikerwelt, sorry for not responding earlier. My advice is: don't use jquery.wikibase.entityselector. Write your own code, ideally based on OOUI, not jQuery. Seriously. It's your code then, and it does exactly what you want, which isn't that much. The existing entityselector code appears complicated, but it really doesn't do much. All it essentially does is querying the wbsearchentities API. There is a bit of caching on top, and a lot of configuration you probably don't need.

The probably only configuration you need is the address of the API, because you want to query the Wikidata server from e.g. the English Wikipedia. On wikis with WikibaseRepo enabled this is exposed to JavaScript as part of the wbRepo configuration, see \Wikibase\Lib\Modules\RepoAccessModule. You might need to expose this configuration yourself on your special page (but only on the special page). This can be done directly in the special page's class using e.g. \ResourceLoader::makeConfigSetScript().

@thiemowmde ok. I only need two variables language and action API url endpoint. The hard part will be to get these values the rest I did for another project already https://www.npmjs.com/package/codemirror-wikidata However, it somehow feels like reinventing the wheel again. I will use the OOUI completion as recommended here T85394.

I might oversimplify this, but exposing the API endpoint should be possible like that:

In SpecialMathWikibase.php
$settings = WikibaseClient::getDefaultInstance()->getSettings();
$url = $settings->getSetting( 'repoUrl' );
$scriptPath = $settings->getSetting( 'repoScriptPath' );
$this->getOutput()->addJsConfigVars( 'repoApiUrl', $url . $scriptPath . '/api.php' );
In ext.math.wikibase.js
var repoApiUrl = mw.config.get( 'repoApiUrl' );

For the language, the code currently uses mw.config.get( 'wgContentLanguage' ). I think this is fine. It's what I would do as well.

Physikerwelt renamed this task from Use wikidata entity selector in OOUI input field to Implement wikidata entity selector in OOUI input field.Sep 20 2020, 8:59 AM

@thiemowmde ... I am still working on this... it is difficult for me to set up wikidata on my dev instance without js warnings... I see exceptions like

[105223064898a872602238d1] /load.php?lang=en&modules=jquery%2Coojs%2Coojs-ui-core%2Csite%7Cjquery.client%2Cspinner%2Cthrottle-debounce%2Cui%7Cjquery.event.special.eachchange%7Cjquery.spinner.styles%7Cjquery.ui.suggester%7Cjquery.wikibase.entityselector%7Cmediawiki.String%2CTitle%2Capi%2Cbase%2Ccldr%2Cdebug%2CjqueryMsg%2Clanguage%2Cutil%7Cmediawiki.libs.pluralruleparser%7Cmediawiki.page.ready%7Coojs-ui-core.icons%2Cstyles%7Coojs-ui.styles.indicators%7Cskins.vector.legacy.js%7Cuser.defaults%7Cutil.inherit%7Cwikibase.ui.entitysearch&skin=vector&version=1uw4m   RuntimeException from line 485 of /var/www/html/includes/resourceloader/ResourceLoaderFileModule.php: ResourceLoaderFileModule::getFileContents: script file not found, or is not a file: "/var/www/html/extensions/Wikibase/view/lib/wikibase-data-values-value-view/lib/jquery.ui/jquery.ui.suggester.js"
Backtrace:
#0 /var/www/html/includes/resourceloader/ResourceLoaderFileModule.php(907): ResourceLoaderFileModule->getFileContents(string, string)
#1 /var/www/html/includes/resourceloader/ResourceLoaderFileModule.php(362): ResourceLoaderFileModule->readScriptFiles(array)
#2 /var/www/html/includes/resourceloader/ResourceLoaderModule.php(736): ResourceLoaderFileModule->getScript(ResourceLoaderContext)
#3 /var/www/html/includes/resourceloader/ResourceLoaderModule.php(704): ResourceLoaderModule->buildContent(ResourceLoaderContext)
#4 /var/www/html/includes/resourceloader/ResourceLoader.php(1191): ResourceLoaderModule->getModuleContent(ResourceLoaderContext)
#5 /var/www/html/includes/resourceloader/ResourceLoader.php(899): ResourceLoader->makeModuleResponse(ResourceLoaderContext, array, array)
#6 /var/www/html/load.php(51): ResourceLoader->respond(ResourceLoaderContext)
#7 /var/www/html/load.php(38): wfLoadMain()
#8 {main}

and I am not 100% that this is unrelated to the problem we are working on in this ticket.

@Physikerwelt Nowadays we pull in some of the (JS) libraries using git submodules. Are your submodules in Wikibase all initialized and up to date?

Change 638094 had a related patch set uploaded (by Physikerwelt; owner: Physikerwelt):
[mediawiki/extensions/Math@master] Implement wikidata entity selector

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

@thiemowmde @Esanders @Lucas_Werkmeister_WMDE I am unsure how to proceed here. Is there anything I can do to get the patch merged? I think it is ok in its current form. Also for the ResourceLoader question, I got additional feedback by @awight https://lists.wikimedia.org/pipermail/wikitech-l/2020-December/094094.html . As the module will also be used to select the qid in the visual editor I think merging those two modules would not be desirable (if it was technically possible).
Any feedback would be highly appreciated. I am not afraid of additional effort. I just don't know what else to do to get this little inconvenience fixed.

I know this is frustrating. WMDE staff is happy to help, but is currently not in a position to invest substantial resources into the Math extension. According to https://www.mediawiki.org/wiki/Developers/Maintainers the owner of the extension is the WMF editing team (lead by @Esanders), as well as @TheDJ and you. My personal opinion: When there aren't any objections from Ed or their team, this might be one of the rare situations where it's fine to self-merge your own patch. 🤷‍♂️

@thiemowmde thank you for your prompt reply. I am not confident enough to self-merge this. The interplay of PHP and JS code is too frightening to me. If it was just a PHP or JS code I might have a different opinion, but in this case, I think self-merging is not an option.

this might be one of the rare situations where it's fine to self-merge your own patch. 🤷‍♂️

No. It isn't.

James, such a passive-aggressive tone is inakzeptable. If you are unable to explain yourself then please don't comment, especially if you are not even asked for your opinion.

James, such a passive-aggressive tone is inakzeptable. If you are unable to explain yourself then please don't comment, especially if you are not even asked for your opinion.

Sorry, I'll be clearer, rather than assume you remembered the policy:

Please do not ever give such shockingly, grossly inappropriate and unprofessional advice, which is directly in contravention of the policy to which you agreed when given C+2 rights. If you do it again, I will feel obliged to proposed that your C+2 rights are removed, per that policy.

I feel sorry. I did not intend to start a discussion on the principle of +2 in general. To put the problem in a simple picture.

Currently, I see the following situation:

production-bug.png (364×1 px, 159 KB)

On the left side, you see a screenshot of Wikipedia and on the right side, you see a screenshot of Wikidata. On the Wikidata side, you can enter text to select a QID, and on the Wikipedia side, you don't see a dropdown but an error in the javascript console (if you have that opened). This is because Wikipedia has not the Wikibase repo extension enabled, which contains the dropdown code. I implemented the code to fix that following the recommendations and discussion in this ticket. Here the advice of @thiemowmde (how is a Wikibase expert) was essential for the implemented solution. Also, the +1 code review from @Esanders suggests that there is no obvious flaw from the OOUI perspective. Even though my feeling is that the solution I implemented is not optimal, I am not aware of a better solution nor of anyone who could help to implement a better solution with reasonable effort. Therefore, I am hoping for a final go. One alternative I see is to consult CPT as they help with mathoid and restbase related code in extension math. On the other hand this problem is just UI and not related to mathoid.

Physikerwelt lowered the priority of this task from High to Medium.Dec 13 2020, 8:21 AM

Regarding that why number of RL modules should be kept at minimum T264334#6523308 might be useful. TLDR, it's a cost to get a way bigger gain.

Change 649718 had a related patch set uploaded (by Physikerwelt; owner: Physikerwelt):
[mediawiki/extensions/Math@master] WIP: Implement wikidata entity selector

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

Change 649718 abandoned by Physikerwelt:
[mediawiki/extensions/Math@master] WIP: Implement wikidata entity selector

Reason:

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

Change 638094 merged by jenkins-bot:
[mediawiki/extensions/Math@master] Implement wikidata entity selector

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

Eventually it works on enwiki. Thank you @Ladsgroup for your great support, which was significant to complete this task after 1.5 years of perplexity.