Mediawiki API

From XPUB & Lens-Based wiki
Revision as of 13:03, 20 November 2017 by Andre Castro (talk | contribs) (→‎Script)

Mediawiki API: semantic search and download

Script wiki-download.py from scan-utils, interfaces with the mediawiki API in order to download files according to ask requests.

API what is the API?

More on the basics of MW API in Wiki_publishing#API


Semantic queries: ASK

Semantic MediaWiki includes a simple query language for Semantic search, so that users can directly request certain information from the wiki.[1].

Inside a wiki, with SMW extension installed,the page [[Special:Ask]] provides a interface for query the wiki. See Autonomous Archive's Special:Ask

Although there are many parameters possible to include, let's keep it simple and focus on syntax for Selecting pages

Selecting pages

Wiki pages

  • select all pages under the File: namespace (all files) [[File:+]]
  • select all pages under the User: namespace (all users) [[User:+]]

Semantic properties and values

  • all pages/items with property Actor [[Actor::+]]
  • all pages/items with property Actor::Eetcafe [[Actor::Eetcafe]]

Combining more than one query string

  • all File: pages/items with property Production_Method::Typewriter [[Files:+]][[Production_Method::Typewriter]]
  • all File: pages/items

Notes on selecting pages

Difference between Wiki pages and Semantic property and values:

  • 1 : wiki pages [[User:Zalán_Szakács]]User:Zalán_Szakács
  • 2 :: semantic property values [[Production_Method::Typewriter]]


Displaying information on a property can be done by include in the ?Property to the Additional data to display window.

  • ?Production Method display the Production_Method values of the page
  • ?Actor|?Origin display the Actor and Origin values of the page

Finding existing properties and their use:

Ask 2 more interfaces

Api

The same Ask requests, which we have been making the wiki Ask interface, can be made using the mediawiki API, through the ASK module[2]

Using: /api.php?action=ask&query=

https://aa.xpub.nl/api.php?action=ask&query=[[Production_Method::%2B]]&format=jsonfm

https://aa.xpub.nl/api.php?action=ask&query=[[Actor::Poortgebouw]]&format=jsonfm

https://aa.xpub.nl/api.php?action=ask&query=[[Actor::Poortgebouw]][[Production_Method::Typewriter]]&format=jsonfm

Note that:

  • we start using the [[ ]], which we were in the wiki ask interface
  • the + sign is encoded with URL percent encoding, becoming %2B
  • we are declaring the format format=jsonfm, format=xml are possible

Script

With the wiki-download.py script from https://git.xpub.nl/scan-utils/ we can perform the same semantic queries, and dowload the resulting items, if they happen to be a file

Usage: python wiki-download.py --help ask for help

python wiki-download.py --download imgs --ask [[Production_Method::Typewriter]]

python wiki-download.py --download imgs --ask [[Production_Method::+]][[Document_Type::Flyer]]


Production method can be Hand-written OR Typewriter: python wiki-download.py --download imgs --ask [[Production_Method::Hand-written]]OR[[Production_Method::Typewriter]]

References