Expand description
A MediaWiki bot and tool framework
mwbot
aims to provide a batteries-included framework for building bots
and tools for MediaWiki wikis. It builds on top of the mwapi
and parsoid crates, which offer lower-level APIs.
§Quickstart
§Configuration
Create a ~/.config/mwbot.toml
file with the following structure:
wiki_url = "https://en.wikipedia.org/w/"
If want to authenticate, add an auth section:
[auth]
username = "Example"
oauth2_token = "[...]"
See the OAuth documentation for how to get an OAuth 2 token. Using an owner-only consumer is the easiest way to do so.
On UNIX-like systems, for security, you must make sure the config’s
file permissions don’t permit reading by other users, or authorization
will fail with a ReadableConfig
error. In this case,
chmod 600 ~/.config/mwbot.toml
can be used to correct the permissions and
make sure the file is only readable and writeable to its owner.
§Editing a page
let bot = mwbot::Bot::from_default_config().await.unwrap();
let page = bot.page("Project:Sandbox")?;
let wikitext = "This is a test edit!";
page.save(wikitext, &SaveOptions::summary("test edit!")).await?;
Page.save()
accepts both HTML and wikitext and supports the {{nobots}}
exclusion mechanism, among other features.
§Next steps
Try using one of the offered page generators to fetch and operate on multiple pages.
§Contributing
mwbot
is the flagship crate of the mwbot-rs
project.
We’re always looking for new contributors, please reach out
if you’re interested!
Re-exports§
pub use mwtimestamp as timestamp;
pub use parsoid;
Modules§
- file
upload
- generators
generators
- Page generators
- upload
upload
Structs§
- ApiClient
- API Client
- Bot
- Main bot class
- Builder
- Build a
mwbot::Bot
instance programmatically - Page
- A
Page
represents a wiki page on a specific wiki (Bot
). You can get metadata about a page, its contents (in HTML or wikitext) and edit the page. - Save
Options - Extra options for saving pages
- Title
- Represents a MediaWiki title. A title can be broken down into the following
attributes:
[[interwiki:ns:db_key#fragment]]
. - Title
Codec - The
TitleCodec
is responsible for parsing, normalizing and formattingTitle
s. See the crate-level documentation for an example of how to construct one.
Enums§
- Config
Error - Error class for config and setup
- Error
- Primary error class
- Namespace
Functions§
- init_
logging - Setup logging, can be adjusted by setting the
RUST_LOG
environment variable.