維基數據:如何在維基媒體計畫中應用數據

This page is a translated version of the page Wikidata:How to use data on Wikimedia projects and the translation is 31% complete.
Outdated translations are marked like this.

用 Lua 代码或解析器函数等方法可以将许多维基数据的内容展示在其他维基媒体项目上,如标签、描述、值等信息。 Wikidata:Wikidata in Wikimedia projects 概述了维基数据在维基媒体项目中的应用。

本页面将告诉你如何在你的维基上使用维基数据中的信息。另外也可以看看维基数据是什么数据是如何组织起来的,以及术语表

我可否在自己的維基存取維基數據資料?

目前,解析器函数和 Lua 代码这两种主要客户端功能均已在几乎所有的维基媒体项目中启用。

要想确认某个维基是否启用了这两种功能,查看Special:Version页面即可。在这个特殊页面的“Parser function hooks”一节的列表中如果有“statements”一项,就说明已经启用了。

由于技术限制,目前仅限维基媒体项目使用维基数据中的信息。这意味着你无法在自己架设的 MediaWiki 站点中使用维基数据。不过,你可以建立自己的 Wikibase 资料库并用类似方法使用其中的数据。

解析器函数

第一种方法是使用 #statements 这个解析器函数。这个函数可以获取某个项的任一声明。

 
一个维基数据项目各部分的名称

直接获取

On a page that is connected to a Wikidata item via the interwiki links, you can use the function by adding the label of the property you want in your language or the P-number of the property. The code has to be added in the wikicode.

Examples:

  • {{#statements:member of political party}} or {{#statements:P102}} will return the "member of political party" value.
  • {{#statements:discoverer or inventor}} or {{#statements:P61}} will return the "discoverer or inventor" value.
  • On w:en:Douglas Adams, the code {{#statements:country of citizenship}} will display "United Kingdom".

Arbitrary access

You can also display data from an item that is not connected via an interwiki link. For this, you use the same function, adding a parameter from= followed by the Q-id of the item.

Examples:

  • {{#statements:birth name|from=Q42}} will display "Douglas Noël Adams"
  • {{#statements:country of citizenship|from=Q42}} will display "United Kingdom".
  • {{#statements:P1476|from=Q191380}} will display "Notre-Dame de Paris"
  • {{#statements:author|from=Q191380}} will display "Victor Hugo"
  • {{#statements:publication date|from=Q191380}} will display "1831"

Multiple values

When a statements has multiple values, the parser function will show the "best" value(s), which means:

Where there are multiple values, they are shown in a comma-separated list.

Example: {{#statements:occupation|from=Q42}} displays "playwright, screenwriter, novelist, children's writer, science fiction writer, comedian, writer, musician" (there are other occupations in Douglas Adams (Q42) but only some are preferred).

Formatted values

For some properties, the #statements parser function will display the value in a specific format.

Commons images

The parser function displays a thumbnail preview of the image, resizing it to 200 pixels. It links to the Wikimedia Commons file description page.

{{#statements:image|from=Q42}} displays

 

Geo coordinates

The parser function displays the coordinates in degree-minute-second format.

{{#statements:coordinate location|from=Q243}} displays 48°51′30″N 2°17′40″E

Monolingual text

Text values are displayed as they are, with no formatting.

{{#statements:native label|from=Q31}} displays "Koninkrijk België, Royaume de Belgique, Königreich Belgien".

Date

The date value will be formatted in day-month-year format.

{{#statements:date of birth|from=Q42}} displays 11 March 1952

Links

The links are clickable.

{{#statements:official website|from=Q243}} displays https://www.toureiffel.paris, https://www.toureiffel.paris/en

External IDs

An external ID will provide a direct link to the external website.

{{#statements:IMDb ID|from=Q42}} displays nm0010930

Items

Items have their label (in the content language) displayed, without a link.

{{#statements:capital|from=Q142}} displays Paris

Raw value

To display the unlinked value, use #property.

Sample:

{{#property:IMDb ID|from=Q42}} displays nm0010930

模組

Data can also be accessed with Lua modules, which are much more flexible. Modules that access data from Wikidata should be organized as instance of Wikimedia module using Wikidata (Q59259626). For instance, Module:Wikidata (Q12069631) is available on many wikis, see w:Module:Wikidata#Usage for usage instruction. If your wiki does not contain a module you can copy it from another wiki and add documentation.

For a full technical reference of Lua functions for accessing Wikidata, see mw:Extension:Wikibase Client/Lua.

模板

Some templates use modules to access Wikidata data. They are as simple to use as regular templates. Moreover, using Wikidata, some parameters become unnecessary. For instance, some infoboxes are able to retrieve data from Wikidata, so you just have to insert the template and all the data will magically appear (if the needed information is present on the Wikidata item, of course). For templates using Wikidata see Category:Templates using data from Wikidata (Q11985372).

If you want to create a template on your wiki, check your documentation page about Module:Wikidata and already existing templates.

列表

定期更新之列表

Daily updated lists based on SPARQL queries can be configured using Template:Wikidata list (Q19860885). Content is replaced daily.

There are essentially two uses:

  • Work lists: lists with topics to be covered in project namespace. Results can be limited to topics that don't exist.
  • Reference list: lists for a specific topic in article namespace.

This is currently the most efficient way of doing lists.

Dynamic lists

Content is displayed from various items based on a selection done in a Lua module.

Manual lists

A series of items are selected and their properties displayed in an article. Content from Wikidata can be completed with locally edited text.

使用範例

Magic infobox

A call of the general cheese infobox template fr:Modèle:Infobox Fromage without any parameters, on an article about a type of cheese, for example fr:Reblochon, produces an infobox with details about that type of cheese, using data from the Wikidata item linked to the article.

共享資源

Commons creator template uses Wikidata with arbitrary access to provide information about the creators of the works.

圖表

Authority model

維基文庫

如何求助?

您可在互助客棧上尋求編者協助。某些維基還有與維基數據相關的計畫,參見Project:WikiProject Wikidata (Q20855878)


See also