Wiki

Wiki

wiki

Source:

Example

wiki({ apiUrl: 'http://fr.wikipedia.org/w/api.php' }).search(...);

Methods

allCategories() → {Array}

Fetch all categories in wiki

Source:
Returns:
Type:
Array

Array of categories

allPages() → {Array}

Fetch all page titles in wiki

Source:
Returns:
Type:
Array

Array of pages

api(params) → {Promise}

Helper function to query API directly

Source:
Parameters:
Name Type Description
params Object

https://www.mediawiki.org/wiki/API:Query

Returns:
Type:
Promise

Query Response

Example
wiki().api({
	action: 'parse',
	page: 'Pet_door'
}).then(res => res.parse.title.should.equal('Pet door'));

chain() → {QueryChain}

Returns a QueryChain to efficiently query specific data

Source:
Returns:
Type:
QueryChain
Example
// Find summaries and images of places near a specific location
wiki()
	.chain()
	.geosearch(52.52437, 13.41053)
	.summary()
	.image()
	.coordinates()
	.request()

exportXml(pageName) → {Promise.<string>}

Returns the Export XML for a page to be used for importing into another MediaWiki

Source:
Parameters:
Name Type Description
pageName string
Returns:
Type:
Promise.<string>

Export XML

find(search, predicateopt) → {Promise}

Find page by query and optional predicate

Source:
Parameters:
Name Type Attributes Description
search string

query

predicate function <optional>

testing function for choosing which page result to fetch. Default is first result.

Returns:
Type:
Promise
Example
wiki.find('luke skywalker').then(page => console.log(page.title));

findById(pageid,) → {Promise}

Get Page by PageId

Source:
Parameters:
Name Type Description
pageid, integer

id of the page

Returns:
Type:
Promise
Example
wiki.findById(4335).then(page => console.log(page.title));

geoSearch(lat, lon, radiusopt, limitopt) → {Promise}

Geographical Search

Source:
Parameters:
Name Type Attributes Default Description
lat Number

latitude

lon Number

longitude

radius Number <optional>
1000

search radius in meters (default: 1km)

limit Number <optional>
10

number of results (default: 10 results)

Returns:
Type:
Promise
  • List of page titles
Example
wiki.geoSearch(32.329, -96.136).then(titles => console.log(titles.length));

mostViewed() → {Promise}

Find the most viewed pages with counts

Source:
Returns:
Type:
Promise
  • Array of {title,count}
Example
wiki.mostViewed().then(list => console.log(`${list[0].title}: ${list[0].count}`))

page(title) → {Promise}

Get Page

Source:
Parameters:
Name Type Description
title string

title of article

Returns:
Type:
Promise
Example
wiki.page('Batman').then(page => console.log(page.pageid));

pagesInCategory(category) → {Array}

Fetch all pages in category

Source:
Parameters:
Name Type Description
category String

Category to fetch from

Returns:
Type:
Array

Array of pages

prefixSearch(query, limitopt) → {Promise}

Search articles using "fuzzy" prefixsearch

Source:
Parameters:
Name Type Attributes Description
query string

keyword query

limit Number <optional>

limits the number of results

Returns:
Type:
Promise
  • pagination promise with results and next page function
Examples
wiki.prefixSearch('star wars').then(data => console.log(data.results.length));
wiki.prefixSearch('star wars').then(data => {
	data.next().then(...);
});

random(limitopt) → {Promise}

Random articles

Source:
Parameters:
Name Type Attributes Description
limit Number <optional>

limits the number of random articles

Returns:
Type:
Promise
  • List of page titles
Example
wiki.random(3).then(results => console.log(results[0]));

Search articles

Source:
Parameters:
Name Type Attributes Description
query string

keyword query

limit Number <optional>

limits the number of results

all Boolean <optional>

returns entire article objects instead of just titles

Returns:
Type:
Promise
  • pagination promise with results and next page function
Examples
wiki.search('star wars').then(data => console.log(data.results.length));
wiki.search('star wars').then(data => {
	data.next().then(...);
});