Code for usefulQueries
Documentation: https://www.wikidata.org/wiki/User:Kristbaum/usefulQueries
Queries that would be useful to general users can be added as suggestions on GitHub or on Wikidata.
You can add your own query templates to the project by reusing the existing JSON templates in templates/queries.
Steps:
-
Download this repo
-
Install npm
-
Copy one of the existing files from
templates/queriesand rename it for your new query (keep the.jsonextension). -
Edit the file following TEMPLATE_GUIDE.md (or give that file to an LLM and let it write the template).
-
Optionally add a link template in
templates/linksif your query integrates with an external viewer. -
Rebuild the project assets so the new template becomes available in the UI:
npm install npm run build
-
Copy
minified_usefulQueries.jsand upload it to a location like: https://www.wikidata.org/wiki/Special:MyPage/myUsefulQueries.js -
Replace the link in https://www.wikidata.org/wiki/Special:MyPage/common.js with your version.
The full reference, including fields, placeholders, where a button should hang, and how to write SPARQL that runs (hopefully) on both WDQS and QLever, is TEMPLATE_GUIDE.md. It is written as a self-contained documentation, so everything for writing your own queries templates should be in there.
In short, each button is one JSON file with a scope:
entity: next to the item title, on every item.property: next to a property label; for queries that use all of that property's values together, or none of them (the property just signals the right kind of item).value: next to each statement value; for queries whose answer depends on the clicked value ({valueQid}), or, withvalueId, for buttons that should only appear when a value matches (e.g. occupation = painter).
Adapt the settings in settings.json and rebuild using:
npm install
npm run buildWikibase Cloud / MediaWiki version compatibility: The popup feature relies on
CdxPopoverfrom the Codex design system, which is not available on every Wikibase Version. The script detects this at runtime and automatically falls back to opening the query as a plain link in a new tab instead of showing an inline popup.
A profile is a self-contained build with its own settings, templates and output, kept in a named subfolder and built with the --profile <Name> flag. Use one to target a different Wikibase, or to ship a separate set of buttons for Wikidata.
Expected folder layout for a profile named MyQueries:
MyQueries/
├── settings.json # Same format as src/settings.json
└── templates/
├── queries/ # Query template JSON files
└── links/ # Link template JSON filesBuild command:
node scripts/assemble.mjs --profile MyQueriesThe build will read MyQueries/settings.json, load templates from MyQueries/templates/queries/ and MyQueries/templates/links/, and write the output files into the same subfolder:
MyQueries/MyQueries_usefulQueries.js— readable outputMyQueries/minified_MyQueries_usefulQueries.js— minified output for upload
This is the same naming as the main build (usefulQueries.js / minified_usefulQueries.js), with the profile name as a prefix.
Missing queries/ or links/ subdirectories are silently ignored (treated as empty). The shared source files in src/ are always used, so only settings and templates need to be provided per profile.
Profiles in this repository:
ReSaNode/— targets the ReSaNode Wikibase Cloud instance.Deckenmalerei/— targets Wikidata, with queries for the Baroque ceiling painting corpus (deckenmalerei.eu ID, P10626).
sudo apt install npm
npm install # For linting tools
npm run build
# Optional
npm run lint- Make it Wikibase agnostic