Giter VIP home page Giter VIP logo

mediawiki-api's Introduction

mediawiki-api

Build Status Code Coverage Scrutinizer Quality Score Dependency Status

On Packagist: Latest Stable Version Download count

Issue tracker: https://phabricator.wikimedia.org/project/profile/1490/

Installation

Use composer to install the library and all its dependencies:

composer require "addwiki/mediawiki-api:~0.7.0"

Example Usage

// Load all the stuff
require_once( __DIR__ . '/vendor/autoload.php' );

// Log in to a wiki
$api = new \Mediawiki\Api\MediawikiApi( 'http://localhost/w/api.php' );
$api->login( new \Mediawiki\Api\ApiUser( 'username', 'password' ) );
$services = new \Mediawiki\Api\MediawikiFactory( $api );

// Get a page
$page = $services->newPageGetter()->getFromTitle( 'Foo' );

// Edit a page
$content = new \Mediawiki\DataModel\Content( 'New Text' );
$revision = new \Mediawiki\DataModel\Revision( $content, $page->getPageIdentifier() );
$services->newRevisionSaver()->save( $revision );

// Move a page
$services->newPageMover()->move(
	$services->newPageGetter()->getFromTitle( 'FooBar' ),
	new Title( 'FooBar' )
);

// Delete a page
$services->newPageDeleter()->delete(
	$services->newPageGetter()->getFromTitle( 'DeleteMe!' ),
	array( 'reason' => 'Reason for Deletion' )
);

// Create a new page
$newContent = new \Mediawiki\DataModel\Content( 'Hello World' );
$title = new \Mediawiki\DataModel\Title( 'New Page' );
$identifier = new \Mediawiki\DataModel\PageIdentifier( $title );
$revision = new \Mediawiki\DataModel\Revision( $newContent, $identifier );
$services->newRevisionSaver()->save( $revision );

// List all pages in a category
$pages = $services->newPageListGetter()->getPageListFromCategoryName( 'Category:Cat name' );

Running the integration tests

To run the integration tests, you need to have a running MediaWiki instance. The tests will create pages and categories without using a user account so it's best if you use a test instance. Furthermore you need to turn off rate limiting by adding the line

$wgGroupPermissions['*']['noratelimit'] = true;

to the LocalSettings.php of your MediaWiki.

By default, the tests will use the URL http://localhost/w/api.php as the API endpoint. If you have a different URL (e.g. http://localhost:8080/w/api.php), you need to configure the URL as an environemnt variable before running the tests. Example:

export MEDIAWIKI_API_URL='http://localhost:8080/w/api.php'

Warning: Running the integration tests can take a long time to complete.

mediawiki-api's People

Contributors

addshore avatar samwilson avatar karatakis avatar gbirke avatar dfelten avatar kainissen avatar benestar avatar jeroendedauw avatar johnflewis avatar ricordisamoa avatar southparkfan avatar tpt avatar

Watchers

Rafid Aslam 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.