Page MenuHomePhabricator

Fix the "Query is malformed" error in the "EasyQuery" JavaScript gadget on wikidata.org
Closed, ResolvedPublic

Description

To reproduce the problem:

image.png (706×1 px, 114 KB)

SPARQL-QUERY: queryStr=SELECT ?item ?label ?_image WHERE {
  ?item wdt:P2044 "4 <span class="wb-unit">metre</span>".
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" . 
    ?item rdfs:label ?label
  }
  
OPTIONAL { ?item wdt:P18 ?_image. }
}
LIMIT 100

The code to fix is located in https://www.wikidata.org/wiki/MediaWiki:Gadget-EasyQuery.js

When you work on this task, you can test the code and your changes by copy-pasting the code into the console (in Inspect element) of your web browser's developer tools. Once your code works as expected, upload your new version as a file into the Phabricator task. @Ladsgroup will review your code there.

Event Timeline

Aklapper added a subscriber: Ladsgroup.

@Ladsgroup: Could you elaborate where a contributor could find the code base to work on, how to test a potential fix, where to propose such a fix? Thanks!

@Aklapper: The code is: https://www.wikidata.org/wiki/MediaWiki:Gadget-EasyQuery.js, they can test it by copy-pasting it into console (in Inspect element), if they want to make a change, just copy past the new version here and I will review.

Aklapper renamed this task from EasyQuery gadget: Malformed query to Fix the "Query is malformed" error in the "EasyQuery" JavaScript gadget on wikidata.org.Nov 27 2017, 8:56 PM
Aklapper updated the task description. (Show Details)

Confirmed that the fact no longer has an ellipsis. I also tried an old revision, https://www.wikidata.org/w/index.php?title=Q1021880&oldid=463116190

The "triple dot link" is not showing on this Wikimedia page...

Yeah need to install the easy query gadget first, it is in https://www.wikidata.org/wiki/MediaWiki:Gadget-EasyQuery.js (you can copy-paste it in the console or enable it in gadget section in your preferences)

Here's the patched code:

Could you test it @Ladsgroup ?

When running your snippet in console, I get "org.openrdf.query.MalformedQueryException: Encountered " <STRING_LITERAL2> "\"Commons category\" "" at line 2, column 26." (link to query)

@Ladsgroup have you disabled the gadget (EasyQuery) first at your Wikidata account? I had the same problem before, it seems like caused by jQuery catched the wrong element when there are 2 3 dots buttons

Yes, you're right, Overall it's better to select based on class and id so nothing like this happens and it selects from the right element regardless of changes, but that can happen later.