MediaWiki – Datenmodell (Rust)
Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).
Dieses Dokument bildet das Kern-Datenmodell von MediaWiki (wie es z. B. Wikipedia zugrunde liegt) als Rust struct/enum ab. Orientiert an den zentralen MediaWiki-DB-Tabellen (page, revision, text, user, category, pagelinks, …). Es ist nur das Modell – keine Business-Logik.
Namespace
MediaWiki organisiert Seiten über feste, nummerierte Namespaces (page_namespace in der DB).
pub enum Namespace {
Media = -2,
Special = -1,
Main = 0,
Talk = 1,
User = 2,
UserTalk = 3,
Project = 4,
ProjectTalk = 5,
File = 6,
FileTalk = 7,
MediaWiki = 8,
MediaWikiTalk = 9,
Template = 10,
TemplateTalk = 11,
Help = 12,
HelpTalk = 13,
Category = 14,
CategoryTalk = 15,
Custom(i32),
}
Page
Entspricht der page-Tabelle. Hält keinen Inhalt, sondern verweist auf die aktuellste Revision.
use chrono::{DateTime, Utc};
pub type PageId = u64;
pub type RevisionId = u64;
pub type UserId = u64;
pub type TextId = u64;
pub struct Page {
pub page_id: PageId,
pub namespace: Namespace,
pub title: String,
pub is_redirect: bool,
pub is_new: bool,
pub latest: RevisionId,
pub len: u64,
pub content_model: ContentModel,
pub touched: DateTime<Utc>,
}
pub enum ContentModel {
Wikitext,
JsonContent,
JavaScript,
Css,
Text,
}
Revision
Entspricht der revision-Tabelle. Jede Bearbeitung erzeugt eine neue, unveränderliche Revision; der eigentliche Text liegt separat in text/slot.
pub struct Revision {
pub rev_id: RevisionId,
pub page_id: PageId,
pub parent_id: Option<RevisionId>,
pub text_id: TextId,
pub user: RevisionUser,
pub comment: Option<String>,
pub timestamp: DateTime<Utc>,
pub minor_edit: bool,
pub sha1: String,
pub len: u64,
}
// Angemeldeter User oder anonyme Bearbeitung per IP (wie in MediaWiki üblich).
pub enum RevisionUser {
Registered(UserId),
Anonymous { ip: String },
}
Text (Content)
Entspricht der text-Tabelle bzw. modernem content/slots-Schema.
pub struct Text {
pub old_id: TextId,
pub content: String,
pub flags: Vec<TextFlag>,
}
pub enum TextFlag {
Gzip,
Utf8,
External,
}
User
Entspricht der user-Tabelle.
pub struct User {
pub user_id: UserId,
pub name: String,
pub real_name: Option<String>,
pub email: Option<String>,
pub registration: DateTime<Utc>,
pub edit_count: u64,
pub groups: Vec<UserGroup>,
pub blocked: Option<Block>,
}
pub enum UserGroup {
User,
Autoconfirmed,
Bot,
Sysop,
Bureaucrat,
Custom(String),
}
pub struct Block {
pub reason: String,
pub expiry: Option<DateTime<Utc>>,
pub blocked_by: UserId,
}
Category
Entspricht category + categorylinks.
pub struct Category {
pub name: String,
pub page_count: u64,
pub subcat_count: u64,
pub file_count: u64,
}
pub struct CategoryLink {
pub page_id: PageId,
pub category: String,
pub sort_key: String,
pub kind: CategoryLinkType,
}
pub enum CategoryLinkType {
Page,
Subcat,
File,
}
Links (interne Verlinkung)
Entspricht den Link-Tabellen pagelinks, templatelinks, imagelinks, externallinks, langlinks, redirect.
pub struct PageLink {
pub from: PageId,
pub to_namespace: Namespace,
pub to_title: String,
}
pub struct TemplateLink {
pub from: PageId,
pub template_namespace: Namespace,
pub template_title: String,
}
pub struct ImageLink {
pub from: PageId,
pub file_name: String,
}
pub struct ExternalLink {
pub from: PageId,
pub url: String,
}
pub struct LangLink {
pub from: PageId,
pub lang: String,
pub title: String,
}
pub struct Redirect {
pub from: PageId,
pub to_namespace: Namespace,
pub to_title: String,
pub fragment: Option<String>,
}
RecentChanges
Entspricht recentchanges – Ereignis-Log für Edits, Neuanlagen, Log-Aktionen.
pub struct RecentChange {
pub rc_id: u64,
pub timestamp: DateTime<Utc>,
pub page_id: PageId,
pub rev_id: Option<RevisionId>,
pub user: RevisionUser,
pub kind: RecentChangeType,
pub comment: Option<String>,
pub bot: bool,
pub patrolled: bool,
}
pub enum RecentChangeType {
Edit,
New,
Log(LogAction),
Categorize,
}
pub enum LogAction {
Delete,
Move,
Block,
Protect,
Upload,
Merge,
}
Watchlist
Entspricht watchlist.
pub struct WatchlistEntry {
pub user_id: UserId,
pub namespace: Namespace,
pub title: String,
pub notification_timestamp: Option<DateTime<Utc>>,
}
Beziehungen (Übersicht)
User ──authors──▶ Revision ──belongs to──▶ Page ──in──▶ Namespace
│ │ │
│ └──points to──▶ Text ├──has many──▶ CategoryLink ──▶ Category
│ ├──has many──▶ PageLink / TemplateLink / ImageLink
└──has──▶ WatchlistEntry ├──may be──▶ Redirect
└──generates──▶ RecentChange
Hinweis
Hinweis: Diese Inhalte wurden mit Unterstützung von Künstlicher Intelligenz erstellt und redaktionell überprüft (Transparenzhinweis gemäß Art. 50 EU AI Act).