illuminated / wikipedia-grabber
Wikipedia/MediaWiki Grabber for Laravel.
Installs: 7 262
Dependents: 1
Suggesters: 0
Security: 0
Stars: 46
Watchers: 4
Forks: 5
Open Issues: 0
Language:HTML
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.5
- guzzlehttp/psr7: ^2.0
- illuminate/support: ^10.0
Requires (Dev)
- mockery/mockery: ^1.5.1
- orchestra/testbench: ^8.0
- phpunit/phpunit: ^10.5
This package is auto-updated.
Last update: 2024-11-06 23:17:04 UTC
README
Laravel Wikipedia Grabber
Wikipedia/MediaWiki Grabber for Laravel.
Table of contents
Usage
-
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();
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
License
Laravel Wikipedia Grabber is open-sourced software licensed under the MIT license.