Anonymous
Not logged in
Talk
Contributions
Create account
Log in
Publication Station
Search
Editing
Courses/Wikis-Publishing Platforms
(section)
From Publication Station
Namespaces
Page
Discussion
More
More
Page actions
Read
Edit
History
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=Day 3: Remediation - Mediawiki API= ''Appropriating and reporposing wikis' content''. ==How to get content?== Although there is nothing wrong in copying the content of wiki pages in order to turn them into other publishing objects, it is a slightly tedious process, specially when you want to work with large quantities of data. Those tedious tasks can be more easily handled by software. Mediawiki wiki present a solution for this problem by providing a Web API, which functions as a programmatic interface (computer-to-computer instead of human-to-computer) to Mediawiki installations. ==APIs== 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 [http://en.wikipedia.org/wiki/Application_programming_interface#Web_APIs Web API]. Essentially it means that the API is accessed thought '''HTTP requests''' and responds using '''JSON or XML object'''. ==Mediawiki API== [http://www.mediawiki.org/wiki/API:Main_page 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== https://en.wikipedia.org/w/api.php?format=json&action=query&titles=Main_Page&prop=info English Wikipedia's Main Page http://beyond-social.org/wiki/api.php?format=json&action=query&titles=Colophon&prop=info Beyond Social's Colophon page ==Example: Page content== https://en.wikipedia.org/w/api.php?format=json&action=query&titles=Main_Page&prop=revisions&rvprop=content English Wikipedia's Main Page http://beyond-social.org/wiki/api.php?format=json&action=query&titles=Colophon&prop=revisions&rvprop=content Beyond Social's Colophon page ==Decomposing an API request== http://beyond-social.org/wiki/api.php? format=json & action=query & titles=Colophon & prop=revisions & rvprop=content * <code>http://beyond-social.org/wiki/api.php?</code> - '''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 * <code>format=json</code> - the format of the output. Can either be JSON of XML, although XML is being phased out * <code>action=query</code> - what action to you want to performed. [http://www.mediawiki.org/wiki/API:Query query] is the most used, but there many more available options, such as editing and deleting pages. '''Then comes the action specific parameters''' * <code>titles=Colophon</code> - the page queried * <code>prop=revisions</code> - what [http://www.mediawiki.org/wiki/API:Properties properties] you want from of a page: revision. As no particular revision is specified the latest will be returned * <code>rvprop=content</code> - what specific properties you want from the page revision in question: content. You could also ask for the <code>user</code> who created the last revision, or the <code>comment</code> left by the user. These properties can be combined in a single request. <code>rvprop=content|user|comment</code> ==Example: Page revisions== ?? ==Example: Images in a page== https://en.wikipedia.org/w/api.php?format=json&action=query&titles=Willem_de_Kooning&prop=images ==Example: categories a page belongs to== https://en.wikipedia.org/w/api.php?format=json&action=query&titles=Willem_de_Kooning&prop=categories ==Examples: Contributors to a page== https://en.wikipedia.org/w/api.php?format=json&action=query&titles=Willem_de_Kooning&prop=contributors http://beyond-social.org/wiki/api.php?format=json&action=query&titles=Colophon&prop=contributors ==Example: Users of a wiki== http://beyond-social.org/wiki/api.php?format=json&action=query&list=allusers&aulimit=100 limit of 100 users ==Create something with API results== Getting wiki's information (content, users, revisions, images, etc) is easy like this. Yet, turning it into something else, can be challenging and involve writing scripts to sort the information received from the API calls. To make life slightly easier for you I'll add a few python scripts that will create: * a map of all the users of a wiki * a history of the recent edits to an article * ???? All these scripts have parameters that affect their behavior, such as the queried wiki page and wiki, dates, etc. All the results are HTML pages, which are driven from template html page, a sort of shell container to the content collected by the API. You can change the template's CSS style-sheet as well as structure. Just be aware of not changing elements that have <nowiki><!-- container --></nowiki> written inside them. , an interface to Mediawiki wikis, which allows retrieving and editing content programatically
Summary:
Please note that all contributions to Publication Station are considered to be released under the Creative Commons Attribution-NonCommercial-ShareAlike (see
Publication Station:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation
Main navigation
Main page
Printmaking Studio
Print Studio
Dig. Publishing Studio
Namespaces
Grafiwiki
Random Page
Log in
Wiki tools
Wiki tools
Page tools
Page tools
User page tools
More
What links here
Related changes
Page information
Page logs