illuminated/wikipedia-grabber

Wikipedia/MediaWiki Grabber for Laravel.

10.0.0 2024-03-06 21:53 UTC

README

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
11.x Support
10.x 10.x
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

Usage

  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;`

Advanced

MediaWiki

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();
$sections->push(
    new Section('Interesting Facts', 'He had two pet llamas on his ranch called Lola and Louis.', $level = 2)
);

Sponsors

Laravel Idea
Material Theme UI Plugin

License

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

Buy me a coffee