This file is indexed.

/usr/share/perl5/MediaWiki/DumpFile/Compat.pm is in libmediawiki-dumpfile-perl 0.2.2-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#!/usr/bin/env perl

#Parse::MediaWikiDump compatibility

package MediaWiki::DumpFile::Compat;

our $VERSION = '0.2.0';

package #go away indexer! 
	Parse::MediaWikiDump;

use strict;
use warnings;

sub new {
	my ($class) = @_;
	return bless({}, $class);
}

sub pages {
	shift(@_);
	return Parse::MediaWikiDump::Pages->new(@_);
}

sub revisions {
	shift(@_);
	return Parse::MediaWikiDump::Revisions->new(@_);
}

sub links {
	shift(@_);
	return Parse::MediaWikiDump::Links->new(@_);
}

package #go away indexer! 
	Parse::MediaWikiDump::Links;

use strict; 
use warnings;

use MediaWiki::DumpFile::SQL;

sub new {
	my ($class, $source) = @_;
	my $self = {};
	my $sql;
	
	$Carp::CarpLevel++;
	$sql = MediaWiki::DumpFile::SQL->new($source);
	$Carp::CarpLevel--;
	
	if (! defined($sql)) {
		die "could not create SQL parser";
	}
	
	$self->{sql} = $sql;
	
	return bless($self, $class);
}

sub next {
	my ($self) = @_;
	my $next = $self->{sql}->next;
	
	unless(defined($next)) {
		return undef;
	}
	
	return Parse::MediaWikiDump::link->new($next);
}

package #go away indexer! 
	Parse::MediaWikiDump::link;

use strict; 
use warnings;

use Data::Dumper;

sub new {
	my ($class, $self) = @_;
	
	bless($self, $class);
}

sub from {
	return $_[0]->{pl_from};
}

sub namespace {
	return $_[0]->{pl_namespace};
}

sub to {
	return $_[0]->{pl_title};
}

package #go away indexer! 
	Parse::MediaWikiDump::Revisions;

use strict;
use warnings;
use Data::Dumper;

use MediaWiki::DumpFile::Pages;

sub new {
	my ($class, @args) = @_;
	my $self = { queue => [] };
	my $mediawiki;
	
	$Carp::CarpLevel++;
	$mediawiki = MediaWiki::DumpFile::Pages->new(@args);
	$Carp::CarpLevel--;
	
	$self->{mediawiki} = $mediawiki;
	
	return bless($self, $class);
}

sub version {
	return $_[0]->{mediawiki}->version;
}

sub sitename {
	return $_[0]->{mediawiki}->sitename;
}

sub base {
	return $_[0]->{mediawiki}->base;
}

sub generator {
	return $_[0]->{mediawiki}->generator;
}

sub case {
	return $_[0]->{mediawiki}->case;
}

sub namespaces {
	my $cache = $_[0]->{cache}->{namespaces};
	
	if(defined($cache)) {
		return $cache;
	}
	
	my %namespaces = $_[0]->{mediawiki}->namespaces;
	my @temp;
	
	while(my ($key, $val) = each(%namespaces)) {
		push(@temp, [$key, $val]);
	}
	
	@temp = sort({$a->[0] <=> $b->[0]} @temp);
	
	$_[0]->{cache}->{namespaces} = \@temp;
	
	return \@temp;
}

sub namespaces_names {
	my ($self) = @_;
	my @result;
	
	return $self->{cache}->{namespaces_names} if defined $self->{cache}->{namespaces_names};
	
	foreach (@{ $_[0]->namespaces }) {
		push(@result, $_->[1]);
	}
	
	$self->{cache}->{namespaces_names} = \@result;
	
	return \@result;
}

sub current_byte {
	return $_[0]->{mediawiki}->current_byte;
}

sub size {
	return $_[0]->{mediawiki}->size;
}

sub get_category_anchor {
	my ($self) = @_;
	my $namespaces = $self->namespaces;
	my $cache = $self->{cache};
	my $ret = undef;
	
	if (defined($cache->{category_anchor})) {
		return $cache->{category_anchor};
	}

	foreach (@$namespaces) {
		my ($id, $name) = @$_;
		if ($id == 14) {
			$ret = $name;
		}
	}	
	
	$self->{cache}->{category_anchor} = $ret;
	
	return $ret;
}

sub next {
	my $self = $_[0];
	my $queue = $_[0]->{queue};
	my $next = shift(@$queue);
	my @results;

	return $next if defined $next;
	
	$next = $self->{mediawiki}->next;
	
	return undef unless defined $next;

	foreach ($next->revision) {
		push(@$queue, Parse::MediaWikiDump::page->new($next, $self->namespaces, $self->get_category_anchor, $_));
	}
	
	return shift(@$queue);
}

package #go away indexer! 
	Parse::MediaWikiDump::Pages;

use strict;
use warnings;

our @ISA = qw(Parse::MediaWikiDump::Revisions);

sub next {
	my $self = $_[0];
	my $next = $self->{mediawiki}->next;
	my $revision_count;
	
	return undef unless defined $next;
	
	$revision_count = scalar(@{[$next->revision]});
						#^^^^^ because scalar($next->revision) doesn't work
	
	if ($revision_count > 1) {
		die "only one revision per page is allowed\n";
	}

	return Parse::MediaWikiDump::page->new($next, $self->namespaces, $self->get_category_anchor);
}


package #go away indexer! 
	Parse::MediaWikiDump::page;

use strict;
use warnings;

our %REGEX_CACHE_CATEGORIES;

sub new {
	my ($class, $page, $namespaces, $category_anchor, $revision) = @_;
	my $self = {page => $page, namespaces => $namespaces, category_anchor => $category_anchor};
	
	$self->{revision} = $revision;
	
	return bless($self, $class);
}

sub _revision {
	if (defined($_[0]->{revision})) { return $_[0]->{revision}};
	
	return $_[0]->{page}->revision;
}

sub text {
	my $text = $_[0]->_revision->text;
	return \$text;
}

sub title {
	return $_[0]->{page}->title;
}

sub id {
	return $_[0]->{page}->id;
}

sub revision_id {
	return $_[0]->_revision->id;
}

sub username {
	return $_[0]->_revision->contributor->username;
}

sub userid {
	return $_[0]->_revision->contributor->id;
}

sub userip {
	return $_[0]->_revision->contributor->ip;
}

sub timestamp {
	return $_[0]->_revision->timestamp;
}

sub minor {
	return $_[0]->_revision->minor;
}

sub namespace {
	my ($self) = @_;
	my $title = $self->title;
	my $namespace = '';
	
	if (defined($self->{cache}->{namespace})) {
		return $self->{cache}->{namespace};
	}
	
	if ($title =~ m/^([^:]+):(.*)/o) {
		foreach (@{ $self->{namespaces} } ) {
			my ($num, $name) = @$_;
			if ($1 eq $name) {
				$namespace = $1;
				last;
			}
		}
	}

	$self->{cache}->{namespace} = $namespace;

	return $namespace;
}

sub redirect {
	my ($self) = @_;
	my $text = $self->text;
	my $ret;
	
	return $self->{cache}->{redirect} if defined $self->{cache}->{redirect};

	if ($$text =~ m/^#redirect\s*:?\s*\[\[([^\]]*)\]\]/io) {
		$ret = $1;
	} else {
		$ret = undef;
	}
	
	$self->{cache}->{redirect} = $ret;
	
	return $ret;
}

sub categories {
	my ($self) = @_;
	my $anchor = $$self{category_anchor};
	my $text = $self->text;
	my @cats;
	my $ret;
	
	return $self->{cache}->{categories} if defined $self->{cache}->{categories};
	
	if (! defined($REGEX_CACHE_CATEGORIES{$anchor})) {
		$REGEX_CACHE_CATEGORIES{$anchor} = qr/\[\[$anchor:\s*([^\]]+)\]\]/i;
	}
		
	while($$text =~ /$REGEX_CACHE_CATEGORIES{$anchor}/g) {
		my $buf = $1;
		
		#deal with the pipe trick
		$buf =~ s/\|.*$//;
		push(@cats, $buf);
	}

	if (scalar(@cats) == 0) {
		$ret = undef;
	} else {
		$ret = \@cats;
	}

	return $ret;
}


1;

__END__

=head1 NAME

MediaWiki::DumpFile::Compat - Compatibility with Parse::MediaWikiDump

=head1 SYNOPSIS

  use MediaWiki::DumpFile::Compat;

  $pmwd = Parse::MediaWikiDump->new;

  $pages = $pmwd->pages('pages-articles.xml');
  $revisions = $pmwd->revisions('pages-articles.xml');
  $links = $pmwd->links('links.sql');
  
=head1 ABOUT

This software suite provides the tools needed to process the contents of the XML page 
dump files and the SQL based links dump file from a Mediawiki instance. This is a compatibility 
layer between MediaWiki::Dumpfile and Parse::MediaWikiDump; 
instead of "use Parse::MediaWikiDump;" you "use MediaWiki::DumpFile::Compat;". The benefit of
using the new compatibility module is an increased processing speed - see the 
MediaWiki::DumpFile::Benchmarks documentation for benchmark results. 

=head1 MORE DOCUMENTATION

The original Parse::MediaWikiDump documentation is also available in this package; it has been updated
to include new features introduced by MediaWiki::DumpFile. You can find the documentation in the following
locations:

=over 4

=item MediaWiki::DumpFile::Compat::Pages

=item MediaWiki::DumpFile::Compat::Revisions

=item MediaWiki::DumpFile::Compat::page

=item MediaWiki::DumpFile::Compat::Links

=item MediaWiki::DumpFile::Compat::link

=back

=head1 USAGE

This module is a factory class that allows you to create instances of the individual 
parser objects. 

=over 4

=item $pmwd->pages

Returns a Parse::MediaWikiDump::Pages object capable of parsing an article XML dump file with one revision per each article.

=item $pmwd->revisions

Returns a Parse::MediaWikiDump::Revisions object capable of parsing an article XML dump file with multiple revisions per each article.

=item $pmwd->links

Returns a Parse::MediaWikiDump::Links object capable of parsing an article links SQL dump file.

=back

=head2 General

All parser creation invocations require a location of source data
to parse; this argument can be either a filename or a reference to an already
open filehandle. This entire software suite will die() upon errors in the file or if internal inconsistencies
have been detected. If this concerns you then you can wrap the portion of your code that uses these calls with eval().

=head1 COMPATIBILITY 

Any deviation of the behavior of MediaWiki::DumpFile::Compat from Parse::MediaWikiDump that is not 
listed below is a bug. Please report it so that this package can act as a near perfect standin for
the original. Compatibility is verified by using the existing Parse::MediaWikiDump test suite with the 
following adjustments:

=head2 Parse::MediaWikiDump::Pages

=over 4

=item

Parse::MediaWikiDump did not need to load all revisions of an article into memory when processing
dump files that contain more than one revision but this compatibility module does. The API does not
change but the memory requirements for parsing those dump files certainly do. It is, however, highly
unlikely that you will notice this as most of the documents with many revisions per article are so large
that Parse::MediaWikiDump would not have been able to parse them in any reasonable timeframe. 

=item 

The order of the results from namespaces() is now sorted by the namespace ID instead of being in document order

=back

=head2 Parse::MediaWikiDump::Links

=over 4

=item 

Order of values from next() is now in identical order as SQL file.

=back

=head1 BUGS

=over 4

=item

The value of current_byte() wraps at around 2 gigabytes of input XML; see http://rt.cpan.org/Public/Bug/Display.html?id=56843

=back

=head1 LIMITATIONS

=over 4

=item 

This compatibility layer is not yet well tested.

=back