Grab Wikipedia (or another MediaWiki) page in Laravel.

5.8.0 2019-03-10 09:07 UTC


Become a Patron

StyleCI Build Status Coverage Status

Latest Stable Version Latest Unstable Version Total Downloads License

Grab Wikipedia (or another MediaWiki) page in Laravel.

Laravel Wikipedia Grabber
5.5.* 5.5.*
5.6.* 5.6.*
5.7.* 5.7.*
5.8.* 5.8.*

Table of contents


  1. Install the package via Composer:

    composer require illuminated/wikipedia-grabber
  2. Use Wikipedia class:

    use Wikipedia;
    echo (new Wikipedia)->page('Donald Trump');


Supported formats:

Change format in your config (see Configuration):

'format' => 'bulma',

Or use proper helper methods on the fly:

echo (new Wikipedia)->page('Donald Trump')->bootstrap();


Only en and ru languages are supported now.

English is the default language. But you can change it:

echo (new Wikipedia('ru'))->page('Donald Trump');


You get an object returned, so:

$page = (new Wikipedia)->page('President Trump');

if ($page->isSuccess()) {
    echo $page->getId();    // 4848272
    echo $page->getTitle(); // Donald Trump
    echo $page;             // These two are the same
    echo $page->getBody();  // These two are the same

Here is an example of the successfully grabbed page:

$page = (new Wikipedia)->page('Donald Trump');

$page->isSuccess();         // true
$page->isMissing();         // false
$page->isInvalid();         // false
$page->isDisambiguation();  // false

And here is an example of the successfully grabbed disambiguation page:

$page = (new Wikipedia)->page('David Taylor');

$page->isSuccess();         // true
$page->isInvalid();         // false
$page->isMissing();         // false
$page->isDisambiguation();  // true


The preview consists of an intro section and the main image. It has the same API:

echo (new Wikipedia)->preview('Donald Trump');


You can grab the random page:

echo (new Wikipedia)->randomPage();

Or the random preview:

echo (new Wikipedia)->randomPreview();



You can publish config to override some settings:

php artisan vendor:publish --provider="Illuminated\Wikipedia\ServiceProvider"

It is highly recommended to override user_agent, at least:

'user_agent' => 'Application Name (;',

Get by id

Just pass an integer to the method:

echo (new Wikipedia)->page(4848272);

The same is true for the preview method:

echo (new Wikipedia)->preview(4848272);


You are not limited to Wikipedia. Grab the pages from any MediaWiki site:

use MediaWiki;

echo (new MediaWiki(''))->page('Donald Trump');


You can append section to the end:

echo (new Wikipedia)
        ->page('Donald Trump')
        ->append('Hey!', 'Please, donate me $1M, Mr. Trump!');

Or take the full control and change sections as you wish:

$page = (new Wikipedia)->page('Donald Trump');

$sections = $page->getSections();

// ...

Caching, caching, caching!

Each time you grab a page - you do the real API calls!

Use caching to improve your application speed and reduce API load:

$html = Cache::remember($key, $minutes, function () {
    return (new Wikipedia)->page('Donald Trump')->getBody();


The MIT License. Please see License File for more information.

Support on Patreon