Module generators

Source
Available on crate feature generators only.
Expand description

§Page generators

Page generators are used to get lists of pages to operate on. For example, you could get a list of pages in a category or pages that use a specific template.

Most generators return a Page, but others may return other types, for example Revisions returns revision metadata.

§Basic usage

All generators follow the same basic structure:

  • a new() constructor that takes mandatory parameters
  • optional functions to supply optional parameters
  • a generate() function to start fetching pages

Rust has mediocre support for asynchronous iterators, so we take the approach of spawning a background task to fetch pages and use a channel to pass the results back. (This is why generators don’t work in WebAssembly.)

§Example

To fetch a list of pages in the category Free software programmed in Rust:

use mwbot::generators::{categories::CategoryMembers, Generator};

let bot = Bot::from_default_config().await.unwrap();
let mut generator = CategoryMembers::new("Category:Free software programmed in Rust");
let mut pages = generator.generate(&bot);
while let Some(page) = pages.recv().await {
    let page = page?;
    println!("{}", page.title());
}

Modules§

allpages
Generator to get all pages
categories
Generators related to categories
file
Generators related to file usage
langlinks
Get language links
link
Generators related to wikilink usage
lintlinter
Generators related to lint errors
log_events
Generators related to log events
lonely
Generator for lonely pages (not linked by other pages)
pageswithprop
Generators related to page property usage
querypage
Generator for QueryPage-based special pages
random
Generator to get a random set of pages
recent_changes
Generator for Special:RecentChanges
revisions
Generators to get revisions (e.g. page history)
search
Generator to search for pages
templates
transcluded
Generator to get transcluded pages
uncategorized
Generators related to uncategorized pages
unconnected_pageswikibase
Generator for pages not linked to a Wikibase item
unused
Generators related to unused pages
unwatched
Generator for unwatched pages
user_contribs
Generator to get user contributions

Structs§

EmbeddedIn
Get pages that transclude the given template

Enums§

FilterRedirect
SortDirection

Traits§

Generator
Derivable trait that implements a straightforward builder to construct API parameters to generate a list of pages. Using the MediaWiki API’s generator feature, it preloads basic metadata about pages to speed up initial processing.
ParamValue
Trait to represent a value that can be an API parameter value.

Functions§

categorymembers_recursive
Recursively get pages that are in given category.

Derive Macros§

Generator
macro to implement the Generator trait