Parse:...::Links(3pm)
π Parse:...::Links π
okay bestie, you found it β this is a page straight out of the User Contributed Perl Documentation, and it's all about Parse::MediaWikiDump::Links. pull up a chair, we're doing this π«Ά
β¨ NAME β¨
Parse::MediaWikiDump::Links β an object that's literally built to process link dump files. no cap.
πΈ ABOUT πΈ
so like, this object is your girl for getting at the content of those SQL-based category dump files. she hands you an iterative interface so you can pull out the individual article links one at a time, no drama, no loading the whole thing into your brain at once π
and the objects she gives you back? those are instances of Parse::MediaWikiDump::link. matching set, periodt.
π SYNOPSIS π
here's the vibe, literally copy-paste core:
$pmwd = Parse::MediaWikiDump->new;
$links = $pmwd->links('pagelinks.sql');
$links = $pmwd->links(\*FILEHANDLE);
#print the links between articles
while(defined($link = $links->next)) {
print 'from ', $link->from, ' to ', $link->namespace, ':', $link->to, "\n";
}
see how you can hand her a filename or a filehandle? versatile queen π
π STATUS π
bestie. sit down. i need to tell you something.
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 β like, a near perfect stand-in for this module. it's faster in every single instance where it actually counts, and it's actively maintained. glow-up fr fr β¨
and here's the messy part: any undocumented deviation of MediaWiki::DumpFile::Compat from Parse::MediaWikiDump is considered a bug and will be fixed. so the new girl is contractually obligated to behave. we love accountability π
π¦ METHODS π¦
Parse::MediaWikiDump::Links->new
spawn a brand new instance of a page links dump file parser. fresh out the box, main character energy π
$links->next
hand over the next available Parse::MediaWikiDump::link object, or undef if there's genuinely no more data left. when she's done, she's done β no crumbs π
π EXAMPLE π
list all links between articles, but make it friendly π₯°
#!/usr/bin/perl
use strict;
use warnings;
use Parse::MediaWikiDump;
my $pmwd = Parse::MediaWikiDump->new;
my $links = $pmwd->links(shift) or die "must specify a pagelinks dump file";
my $dump = $pmwd->pages(shift) or die "must specify an article dump file";
my %id_to_namespace;
my %id_to_pagename;
binmode(STDOUT, ':utf8');
#build a map between namespace ids to namespace names
foreach (@{$dump->namespaces}) {
my $id = $_->[0];
my $name = $_->[1];
$id_to_namespace{$id} = $name;
}
#build a map between article ids and article titles
while(my $page = $dump->next) {
my $id = $page->id;
my $title = $page->title;
$id_to_pagename{$id} = $title;
}
$dump = undef; #cleanup since we don't need it anymore
while(my $link = $links->next) {
my $namespace = $link->namespace;
my $from = $link->from;
my $to = $link->to;
my $namespace_name = $id_to_namespace{$namespace};
my $fully_qualified;
my $from_name = $id_to_pagename{$from};
if ($namespace_name eq '') {
#default namespace
$fully_qualified = $to;
} else {
$fully_qualified = "$namespace_name:$to";
}
print "Article \"$from_name\" links to \"$fully_qualified\"\n";
}
not her casually building two whole lookup hashes and yeeting $dump the second she's done with it π efficient behavior honestly
and that's the page bestie!! π this whole thing comes from perl v5.36.0, dated 2022-10-14 β go forth and parse those links, you absolute icon ππβ¨
π¦ 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