Wikipedia/MediaWiki Grabber for Laravel.
| Laravel | Wikipedia Grabber |
|---|---|
| 12.x | 12.x |
| 11.x | 11.x |
| 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.* |
-
Install the package via Composer:
composer require illuminated/wikipedia-grabber
-
Publish the config:
php artisan vendor:publish --provider="Illuminated\Wikipedia\WikipediaGrabberServiceProvider" -
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();
Here's the list of supported output formats:
plain(default)bootstrapbulma
Change the format in your config file, or specify it explicitly:
echo (new Wikipedia)->page('Michael Jackson')->bulma();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');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)
);Laravel Wikipedia Grabber is open-sourced software licensed under the MIT license.




