PHP code example of aportela / mediawiki-wrapper

1. Go to this page and download the library: Download aportela/mediawiki-wrapper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aportela / mediawiki-wrapper example snippets




    er = new \Psr\Log\NullLogger("");

    // get wikipedia title page from wikidata item
    $i = new \aportela\MediaWikiWrapper\Wikidata\Item($logger, \aportela\MediaWikiWrapper\APIType::REST);
    $i->setItem("Q319");
    $title = $i->getWikipediaTitle(\aportela\MediaWikiWrapper\Language::ENGLISH);

    // get wikipedia title page from wikidata url
    $i = new \aportela\MediaWikiWrapper\Wikidata\Item($logger, \aportela\MediaWikiWrapper\APIType::REST);
    $i->setURL("https://www.wikidata.org/wiki/Q319");
    $title = $i->getWikipediaTitle(\aportela\MediaWikiWrapper\Language::ENGLISH);

    // get wikipedia html page from wikipedia title
    $p = new \aportela\MediaWikiWrapper\Wikipedia\Page($logger, \aportela\MediaWikiWrapper\APIType::REST);
    $p->setTitle($title);
    $html = $p->getHTML();

    // get wikipedia html page from wikipedia url
    $p = new \aportela\MediaWikiWrapper\Wikipedia\Page($logger, \aportela\MediaWikiWrapper\APIType::REST);
    $p->setURL("https://en.wikipedia.org/wiki/Jupiter");
    $html = $p->getHTML();

    // get file URL from title
    $f = new \aportela\MediaWikiWrapper\Wikipedia\File($logger, \aportela\MediaWikiWrapper\APIType::REST);
    $f->setTitle("Commons-logo.svg");
    if ($f->get()) {
        $preferredURL = $f->getURL(\aportela\MediaWikiWrapper\FileInformationType::PREFERRED);
        $originalURL = $f->getURL(\aportela\MediaWikiWrapper\FileInformationType::ORIGINAL);
        $thumbnailURL = $f->getURL(\aportela\MediaWikiWrapper\FileInformationType::THUMBNAIL);
    }