Mediawiki API

From XPUB & Lens-Based wiki
Revision as of 19:22, 19 November 2017 by Andre Castro (talk | contribs)

download / API / ask

Script interfaces with the mw api to download files according to ask requests

API what is the API?

API

An API or application programming interface is an interface that allows interaction via other software. It allows things such as apps to be build on top of existing services, where the apps use the API to interact with the service.


Web APIs

Mediawiki API is a Web API.

Essentially it means that the API is accessed thought HTTP requests and responds using JSON or XML object.

Note: might be helpful to install a JSON add on to your browser, to pretty-prints JSON content.

Mediawiki API

Mediawiki API allows many and very intricate request for information (and editing) from Mediawiki installations.

A few examples will follow, you can request using your web browser. Including a Pretty-prints JSON extension on your browser, as it will help you read the API's responses.


Example: Page basic info

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Main_Page&prop=info PZI MD wiki Main Page

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Wiki_publishing&prop=info This page

Example: Page content

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Wiki_publishing&prop=revisions&rvprop=content This page Page


action=render

action=render

Action render is a simple way of obtaining just the page content as HTML markup.

http://pzwiki.wdka.nl/mw-mediadesign/index.php?title=Wiki_publishing&action=render

Decomposing an API request

http://pzwiki.wdka.nl/mw-mediadesign/api.php? format=json & action=query & titles=Wiki_publishing & prop=revisions & rvprop=content
  • https://pzwiki.wdka.nl/mw-mediadesign/api.php? - endpoint - the home page of the MediaWiki web service. It can be found by going to the Version:Special page of a wiki a searching for the API entry point
  • format=json - the format of the output. Can either be JSON of XML, although XML is being phased out
  • action=query - what action to you want to performed. query is the most used, but there many more available options, such as editing and deleting pages.

Then comes the action specific parameters

  • titles=Wiki_publishing - the page queried
  • prop=revisions - what properties you want from of a page: revision. As no particular revision is specified the latest will be returned
  • rvprop=content - what specific properties you want from the page revision in question: content. You could also ask for the user who created the last revision, or the comment left by the user. These properties can be combined in a single request. rvprop=content|user|comment

Example: Page revisions

Example: Images in a page

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Main_Page&prop=images

Example: categories a page belongs to

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Wiki_publishing&prop=categories

Example: Category members - Pages belonging to a category

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&list=categorymembers&cmtitle=Category:Special Issue

Documentation: https://www.mediawiki.org/wiki/API:Categorymembers

Examples: Contributors to a page

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&titles=Main_Page&prop=contributors

Example: Users of a wiki

http://pzwiki.wdka.nl/mw-mediadesign/api.php?format=json&action=query&list=allusers&aulimit=100

limit of 100 users


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

Combining more than one query string

Notes on selecting pages

Difference between Wiki pages and Semantic property and values:


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=



Script

References