GithubHelp home page GithubHelp logo

aportela / mediawiki-wrapper Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 47 KB

Custom php mediawiki api wrapper

License: GNU Affero General Public License v3.0

PHP 100.00%
composer-package mediawiki mediawiki-api php php8 wikipedia wikipedia-api wikidata wikidata-api

mediawiki-wrapper's Introduction

mediawiki-wrapper

Custom mediawiki api wrapper

Requirements

  • mininum php version 8.x
  • curl extension must be enabled (aportela/httprequest-wrapper)

Limitations

At this time only Wikipedia & Wikidata english pages are supported, also files

Install (composer) dependencies:

composer require aportela/mediawiki-wrapper

Code example:

<?php

    require "vendor/autoload.php";

    $logger = 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);
    }

PHP Composer

mediawiki-wrapper's People

Contributors

aportela avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.