Movatterモバイル変換


[0]ホーム

URL:


Hub

This is aWeb hub: it let's you craft URLs to go from anorigin to adestination on the web, at the condition that you provide enough information on those points to be identified withinWikidata. It works primarily around Wikimedia sites, but given the amount Wikidata knows about the web at large, it can get you pretty far! And if you don't know where you want to go, that's ok too: this will just bring you to the closest Wikipedia article.

Target audience:

A few examples to catch your interest:

we can now link to Wikipedia articles about a concept in the user's favorite language:

but, after choosing your starting point, you can also customize your destination:

for your next prototype, illustrate your concepts the lazy way:

imagesrc
image example/frwiki:Laniakea?property=image&width=256

Summary

User Guide

Every URL is built asa bridge between two points, an origin and a destination:

The separation between the origin and the destination is expressed in the URL by the?: everything before the? aims to identify the origin, everything after identifies the destination.

Example:

Origin

Wikidata id

As the real hub in this story is Wikidata, every request needs to first resolve to a Wikidata id, which can thus be considered the primary origin point:

requestredirection
/Q1https://en.wikipedia.org/wiki/Universe
/Q2https://en.wikipedia.org/wiki/Earth
...
/Q1388426https://en.wikipedia.org/wiki/Bo%C3%ABn-sur-Lignon

Wikipedia and other Wikimedia Project

Alternatively to a Wikidata id, you can pass a key built from sitelinks as starting point, defaulting toenwiki.

requestredirection
/frwikivoyage:Allemagnehttps://en.wikipedia.org/wiki/Germany
/eswikinews:Categoría:Alemaniahttps://en.wikipedia.org/wiki/Germany
/ocwiki:Alemanha?lang=dehttps://de.wikipedia.org/wiki/Deutschland
/ocwiki:Alemanha?lang=el,fa&site=wikivoyagehttps://el.wikivoyage.org/wiki/%CE%93%CE%B5%CF%81%CE%BC%CE%B1%CE%BD%CE%AF%CE%B1
/enwiki:Edward_Snowden?property=P2002https://twitter.com/Snowden
/enwiki:DIY?site=wikidatahttps://www.wikidata.org/wiki/Q26384
/DIY?site=wikidatahttps://www.wikidata.org/wiki/Q26384

External Ids

requestredirection
/P214:24597135https://en.wikipedia.org/wiki/Isaac_Asimov
/viaf:24597135https://en.wikipedia.org/wiki/Isaac_Asimov
/twitter:doctorowhttps://en.wikipedia.org/wiki/Cory_Doctorow

Destination

Default

By default, the destination is Wikipedia in the user language, which is guessed from the requestaccept-language header, falling back to English if the language header can't be found or the Wikipedia page doesn't exist in this language.

requestredirection
/Q184226https://en.wikipedia.org/wiki/Gilles_Deleuze

Wikimedia Projects

lang

Pass alang parameter (or justl) to override theaccept-language header. Pass several values to set the fallback chain. The valueauto can be used to represent the value of theaccept-language header.

requestredirection
/Q184226?lang=frhttps://fr.wikipedia.org/wiki/Gilles_Deleuze
/Q184226?lang=als,oc,auto,fr,en&site=wikiquotehttps://oc.wikipedia.org/wiki/Gilles_Deleuze
site

Pass asite parameter (or justs) to redirect to another site thanwikipedia. Pass several values to set the fallback chain. When combined with alang fallback chain, the site fallback has priority.

requestredirection
/Q184226?site=wikiquotehttps://en.wikiquote.org/wiki/Gilles_Deleuze
/Q184226?site=wikivoyagehttps://en.wikipedia.org/wiki/Gilles_Deleuze
/Q184226?site=wikivoyage,wikiquotehttps://en.wikiquote.org/wiki/Gilles_Deleuze
/Q184226?site=wikiquote&lang=frhttps://fr.wikiquote.org/wiki/Gilles_Deleuze
/Q184226?site=wikivoyage,wikiquote,wikipedia&lang=als,oc,fr,enhttps://fr.wikiquote.org/wiki/Gilles_Deleuze

This can also include sites that can build URLs from Wikidata ids:

requestredirection
/Q23936146?site=crotoshttp://zone47.com/crotos/?q=Q23936146
/Q184226?site=inventairehttps://inventaire.io/entity/wd:Q184226
/Q638519?site=monumentalhttps://monumental.toolforge.org/#/object/Q638519
/Q184226?site=portalhttps://portal.toolforge.org/Q184226
/Q184226?site=reasonatorhttps://reasonator.toolforge.org/?q=Q184226
/Q184226?site=scholiahttps://scholia.toolforge.org/Q184226
/Q184226?site=sqidhttps://sqid.toolforge.org/#/view?id=Q184226

short site names

You can use short versions of those sites names:

longshort
wikidatawd
wikipediawp
commonsc,wc
wikisourcews
wikiquotewq
wiktionarywt
wikivoyagewv
wikiversitywy
wikinewswn
inventaireinv
portalpo
reasonatorre
scholiasc
sqidsq

Example:/Q184226?s=wq,wp,inv,wd&l=fr,en,de

Following a claim

Pass aproperty parameter (or justp) to get the destination from the entity claims associated to the desired property. The following examples illustrate the different behaviors depending on the property type:

requestredirection
Url
/Q21980377?property=P856https://sci-hub.tw
/Q1103345?property=P953http://www.cluetrain.com/#manifesto
/Q756100?property=P1324https://github.com/nodejs/node
/Q132790?property=P4238,P856http://www.biarritz.fr/webcam_2.html
ExternalId
/Q34981?property=P1938https://www.gutenberg.org/ebooks/author/35316
/Q624023?property=P2002,P2003https://twitter.com/EFF
WikibaseItem
/Q155?property=P38https://en.wikipedia.org/wiki/Brazilian_real
CommonsMedia
/Q241?property=P242https://commons.wikimedia.org/wiki/Special:FilePath/Cuba_(orthographic_projection).svg
/Q241?property=P242&width=1000https://commons.wikimedia.org/wiki/Special:FilePath/Cuba_(orthographic_projection).svg?width=1000
GlobeCoordinate
/Q25373?property=P625https://www.openstreetmap.org/?mlat=35.2542&mlon=-24.2585

Not supported:String,Time,Monolingualtext,Quantity,WikibaseProperty,Math

Aw can be used for short forwidth.

properties bundles

Instead of a list of properties, you can use special bundle keys, that behave like a list of properties.Theimage property is a bundles designed to be an easy way to give an image to an entity:

<img src="/Q624023?property=image&width=256" />
requestredirection
/Q624023?property=imagehttps://commons.wikimedia.org/wiki/Special:FilePath/EFF_Logo.svg
/Q624023?property=socialhttps://twitter.com/EFF
/Q604319?property=socialhttps://tools.wmflabs.org/wikidata-externalid-url/?p=4033&id=LaQuadrature@mamot.fr
/Q624023?property=image&width=120https://commons.wikimedia.org/wiki/Special:FilePath/EFF_Logo.svg?width=120
/Q241?p=P242&w=1000https://commons.wikimedia.org/wiki/Special:FilePath/Cuba_(orthographic_projection).svg?width=1000
multiple properties

Did you ever wish to link to Stephan Zweig's (Q78491) spouse's (P26) place of death (P20) administrative territory (P131) time zone (P421) image (P18)? Now you can:

requestredirection
/Q78491?property=P26|P20|P131|P421|P18https://commons.wikimedia.org/wiki/Special:FilePath/Timezones2008_UTC-5_gray.png

fallback

By default, when a destination is not found, you are redirected to the Wikidata entity page. This behavior can be customized:

requestredirection
/Q32689091?property=image&fallback=404404 response
/Q32689091?property=image&fallback=http%3A%2F%2Fexample.org%2F404.pnghttp://example.org/404.png

In the case where you use a URL as a fallback, make sure that it isURL-encoded. In Javascript for example, that could be done like this:

const fallbackUrl = 'https://upload.wikimedia.org/wikipedia/commons/e/e0/Wikimedia_error_404.png'const encodedFallbackUrl = encodeURIComponent(fallbackUrl)const url = `https://hub.toolforge.org/Q32689091?property=image&fallback=${encodedFallbackUrl}`

JSON

You can get a JSON response (status code200) instead of a redirection (status code302) by adding the query parameterformat=json. Ex:/Q184226?lang=fr&format=jsonThis can be useful for debugging, or to use the internal resolver as a JSON API.

requestresponse
/Q184226?lang=fr&format=json{ origin: [Object], destination: [Object] }
/Q184226?l=fr&f=j{ origin: [Object], destination: [Object] }

Query the Hub as a search engine

Building Hub URLs from the URL bar requires a few steps:

But we could be even more lazy by adding Hub as a search engine to your browser (see tutorials hereafter forfirefox andchrome). The steps can now be as follow (assuming you sethub as search engine keyword):

Firefox

Chrome

Developer Guide

Dependencies

Install

git clone https://github.com/maxlath/hubcd hubnpm install# Starts the server on port 2580 and watch for files changes to restartnpm run watch

Deploy

The step followed to setup this tool on tools.wmflabs.org are documented here:deploy

See also

License

AGPL-3.0


[8]ページ先頭

©2009-2025 Movatter.jp