PHPackages                             webconsul/mediawiki-sdk-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. webconsul/mediawiki-sdk-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

webconsul/mediawiki-sdk-php
===========================

60[3 PRs](https://github.com/WebConsul/mediawiki-sdk-php/pulls)PHP

Since Jul 7Pushed 3y ago2 watchersCompare

[ Source](https://github.com/WebConsul/mediawiki-sdk-php)[ Packagist](https://packagist.org/packages/webconsul/mediawiki-sdk-php)[ RSS](/packages/webconsul-mediawiki-sdk-php/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (2)DependenciesVersions (6)Used By (0)

MediaWiki SDK (PHP)
===================

[](#mediawiki-sdk-php)

This project enables PHP developers to use

- the [MediaWiki REST API](https://www.mediawiki.org/wiki/API:REST_API/Reference)
- the [Wikimedia REST API](https://en.wikipedia.org/api/rest_v1/)in their PHP code.

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

[](#installation)

You can install the package via composer:

```
composer require ekut/mediawiki-sdk-php
```

- **Note**: This package only supports `php:^8.0`.

Usage
-----

[](#usage)

In general, we use the SDK by this way:

```
  $wiki = new \MediawikiSdkPhp\MediaWiki();
  $params = ['foo'=>'bar'];
  /** @var \Spatie\DataTransferObject\DataTransferObject $res */
  $res = $wiki->{ResourceName()}->{ActionName($params)}
  /** @var array $data */
  $data = $res->toArray();
```

Default language is English. If we want to use another language, we can set it in MediaWiki constructor:

```
  $wiki = new \MediawikiSdkPhp\MediaWiki('ru');
```

Real examples: see bellow. Error handling: see bellow.

### Configuration (.env)

[](#configuration-env)

The package use `vlucas/phpdotenv` for set environment variables. All you need to do is fulfill `.env` file in root project folder with two variables/values:

```
MEDIAWIKI_HOST="https://www.wikipedia.org/"
COMMONS_HOST="https://commons.wikimedia.org/"
```

### Available Resources and Actions

[](#available-resources-and-actions)

### MediaWiki REST API

[](#mediawiki-rest-api)

- file
    - get
- page
    - create - @ToDo
    - update - @ToDo
    - get
    - getOffline
    - getSource
    - getHtml
    - getLanguages
    - getFiles
    - getHistory
    - getHistoryCounts
- revision
    - get
    - compare
- search
    - pages
    - autocompletePageTitle

### Wikimedia REST API

[](#wikimedia-rest-api)

- pageContent
    - getPageSummary
    - getPageTitle
- mobile - @ToDo
- feed - @ToDo
- transforms - @ToDo
- math - @ToDo
- citation - @ToDo
- readingLists - @ToDo
- recommendation - @ToDo
- offline - @ToDo
- talkPages - @ToDo

MediaWiki REST API
------------------

[](#mediawiki-rest-api-1)

### file

[](#file)

#### get

[](#get)

Returns information about a file, including links to download the file in thumbnail, preview, and original formats.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'The_Blue_Marble.jpg'];
  $res = $wiki->file()->get($params);
```

### page

[](#page)

#### create

[](#create)

Creates a wiki page. The response includes a location header containing the API endpoint to fetch the new page.

This endpoint is designed to be used with the OAuth extension authorization process. Callers using cookie-based authentication instead must add a CSRF token to the request body. To get a CSRF token, see the Action API.

```
@ToDo
```

#### update

[](#update)

Updates or creates a wiki page. This endpoint is designed to be used with the OAuth extension authorization process. Callers using cookie-based authentication instead must add a CSRF token to the request body. To get a CSRF token, see the Action API.

To update a page, you need the page's latest revision ID and the page source. First call the get page source endpoint, and then use the source and latest.id to update the page. If latest.id doesn't match the page's latest revision, the API resolves conflicts automatically when possible. In the event of an edit conflict, the API returns a 409 error.

To create a page, omit latest.id from the request.

```
@ToDo
```

#### get

[](#get-1)

Returns the standard page object for a wiki page, including the API route to fetch the latest content in HTML, the license, and information about the latest revision.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->get($params);
```

#### getOffline

[](#getoffline)

Returns information about a wiki page, including the license, latest revision, and latest content in HTML.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getOffline($params);
```

#### getSource

[](#getsource)

Returns the content of a wiki page in the format specified by the content\_model property, the license, and information about the latest revision.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getSource($params);
```

#### getHtml

[](#gethtml)

Returns the latest content of a wiki page in HTML.

```
@ToDo = MediawikiResponse.
```

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getHtml($params);
```

#### getLanguages

[](#getlanguages)

Searches connected wikis for pages with the same topic in different languages. Returns an array of page language objects that include the name of the language, the language code, and the translated page title.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getLanguages($params);
```

#### getFiles

[](#getfiles)

Returns information about media files used on a wiki page.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getFiles($params);
```

#### getHistory

[](#gethistory)

Returns information about the latest revisions to a wiki page, in segments of 20 revisions, starting with the latest revision.

The response includes API routes for the next oldest, next newest, and latest revision segments, letting you scroll through page history.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter'];
  $res = $wiki->page()->getHistory($params);
```

#### getHistoryCounts

[](#gethistorycounts)

Returns data about a page's history.

```
  $wiki = new MediaWiki();
  $params = ['title'=>'Jupiter', 'type' => 'edits', 'from' => 384955912, 'to'=>406217369];
  $res = $wiki->page()->getHistoryCounts($params);
```

### revision

[](#revision)

#### get

[](#get-2)

Returns details for an individual revision.

```
  $wiki = new MediaWiki();
  $params = ['id'=>1084994628];
  $res = $wiki->revision()->get($params);
```

#### compare

[](#compare)

Returns data that lets you display a line-by-line comparison of two revisions. Only text-based wiki pages can be compared.

```
  $wiki = new MediaWiki();
  $params = ['from' => 384955912, 'to' => 406217369];
  $res = $wiki->revision()->compare($params);
```

### search

[](#search)

#### pages

[](#pages)

Searches wiki page titles and contents for the provided search terms, and returns matching pages.

```
  $wiki = new MediaWiki();
  $params = ['q' => 'Jupiter', 'limit' => 5];
  $res = $wiki->search()->pages($params);
```

#### autocompletePageTitle

[](#autocompletepagetitle)

Searches wiki page titles, and returns matches between the beginning of a title and the provided search terms. You can use this action for a typeahead search that automatically suggests relevant pages by title.

```
  $wiki = new MediaWiki();
  $params = ['q' => 'Jupiter', 'limit' => 5];
  $res = $wiki->search()->autocompletePageTitle($params);
```

Wikimedia REST API
------------------

[](#wikimedia-rest-api-1)

### Page Content

[](#page-content)

#### getPageSummary

[](#getpagesummary)

```
  $wiki = new MediaWiki();
  $params = ['title' => 'Jupiter'];
  $res = $wiki->pageContent()->getSummary($params);
```

#### getPageTitle

[](#getpagetitle)

```
  $wiki = new MediaWiki();
  $params = ['title' => 'Jupiter'];
  $res = $wiki->pageContent()->getTitle($params);
```

Request parameters validation
-----------------------------

[](#request-parameters-validation)

For validation the package use `spatie/data-transfer-object` and `ekut/spatie-dto-validators`.

Input array `$params` for each action will be validated with related `{...Request}` class (extends DataTransferObject). All Request DTOs are strict. It means: if `$params` contains some unknown property, MediaWikiException will be thrown. See [Request classes](src%5CDTO%5CRequests) in code tree.

Error Handling
--------------

[](#error-handling)

Any none-successful request (status &gt;= 400) will throw MediaWikiException.

```
try{
    $res = $wiki->{ResourceName()}->{ActionName($params)}
} catch (\MediawikiSdkPhp\Exceptions\MediaWikiException $e) {
    echo $e->getCode();
    echo $e->getMessage();
    echo $e->getReason();
}
```

It extends main PHP Exception class and contains one additional method:

```
  $e->getReason();
```

### Development

[](#development)

Need **Docker** and **Docker-Compose**.

Init developer environment:

```
make init

```

Run tests:

```
make sdk-test

```

Run bash shell:

```
make sdk-shell

```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity31

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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/d6ab628e9a1a159c020163de8aa7f00b821afe6b21ddb9004054efdcc52b05bd?d=identicon)[ekut](/maintainers/ekut)

---

Top Contributors

[![ekut](https://avatars.githubusercontent.com/u/6266596?v=4)](https://github.com/ekut "ekut (14 commits)")[![dku1](https://avatars.githubusercontent.com/u/103057737?v=4)](https://github.com/dku1 "dku1 (12 commits)")[![eljump](https://avatars.githubusercontent.com/u/45133615?v=4)](https://github.com/eljump "eljump (7 commits)")[![erbolat-sabirov](https://avatars.githubusercontent.com/u/26741651?v=4)](https://github.com/erbolat-sabirov "erbolat-sabirov (4 commits)")[![poymanov](https://avatars.githubusercontent.com/u/13321928?v=4)](https://github.com/poymanov "poymanov (3 commits)")

### Embed Badge

![Health badge](/badges/webconsul-mediawiki-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/webconsul-mediawiki-sdk-php/health.svg)](https://phpackages.com/packages/webconsul-mediawiki-sdk-php)
```

###  Alternatives

[mmanos/laravel-casset

An asset management package for Laravel 4.

112.6k](/packages/mmanos-laravel-casset)

PHPackages © 2026

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