Jump to content

Rosetta Code:API/MediaWiki/Perl/MediaWiki::API

From Rosetta Code

Official Resources

MediaWiki::API on CPAN.

Usage

All of the methods take hashrefs, which provides a named parameter approach to function arguments. MediaWiki::API uses object-oriented principles, which means you need to instanciate an object. Using MediaWiki::API involves four stages.

Construction

The new method instanciates a MediaWiki::API object <lang perl>my %options; # Options might go in this hash, passed in via an anonymous hashref, or assigned later. my $mw = MediaWiki::API->new( \%options ); #Construct the object</lang>

Some configuration options will be specific to Rosetta Code, though this currently only applies to the api_url. <lang perl>my %rcopts = ( 'api_url' => 'http://rosettacode.org/mw/api.php' );</lang>

Login

Provide MediaWiki with your login credentials, or those of the account you created for your bot. <lang perl>my %login = ( 'lgname' => 'Some Anonymous Bot', 'lgpassword' => 'hf6873#@!!hfFHs' );</lang>

Use the API

Assuming your login succeeded, you may now use the API. See the api, edit, get_page, list, upload and download methods in the Method Reference below.

Logout

Log out of MediaWiki tidily.

Method Reference

Primary Methods

These methods perform unique operations with respect to MediaWiki and the API.

api Direct abstraction of api.php
download Download files from the wiki
login Log in and gain access to MediaWiki functionality.
new Constructs a MediaWiki::API instance
upload Upload files to the wiki

Helper Methods

These methods wrap one or more primary methods, providing default operations for common operations. Anything you can do with one of these methods, you can do with one of the primary methods.

edit Edit a page
get_page Retrieve the latest version of a page
list Retrieve listings
Cookies help us deliver our services. By using our services, you agree to our use of cookies.