A MediaWiki client library in Rust
Introduction
This crate lets you interact with a MediaWiki API service.
To establish a connection to a MediaWiki API, use Api (async) or ApiSync.
Optionally, log in, as a bot or via OAuth2 (recommended).
You can then query the API directly via get_query_api_json and similar methods. You can get an edit token via get_edit_token.
Alternatively, use the high-level ActionApi and ActionApiQuery structs to interact with the API through structs instead of JSON. All MediaWiki and Wikibase API actions are implemented. Use PageInfo and PageInfoList to parse page info results.
Examples
Get all categories of "Albert Einstein" on English Wikipedia
use *;
let api = new.await.unwrap;
let result = categories
.cllimit
.titles
.run
.await
.unwrap;
let categories: = result
.as_object
.unwrap
.values
.flat_map
.collect;
dbg!;
Edit the Wikimedia Sandbox (as a bot)
use *;
let mut api = new.await.unwrap;
api.login.await.unwrap;
let token = api.get_edit_token.await.unwrap;
let res = edit
.title
.bot
.text
.summary
.token
.run
.await
.unwrap;
dbg!;
Edit via OAuth
use *;
let json = json!;
let oauth = new_from_json;
let mut api = new.await.unwrap;
api.set_oauth;
// Now use ActionApi or ActionApiQuery as normal; OAuth is applied automatically.
let token = api.get_edit_token.await.unwrap;
let res = edit
.title
.text
.summary
.token
.run
.await
.unwrap;
Get typed page info (no raw JSON needed)
use *;
let api = new.await.unwrap;
let result = info
.inprop
.titles
.run
.await
.unwrap;
let list = from_result;
for page in list.pages
Query Wikidata using SPARQL
use *;
// Will determine the SPARQL API URL via site info data
let api = new.await.unwrap;
let res = api.sparql_query.await.unwrap;
println!;
License
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.