Wikibase/API

From mediawiki.org
This page is a translated version of the page Wikibase/API and the translation is 34% complete.
MediaWiki version:
1.9

Какво е Wikibase API?

Уикибаза предоставя общ механизъм за съхраняване на извлеченията като структурирани данни. Изявленията за елементи се намират на сървъра на wikidata.org. Вижте Wikidata:Glossary за повече информация за Wikibase и други концепции.

A statement

The Wikibase API allows querying, adding, removing and editing information on Wikidata or any other Wikibase instance.

Тя се осигурява чрез набор от разширения към АПИ на Медияуики. Когато използвате Wikibase API, трябва да имате основни познания за MediaWiki Action API: действия, заявки и т.н., както и с общи параметри като curtimestamp и requestid.

How to use the Wikibase api

Send requests to the API through HTTP, the same as with the MediaWiki Action API. See API:Tutorial#How to use it for information about how to use the MediaWiki Action API.

Request Format

The endpoint for the API is https://wikidata.org/w/api.php.

In the query string, add the action parameter, which tells the API which action to perform. For example, action=wbgetentities tells the API to get the data for Wikibase entities. For meta and property submodules, use action=query&meta=yourmodule and action=query&prop=modulename respectively.

Някои параметри са почти винаги налични. Формите за множествено число се използват в случаите, в които параметърът може да приеме няколко стойности. Параметрите са:

  • id/ids: Идентифицира специфичен " субект" или "субект" , много типична както "тях". Множествено формата се използва в wbgetentities . Списъците с идентификатори трябва да бъдат разделени от тръбовиден символ
  • site ∩ title/sites ∩ titles: Идентифицира техните свободни или многократни. множествената форма се употребява в конзолата

"wbgenetentites".Само един от сайтове и заглавия може да има няколко стойности едновременно.

  • language/languages: Езика е използван като филтърен механизъм да филтрира етикети и описания в действия за получаване или за идентифициране на конкретен език за зададени действия.
  • format: Винаги трябва да бъде зададено на json (или jsonfm за отстраняване на грешки) или xml (или xmlfm за отстраняване на грешки), не се поддържа друга форма.
  • summary: Добавя обобщена от потребителя резюме в допълнение към системата, генерирана от нея.
  • token: Шифрованият низ, който заявителят трябва да предаде, искането ще бъде изпълнено.
  • baserevid: ИД за последната известна ревизия, която трябва да бъде предадена, за да може сървърът да открие сблъсъци за редактиране.

A simple query

GET request

Get the item for page "Berlin" on English Wikipedia.


Explanation of each part of the URL:

  • http://www.wikidata.org/w/api.php is the main endpoint.
  • action=wbgetentities tells the API to get the data for Wikibase entities.
  • sites=enwiki means get the data from English Wikipedia.
  • titles=Berlin indicates the title of the page to get data from.
  • props=descriptions indicates properties to get from the entities, in this case the property is the descriptions of the entities.
  • languages=en means filter the results down to the English language.
  • format=json indicates JSON output, which is the recommended output format.

Response

{
    "entities": {
        "Q64": {
            "type": "item",
            "id": "Q64",
            "descriptions": {
                "en": {
                    "language": "en",
                    "value": "capital and largest city of Germany"
                }
            }
        }
    },
    "success": 1
}

Отговорът на заявка обикновено съдържа:

  • A success key with a boolean cast as an integer if the request is successful. If the integer is zero, any additional values might be wrong.
  • С клавиша error се отбелязват 2, оптималнo 3 клавиша, code,info и *,ako заявката е успешна.
  • това е един-единствен елемент или елементи , ако е няколко.Предава се на най-горното ниво или под артикул , ако е няколко елемента, всеки се намира под ключ със собствен идентификатор на артикула.

Празните обекти се връщат като масиви JSON, а не като обекти, докато празните параметри „премахват“ действителния запис от елемента.

API документация и Wikibase модули

Source-generated documentation for the MediaWiki Action API including Wikibase 'wb' API modules is available at wikidata.org/w/api.php

Meta submodules

  • wikibase: ⧼Apihelp-query+wikibase-description⧽
  • wbcontentlanguages: Returns information about the content languages Wikibase accepts in different contexts.

Property submodules

  • pageterms: ⧼Apihelp-query+pageterms-description⧽
  • wbentityusage: ⧼Apihelp-query+wbentityusage-description⧽

API modules

Възможни грешки

Възможни грешки за всеки модул могат да бъдат открити за action=paraminfo&modules=modulename The error format corresponds to that of the MediaWiki Action API. See API:Errors and warnings#Legacy format.

All error messages from the Wikibase modules should be internationalised (i18n) and localised (l10n). The user language for the logged-in user will be the default for error messages, but you can override this by adding uselang=languageCode to the URL query string.

Error type Code Info
An internationalized error message that isn't localized. no-such-item <wikibase-api-no-such-item>
A correctly localized error message. no-such-item There are no such item to be found
A localized variant.(Norwegian) no-such-item Det finnes ingen slik item

Additional notes

  • Many Wikimedia wikis run the Wikibase Client extension. This lets API clients on them to query the wikibase meta submodule to determine URLs for the full Wikibase repo, and the pageterms property submodule to get some Wikidata information about pages on the local wiki.
  • The calender models that can be used with Wikibase are the Gregorian calendar(d:Q1985727) and the Julian calendar(d:Q1985786).
  • The API uses revision ids for edit collision detection. If there is an edit collision, the requester must acquire a newer revision id to be able to continue. This typically involves requesting wbgetentities for the item in question, and then storing (and using) the revision from the entry.
  • Any MediaWiki installation can run Wikibase. On the Wikimedia cluster, most wikis do not run the full set of Wikibase extensions.

Wikimedia Commons has its own Wikibase for properties of the files on Commons.

  • Do not test the info value for a particular error, instead use the code value as this will remain independent of localisation.

Вижте също