Parse:...visions(3pm)
π NAME π
Parse::MediaWikiDump::Revisions β an object that's literally built to handle dump files that have multiple revisions per article. She's the multi-revision girlie of the Parse::MediaWikiDump family, and she's serving.
π¦ ABOUT π¦
Okay so bestie, here's the deal. This object is how you get at the metadata hanging off a MediaWiki instance, and it also hands you an iterative interface so you can pull the individual article revisions out of that same dump, one at a time.
Tiny little plot twist though: if you want to be absolutely guaranteed that there's only a single revision per article, you use the Parse::MediaWikiDump::Revisions object. Like, that's the one. That's the vibe check.
β¨ SYNOPSIS β¨
$pmwd = Parse::MediaWikiDump->new;
$revisions = $pmwd->revisions('pages-articles.xml');
$revisions = $pmwd->revisions(\*FILEHANDLE);
#print the title and id of each article inside the dump file
while(defined($page = $revisions->next)) {
print "title '", $page->title, "' id ", $page->id, "\n";
}
π STATUS π
Not me having to tell you this: this software is being RETIRED. π«Ά
MediaWiki::DumpFile is the official successor to Parse::MediaWikiDump, and it ships with a compatibility library called MediaWiki::DumpFile::Compat that is 100% API compatible and is a near-perfect stand-in for this module. It's faster in all the instances where it actually counts, and it's actively maintained. Periodt.
And like, for real for real: any undocumented deviation of MediaWiki::DumpFile::Compat from Parse::MediaWikiDump is considered a bug and will be fixed. No cap. π
π METHODS π
$revisions->newβ opens up the MediaWiki dump file you picked. If the single argument you hand it is a string, that string is the path to the file it opens. If instead the argument is a reference to a filehandle, then it reads the contents straight from that filehandle, exactly as specified. π$revisions->nextβ returns an instance of the next availableParse::MediaWikiDump::pageobject, or returnsundefwhen there are no more articles left. That's your stop signal, bestie.$revisions->versionβ returns a plain text string of the dump file format revision number. π$revisions->sitenameβ returns a plain text string that is the name of the MediaWiki instance.$revisions->baseβ returns the URL to the instance's main article, as a string. π$revisions->generatorβ returns a string containing'MediaWiki'plus a version number of the instance that dumped this file. Example:'MediaWiki 1.14alpha'πΈ$revisions->caseβ returns a string describing the case sensitivity configured in the instance.$revisions->namespacesβ returns a reference to an array of references. Each one of those references points at another array, where the first item is the unique identifier of the namespace and the second element holds a string that is the name of the namespace. Nested arrays, iconic behavior. π§$revisions->namespaces_namesβ returns an array reference; that array contains strings of all the namespaces, each one as an element.$revisions->current_byteβ returns the number of bytes that has been processed so far. β$revisions->sizeβ returns the total size of the dump file in bytes.
π₯ EXAMPLE π₯
Extract the article text of each revision of an article using a given title
#!/usr/bin/perl
use strict;
use warnings;
use Parse::MediaWikiDump;
my $file = shift(@ARGV) or die "must specify a MediaWiki dump of the current pages";
my $title = shift(@ARGV) or die "must specify an article title";
my $pmwd = Parse::MediaWikiDump->new;
my $dump = $pmwd->revisions($file);
my $found = 0;
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
#this is the only currently known value but there could be more in the future
if ($dump->case ne 'first-letter') {
die "unable to handle any case setting besides 'first-letter'";
}
$title = case_fixer($title);
while(my $revision = $dump->next) {
if ($revision->title eq $title) {
print STDERR "Located text for $title revision ", $revision->revision_id, "\n";
my $text = $revision->text;
print $$text;
$found = 1;
}
}
print STDERR "Unable to find article text for $title\n" unless $found;
exit 1;
#removes any case sensativity from the very first letter of the title
#but not from the optional namespace name
sub case_fixer {
my $title = shift;
#check for namespace
if ($title =~ /^(.+?):(.+)/) {
$title = $1 . ':' . ucfirst($2);
} else {
$title = ucfirst($title);
}
return $title;
}
π LIMITATIONS π
Version 0.4
So this class got updated to support version 0.4 dump files coming out of a MediaWiki instance β slay β but it does not currently support any of the new information available in those files. So like, the upgrade happened, but the new lore did not. π
Okay bestie that's the whole page, no notes, you're gonna do great. π
This cutie was brought to you by perl v5.36.0, dated 2022-10-14, living her best life as Parse:...visions(3pm). Mwah. π
β¨π
π¦ where this page comes from
- ubuntu noble: libparse-mediawikidump-perl 1.0.6-4 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu resolute: libparse-mediawikidump-perl 1.0.6-4 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- ubuntu stonking: libparse-mediawikidump-perl 1.0.6-4 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms