User:MerlIwBot/WikiData

This page shows how the bot can add/change langlinks on wikidata.

Scenario

edit

The bot wants to create an interwikigroup of four pages (all having different/localized titles in this example):

Precondition

edit
  • The bot is logged in and sends the required cookie data within each request.
  • Always use post request. Only action and format are part of the url.
  • All data is send urlencoded, which is not done for human readability at the examples below.
  • +\ is used as token in all examples, but a token returned by a previous request is used instead.

Step 1

edit

Check which wiki can be added to wikidata.

No api request available. incubator-grc and commonswiki not available at the moment.

Step 2

edit

The bot wants to know if any of these pages are already contained within an item.

One request for every pages needed
  1. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbgetitems&sites=dewiki&titles=WikiDaten&prop=sitelinks
  2. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbgetitems&sites=enwiki&titles=WikiData&prop=sitelinks
    read itemid from /api/items/item/@id (attribute id is missing if no connected item exists and attribute missing exists)

Step 3

edit

Modify WikiData Items

Scenario a

edit

None of these pages is connected to a item.

Request Token
  1. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbsetitem&gettoken=1
    read token: /api/wbsetitem/@setitemtoken
Create a new item conating all pages
  1. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbsetitem&format=xml&data={"labels":{"de":"WikiDaten","en":"WikiData"},"sitelinks":{"dewiki":"WikiDaten","enwiki":"WikiData"}}&token=+\

Scenario b

edit

Some of these pages (dewiki) are already connected to one item (id 111) and the rest (enwiki) should be added to this item.

Request Token
  1. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbsetitem&gettoken=1
    read token: /api/wbsetitem/@setitemtoken
Create a new item conating all pages
  1. http://wikidata-test-repo.wikimedia.de/w/api.php?action=wbsetitem&format=xml&item=111&data={"labels":{"en":"WikiData"},"sitelinks":{"enwiki":"WikiData"}}&token=+\

Scenario c

edit

Pages are connected to different items and should be forced to use the same icon (forced regrouping after review by bot operator)

Costs

edit

This table shows the number of need http requested needed to add/chage an interwikigroup of #pages Pages. For scenario b/c half of the pages are already connected to a wikidata item.

#pages #api-requests
a b c
4
20
100
250