Wikipedia/MediaWiki Grabber for Laravel.

9.1.0 2022-03-15 15:53 UTC


Wikipedia/MediaWiki Grabber for Laravel

Laravel Wikipedia Grabber

Buy me a coffee

StyleCI Build Status Coverage Status

Packagist Version Packagist Stars Packagist Downloads Packagist License

Wikipedia/MediaWiki Grabber for Laravel.

Laravel Wikipedia Grabber
9.x 9.x
8.x 8.x
7.x 7.x
6.x 6.x
5.8.* 5.8.*
5.7.* 5.7.*
5.6.* 5.6.*
5.5.* 5.5.*

Laravel Wikipedia Grabber - Demo

Table of contents


  1. Install the package via Composer:

    composer require illuminated/wikipedia-grabber
  2. Publish the config:

    php artisan vendor:publish --provider="Illuminated\Wikipedia\WikipediaGrabberServiceProvider"
  3. Grab a full page or preview:

    use Wikipedia;
    echo (new Wikipedia)->page('Michael Jackson');
    echo (new Wikipedia)->preview('Michael Jackson');
    // Or
    echo (new Wikipedia)->randomPage();
    echo (new Wikipedia)->randomPreview();

Output formats

Here's the list of supported output formats:

  • plain (default)
  • bootstrap
  • bulma

Change the format in your config file, or specify it explicitly:

echo (new Wikipedia)->page('Michael Jackson')->bulma();

Available methods

When you call the page() or preview() method, you'll get an instance of the proper object.

There are numerous methods available on these objects, for example:

$page = (new Wikipedia)->page('Michael Jackson');

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

echo $page->getId();        // 14995351
echo $page->getTitle();     // "Michael Jackson"
echo $page->getBody();      // Same as `echo $page;`



Wikipedia uses the MediaWiki API under the hood.

Thus, you can grab pages from any MediaWiki website:

use MediaWiki;

echo (new MediaWiki($url))->page('Michael Jackson');

Modify the grabbed page

Sometimes it might be useful to append additional sections to the grabbed page:

$page = (new Wikipedia)->page('Michael Jackson');

$page->append('Interesting Facts', 'He had two pet llamas on his ranch called Lola and Louis.');

Alternatively, you can get the sections collection and change it as needed:

$page = (new Wikipedia)->page('Michael Jackson');

$sections = $page->getSections();
    new Section('Interesting Facts', 'He had two pet llamas on his ranch called Lola and Louis.', $level = 2)


Laravel Idea
Material Theme UI Plugin


Laravel Wikipedia Grabber is open-sourced software licensed under the MIT license.

Support on Patreon  Buy me a coffee