Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
MediaWiki API client written in node.js
JavaScript

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples
lib
.gitignore
README.md

README.md

nodemw

MediaWiki API client written in node.js

Requirements

  • nodejs

Instalation

git clone https://github.com/macbre/nodemw.git

Features

  • HTTP requests are stored in queue and performed in serial, there's no risk of flooding the server
  • nodemw core uses promise pattern powered by deffered-js library

Where it's used

First script

An example script can be found in /examples directory.

cd examples
node pagesInCategory.js

API

The last parameter of each function in nodemw API is a callback which will be fired when the requested action is done.

Creating a bot instance

  var bot = require('./lib/bot').bot;

  // pass configuration object
  var client = new bot({
      server: 'en.wikipedia.org',  // host name of MediaWiki-powered site
      path: '/w',                  // path to api.php script
      debug: false                // is more verbose when set to true
  });

  client.getArticle('foo', function(data) {
      // ...
  });

Config file

nodemw can use config files as well as objects directly provided to bot object constructor.

 // read config from external file
 var client = new bot('config.js');

Config file is a JSON-encoded object with the following fields (see /examples/config-DIST.js file):

{
      server: 'en.wikipedia.org',  // host name of MediaWiki-powered site
      path: '/w',                  // path to api.php script
      debug: false,                // is more verbose when set to true
      username: 'foo',             // account to be used when logIn is called (optional)
      password: 'bar'              // password to be used when logIn is called (optional)
}

bot.logIn(username, password, callback)

Log-in using given credentials - read more

bot.getCategories(prefix, callback)

Gets the list of all categories on a wiki

bot.getPagesInCategory(category, callback)

Gets the list of pages in a given category - read more

bot.getArticle(title, callback)

Gets article content and its meta data - read more

bot.edit(title, content, summary, callback)

Creates / edits an article - read more

bot.delete(title, reason, callback)

Deletes an article - read more

bot.token(title, action, callback)

Returns token required for a number of MediaWiki API operations

bot.whoami(callback)

Gets information about current bot's user (including rights and rate limits) - read more

bot.move(from, to, summary, callback)

Moves (aka renames) given article - read more

bot.getImages(callback)

Gets list of all images on a wiki

bot.getImageUsage(filename, callback)

Gets list of all articles using given image

bot.getImageInfo(filename, callback)

Gets metadata (including uploader, size, dimensions and EXIF data) of given image

bot.expandTemplates(content, title, callback)

Returns XML with preprocessed wikitext - read more

bot.fetchUrl(url, callback)

Makes a GET request to provided resource and returns its content.

TODO

  • Use promise pattern instead of callbacks.
  • Log to a file.
  • Set proper User Agent.
  • Basic wikitext parsing and modifications (reading/replacing/adding template parameters)
Something went wrong with that request. Please try again.