Mediawiki API: Difference between revisions

From XPUB & Lens-Based wiki
(Created page with "= download / API / ask = Script interfaces with the mw api to download files according to ask requests ## API what is the API? Examples == ask == What is Wiki pages accor...")
 
No edit summary
Line 1: Line 1:
= download / API / ask =
= download / API / ask =


Script interfaces with the mw api to download files according to ask requests ## API what is the API?
Script interfaces with the mw api to download files according to ask requests  


Examples
=API what is the API?=
{{:Wiki_publishing}}


== ask ==
=Semantic queries: ASK =
Semantic MediaWiki includes a simple query language for Semantic search, so that users can directly request certain information from the wiki.<ref>https://www.semantic-mediawiki.org/wiki/Help:Inline_queries</ref>.


What is
Inside a wiki, with SMW extension installed,the page <nowiki>[[Special:Ask]]</nowiki> provides a interface for query the wiki. See Autonomous Archive's [https://aa.xpub.nl/index.php?title=Special:Ask Special:Ask]
Although there are many parameters possible to include, let's keep it simple and focus on syntax for '''Selecting pages''' 


Wiki pages according to namespaces: [[File:+]] categories user file
===Selecting pages===
Wiki pages
* select all pages under the File: namespace (all files) <code>[[File:+]]</code>
* select all pages under the User: namespace (all users) <code>[[User:+]]</code>


Semantic property value [[Property::value]]
Semantic properties and values
* all pages/items with property Actor <code>[[Actor::+]] </code>
* all pages/items with property <nowiki>Actor::Eetcafe</nowiki> <code>[[Actor::Eetcafe]]</code>


Meta-characters: + (wildcards? File:*.pdf??)
Combining more than one query string
* all File: pages/items with property Production_Method::Typewriter <code>[[Files:+]][[Production_Method::Typewriter]]</code>
* all File: pages/items


=== same ask string in 3 different interfaces ===
===Notes on selecting pages===
'''Difference between Wiki pages and Semantic property and values:'''
* 1 <code>:</code> wiki pages <code>[[User:Zalán_Szakács]]</code>[[User:Zalán_Szakács]]
* 2 <code>::</code> semantic property values <code>[[Production_Method::Typewriter]]</code>


Semantic query page


Api
Displaying information on a property can be done by include in the
<code>?Property</code> to the ''Additional data to display'' window.
* <code>?Production Method</code> display the Production_Method values of the page
* <code>?Actor|?Origin</code> display the Actor and Origin values of the page


Script
Finding existing properties and their use:
* Visit the [https://aa.xpub.nl/index.php?title=Special:Properties Special:Properties] page
* Visit the [https://aa.xpub.nl/index.php?title=Special%3ASearchByProperty Special:3ASearchByProperty] page
 
=== 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<ref>https://www.semantic-mediawiki.org/wiki/Help:API:ask</ref>
 
Using: <code>/api.php?action=ask&query=</code>
 
 
 
===Script===
 
 
 
=References=

Revision as of 20:22, 19 November 2017

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