This package is abandoned and no longer maintained. The author suggests using the addwiki/guzzle-mediawiki-client package instead.

A Mediawiki API client for Guzzle

Installs: 53

Dependents: 1

Watchers: 4

Forks: 1

Language: PHP

0.1 2014-02-23 00:34 UTC


NOTE: This fork is no longer actively maintained and some issues and known but not fixed. Please take a look at the mediawiki-api-base library.

This is a client for the MediaWiki API. It uses Guzzle web service library. The client API is a custom web service client based on Guzzle\Service\Client.

This fork was originally based on the mediawiki-api-client repo by gbirke


Use composer to install the library and all its dependencies:

composer require "addwiki/guzzle-mediawiki-client:0.1.*"

Usage examples

Parse Wiki Text

require 'vendor/autoload.php';

use Guzzle\Service\Mediawiki\MediawikiApiClient;

$client = MediawikiApiClient::factory();
$parse = $client->getCommand('parse', array(
    'text' => "= Wiki = \n This is test text. \n\nSecond Paragraph\n\n== Foo ==\nLorem Ipsum",
    'contentmodel' => 'wikitext'
$result = $help->execute();

Log in and upload file

require 'vendor/autoload.php';

use Guzzle\Service\Mediawiki\MediawikiApiClient;

$l = MediawikiApiClient::factory(array(
        'base_url' => "http://localhost/w/api.php",

$credentials = array(
    'lgname' => "Uploader",
    'lgpassword' => 'my_super_secret_pw'

// Use magic methods
$result = $l->login($credentials);

$resultMsg = $result['login']['result'];
if ($resultMsg != "NeedToken" && $resultMsg != "Success") {
    die("Login failed: $resultMsg");

// First auth returns "NeedToken", reauthenticate with token
if ($resultMsg == "NeedToken") {
    $result = $l->login(array_merge(array(
        'lgtoken' => $result['login']['token']
    ), $credentials));

// Get an edit token (default value for "type")
$tokens = $l->tokens();

// Upload a file
$result = $l->upload(array(
    'filename' => 'Thingie.jpg',
    'token' => $tokens['tokens']['edittoken'],
    'file' => "path/to/your/image.jpg",
    'ignorewarnings' => true // Set this to false if you don't want to override files


// Cleanup session