9 releases

0.2.5 Sep 5, 2024
0.2.4 Jun 2, 2024
0.2.3 Dec 15, 2023
0.2.2 Feb 20, 2023
0.1.0 Dec 20, 2021

#250 in Web programming

Download history 111/week @ 2024-08-17 179/week @ 2024-08-24 232/week @ 2024-08-31 67/week @ 2024-09-07 76/week @ 2024-09-14 106/week @ 2024-09-21 98/week @ 2024-09-28 135/week @ 2024-10-05 97/week @ 2024-10-12 49/week @ 2024-10-19 47/week @ 2024-10-26 69/week @ 2024-11-02 48/week @ 2024-11-09 56/week @ 2024-11-16 49/week @ 2024-11-23 31/week @ 2024-11-30

197 downloads per month
Used in 3 crates

GPL-3.0-or-later

115KB
2K SLoC

mwtitle

crates.io docs.rs docs (main) pipeline status coverage report

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!

License

This crate is released under GPL-3.0-or-later. See COPYING for details.

Dependencies

~0.5–2MB
~39K SLoC