Github mirror of "mediawiki/ruby/api" - our actual code is hosted with Gerrit (please see https://www.mediawiki.org/wiki/Developer_access for contributing
OTHER License
A library for interacting with MediaWiki API from Ruby. Uses adapter-agnostic Faraday gem to talk to the API.
Add this line to your application's Gemfile:
gem "mediawiki_api"
And then execute:
$ bundle
Or install it yourself as:
$ gem install mediawiki_api
Assuming you have MediaWiki installed via MediaWiki-Vagrant.
require "mediawiki_api"
client = MediawikiApi::Client.new "http://127.0.0.1:8080/w/api.php"
client.log_in "username", "password" # default Vagrant username and password are "Admin", "vagrant"
client.set_oauth_access_token("user_oauth_token") # INSTEAD of logging in, will make all actions as the user authenticated via OAuth
client.create_account "username", "password" # will not work on wikis that require CAPTCHA, like Wikipedia
client.create_page "title", "content"
client.get_wikitext "title"
client.protect_page "title", "reason", "protections" # protections are optional, default is "edit=sysop|move=sysop"
client.delete_page "title", "reason"
client.upload_image "filename", "path", "comment", "ignorewarnings"
client.watch_page "title"
client.unwatch_page "title"
client.meta :siteinfo, siprop: "extensions"
client.prop :info, titles: "Some page"
client.query titles: ["Some page", "Some other page"]
Any API action can be requested using #action
. See the
MediaWiki API documentation for supported
actions and parameters.
By default, the client will attempt to get a csrf token before attempting the
action. For actions that do not require a token, you can specify
token_type: false
to avoid requesting the unnecessary token before the real
request. For example:
client.action :parse, page: 'Main Page', token_type: false
MediaWiki API gem at: Gerrit, GitHub, RubyGems, Code Climate.
See https://www.mediawiki.org/wiki/Gerrit
oauth_access_token
, allowing authenticated actions on behalf of users via Wikimedia's OAuth service. Obtaining the access token is up to this gem's user. In Ruby, one can use the [oauth2](https://gitlab.com/oauth-xx/oauth2/)
gem. A working example can be seen in the source code of the Luthor tool.text
param to MediawikiApi::Client#upload_image
NeedToken
API error only once to avoidCopyright 2013-2023, Wikimedia Foundation & Contributors. Released under the terms of the GNU General Public License, version 2 or later.