Expand description

mwtitle

mwtitle is a library for parsing, normalizing and formatting MediaWiki page titles. It is primarily a port of the MediaWikiTitleCodec class from MediaWiki, and passes the MediaWiki test suite.

The easiest way to get started is create a TitleCodec from a siteinfo API request.

let url = "https://en.wikipedia.org/w/api.php\
           ?action=query&meta=siteinfo\
           &siprop=general|namespaces|namespacealiases|interwikimap\
           &formatversion=2&format=json";
let resp: SiteInfoResponse = reqwest::get(url).await?.json().await?;
let codec = TitleCodec::from_site_info(resp.query)?;
let title = codec.new_title("Talk:Main Page#Section 1")?;
assert_eq!(title.namespace(), 1);
assert_eq!(title.dbkey(), "Main_Page");
assert_eq!(title.fragment(), Some("Section 1"));
assert_eq!(codec.to_pretty(&title), "Talk:Main Page".to_string());
assert_eq!(
    codec.to_pretty_with_fragment(&title),
    "Talk:Main Page#Section 1".to_string()
);

It’s also possible to possible to create a TitleCodec from a JSON siteinfo-namespaces.json or compressed siteinfo-namespaces.json.gz that comes from Wikimedia dumps. This requires the extra utils feature to be enabled.

Contributing

mwtitle is a part of the mwbot-rs project. We’re always looking for new contributors, please reach out if you’re interested!

Structs

Represents an interwiki object in the interwikimap field of a SiteInfo.
A case-insensitive set for interwikis.
Represents a namespace alias object in the namespacealiases field of a SiteInfo.
Represents a namespace object in the namespaces field of a SiteInfo.
Represents the query field of a siteinfo response.
Represents a siteinfo response suitable for making a TitleCodec or a NamespaceMap.
Represents a MediaWiki title. A title can be broken down into the following attributes: [[interwiki:ns:db_key#fragment]].
TitleCodecparsing
The TitleCodec is responsible for parsing, normalizing and formatting Titles. See the crate-level documentation for an example of how to construct one.

Enums

Title validation errors

Type Definitions