PHPackages                             gbirke/mediawiki-api - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. gbirke/mediawiki-api

ActiveLibrary[API Development](/categories/api)

gbirke/mediawiki-api
====================

A Mediawiki API client

2361[2 issues](https://github.com/gbirke/mediawiki-api-client/issues)[1 PRs](https://github.com/gbirke/mediawiki-api-client/pulls)PHP

Since Feb 6Pushed 12y ago1 watchersCompare

[ Source](https://github.com/gbirke/mediawiki-api-client)[ Packagist](https://packagist.org/packages/gbirke/mediawiki-api)[ RSS](/packages/gbirke-mediawiki-api/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

mediawiki-api-client
====================

[](#mediawiki-api-client)

This is a client for the MediaWiki API. It uses [Guzzle](http://guzzlephp.org/) web service library. The client API is a custom web service client based on `Guzzle\Service\Client`.

**WARNING** This client is in no way feature-complete! It only implements the API functions that I need at the moment. Feel free to contribute by expanding the [json file](src/Birke/Mediawiki/Api/client.json) and adding a test.

Installation
------------

[](#installation)

Use composer to install the library and all its dependencies:

```
composer require "gbirke/mediawiki-api:dev-master"

```

Usage examples
--------------

[](#usage-examples)

### Parse Wiki Text

[](#parse-wiki-text)

```
require 'vendor/autoload.php';

use Birke\Mediawiki\Api\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();
print_r($result);
```

### Log in and upload file

[](#log-in-and-upload-file)

```
require 'vendor/autoload.php';

use Birke\Mediawiki\Api\MediawikiApiClient;

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

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

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

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

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

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

// Upload a file
$result = $client->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
));

print_r($result);

// Cleanup session
$client->logout();
```

### Use Session class to handle credentials when uploading

[](#use-session-class-to-handle-credentials-when-uploading)

Since editing is such a common task, you can use the Session class to reduce the amount of code needed for logging in and getting login tokens:

```
require 'vendor/autoload.php';

use Birke\Mediawiki\Api\MediawikiApiClient;
use Birke\Mediawiki\Api\Session;
use Birke\Mediawiki\Api\SessionException;

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

$session = new Session($client);

try {
    $session->login('Uploader', 'my_super_secret_pw');
    $token = $session->getEditToken();

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

    // Cleanup session
    $session->logout();
}
catch(SessionException $e) {
    echo "Something went wrong: ".$e->getMessage();
}
```

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance0

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/33b488eec014d318101af995ecad38a80bc1f87fd4323c71fb081ac63928837b?d=identicon)[gbirke](/maintainers/gbirke)

---

Top Contributors

[![gbirke](https://avatars.githubusercontent.com/u/223326?v=4)](https://github.com/gbirke "gbirke (8 commits)")[![addshore](https://avatars.githubusercontent.com/u/3308769?v=4)](https://github.com/addshore "addshore (2 commits)")

### Embed Badge

![Health badge](/badges/gbirke-mediawiki-api/health.svg)

```
[![Health](https://phpackages.com/badges/gbirke-mediawiki-api/health.svg)](https://phpackages.com/packages/gbirke-mediawiki-api)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
