Skip to main content

wikimedia_api/endpoints/
page.rs

1use serde::{Deserialize, Serialize};
2use strum::Display;
3
4// Wikimedia Page object: https://api.wikimedia.org/wiki/Core_REST_API/Reference/Pages/Page_object
5// NOTE: the schema here slightly deviates from the API, see below and `requester::_Page` for more information.
6#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
7pub struct Page {
8    pub id: usize,                   // Page identifier
9    pub key: String,                 // Page title in URL-friendly format
10    pub title: String,               // Page title in reading-friendly format
11    pub latest: PageLatest,          // Latest revision of the page
12    pub content_model: ContentModel, // Content model used for the page
13    pub license: License,            // Information about the wiki's license
14    // The following part deviates from Wikimedia's API:
15    // html_url: String -- Get page only: API route to fetch the content of the page in HTML
16    // html: String -- Get page offline only: Latest page content in HTML
17    // source: String --  Get page source, create page, and edit page only: Latest page content in the format specified by the content_model property
18    // Since there is exactly 1 String in each mode, we're doing this instead:
19    pub source_or_url: String,
20}
21
22#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
23pub struct PageLatest {
24    pub id: usize,         // Revision identifier for the latest revision
25    pub timestamp: String, // Timestamp of the latest revision in ISO 8601 format
26}
27
28// https://api.wikimedia.org/wiki/Core_REST_API/Reference/Pages/Language_object
29#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
30pub struct Language {
31    code: String, // Language code. For example: ar (Arabic), en (English), es (Spanish). List supported languages.
32    name: String, // Translated language name
33    key: String,  // Translated page title in URL-friendly format
34    title: String, // Translated page title in reading-friendly format
35}
36
37#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
38pub struct License {
39    pub url: String, // URL for a page that describes the terms and conditions of the license
40    pub title: String, // Name of the license in plain text
41}
42
43#[derive(
44    Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display, Serialize, Deserialize,
45)]
46#[serde(rename_all = "lowercase")]
47pub enum ContentModel {
48    WikiText, // (default): MediaWiki-flavored markup, used for most wiki pages
49    CSS,
50    JavaScript,
51    JSON,
52    Text,
53}