Skip to content

Repository files navigation

UsefulQueries

Code for usefulQueries

Documentation: https://www.wikidata.org/wiki/User:Kristbaum/usefulQueries

Adding your own queries

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:

  1. Download this repo

  2. Install npm

  3. Copy one of the existing files from templates/queries and rename it for your new query (keep the .json extension).

  4. Edit the file following TEMPLATE_GUIDE.md (or give that file to an LLM and let it write the template).

  5. Optionally add a link template in templates/links if your query integrates with an external viewer.

  6. Rebuild the project assets so the new template becomes available in the UI:

    npm install
    npm run build
  7. Copy minified_usefulQueries.js and upload it to a location like: https://www.wikidata.org/wiki/Special:MyPage/myUsefulQueries.js

  8. Replace the link in https://www.wikidata.org/wiki/Special:MyPage/common.js with your version.

Writing a template

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, with valueId, for buttons that should only appear when a value matches (e.g. occupation = painter).

Run on another Wikibase

Adapt the settings in settings.json and rebuild using:

npm install
npm run build

Wikibase Cloud / MediaWiki version compatibility: The popup feature relies on CdxPopover from 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.

Profiles with --profile

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 files

Build command:

node scripts/assemble.mjs --profile MyQueries

The 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 output
  • MyQueries/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).

Development

sudo apt install npm
npm install # For linting tools
npm run build

# Optional
npm run lint

Todo

  • Make it Wikibase agnostic

Example Items

Contributors

Languages