Extension:PageSummaries

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki extensions manual
OOjs UI icon advanced.svg
PageSummaries
Release status: beta
Implementation API
Description Most wiki articles begin with a paragraph of text summarizing the rest of the article. This extension parses that first paragraph out separately and adds it to the API for use in a JSON or XML feed. Additionally, it adds a new API module that will fetch the summaries for a list of articles by title.
Author(s) (Unifiedrepublictalk)
Latest version 1.0 (2011/12/13)
MediaWiki 1.16.x (might work below)
PHP 5.x (might work below)
License No license specified
Download PageSummaries.tar.gz
Translate the PageSummaries extension if it is available at translatewiki.net
Check usage and version matrix.

An extension of the API to parse and include article summaries like the one you're reading into the API parse feed. It also creates a new API type named "summaries" that will take a list of article titles and include them into a new feed along with the article summaries. It's small, light weight, and easy to install.

What can this extension do?[edit]

This extension adds two new features to the MediaWiki API.

Since most articles are written with the first paragraph as a summary of the entire article, this extension expands on the "parse" feature of the API, finding the first paragraph of text and appending it to the output in a "summary" field. This is different and separate from the "summary" entered when changing a page.

It adds a new API module called "summaries" which, when provided with a list of article titles, will find and return the summaries for those articles with the formatted titles and links to the page.

I've used this on my site to generate "summary" boxes on other pages via AJAX calls to the API for keywords.

It is compatible will the XML, YAML, TXT, RAW, and JSON formats and probably all the rest as well.

Lastly, the script path in the link provided on return should modify based upon the path of the wiki install location but, worst case scenario, it can be changed on line 58. (Hence the reason this is still in beta.)

Usage[edit]

Standard "parse" API requests will automatically have "summary" fields added to each entry. For instance the following URL will return:

http://www.unifiedrepublicofstars.com/wiki/api.php?action=parse&format=jsonfm&prop=text&page=Ivan_Boldyrev

{
	"parse": {
		"text": {
			"*": "...",
			"summary": "Ivan Boldyrev was a politician from Galileo..."
		}
	}
}

The new summaries API module is accessible by passing the action "summaries" in the query string. So that the following URL will return:

http://urs.localhost/wiki/api.php?action=summaries&format=jsonfm&pages=Ivan_Boldyrev|Junichiro_Niwa

{
	"summaries": [
		{
			"title": "Ivan Boldyrev",
			"summary": "Ivan Boldyrev was a politician from Galileo...",
			"link": "http:\/\/www.unifiedrepublicofstars.com\/wiki\/index.php\/Ivan_Boldyrev"
		},
		{
			"title": "Junichiro Niwa",
			"summary": "Junichiro Niwa was the Prime Minister to the Cherry Blossom Seat on...",
			"link": "http:\/\/www.unifiedrepublicofstars.com\/wiki\/index.php\/Junichiro_Niwa"
		}
	]
}

The examples here are truncated from the actual API response. There is no limit on the size of a summary so long as it is all contained within the first paragraph of text within the article. It will, however, strip out any HTML formatting done within that paragraph before including it into the summary field.

Download instructions[edit]

The package is available for download here.

Installation[edit]

To install this extension, add the following to LocalSettings.php:

require_once("$IP/extensions/PageSummariesAPI/PageSummariesAPI.php");