| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Parse::MediaWikiDump; |
|
2
|
|
|
|
|
|
|
our $VERSION = '1.0.6_02'; |
|
3
|
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
99488
|
use Parse::MediaWikiDump::XML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use Parse::MediaWikiDump::Revisions; |
|
6
|
|
|
|
|
|
|
use Parse::MediaWikiDump::Pages; |
|
7
|
|
|
|
|
|
|
use Parse::MediaWikiDump::page; |
|
8
|
|
|
|
|
|
|
use Parse::MediaWikiDump::Links; |
|
9
|
|
|
|
|
|
|
use Parse::MediaWikiDump::link; |
|
10
|
|
|
|
|
|
|
use Parse::MediaWikiDump::CategoryLinks; |
|
11
|
|
|
|
|
|
|
use Parse::MediaWikiDump::category_link; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#the POD is at the end of this file |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
|
16
|
|
|
|
|
|
|
my ($class) = @_; |
|
17
|
|
|
|
|
|
|
return bless({}, $class); |
|
18
|
|
|
|
|
|
|
} |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub pages { |
|
21
|
|
|
|
|
|
|
shift(@_); |
|
22
|
|
|
|
|
|
|
return Parse::MediaWikiDump::Pages->new(@_); |
|
23
|
|
|
|
|
|
|
} |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub revisions { |
|
26
|
|
|
|
|
|
|
shift(@_); |
|
27
|
|
|
|
|
|
|
return Parse::MediaWikiDump::Revisions->new(@_); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub links { |
|
31
|
|
|
|
|
|
|
shift(@_); |
|
32
|
|
|
|
|
|
|
return Parse::MediaWikiDump::Links->new(@_); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#just a place holder for something that might be used in the future |
|
36
|
|
|
|
|
|
|
#package Parse::MediaWikiDump::ExternalLinks; |
|
37
|
|
|
|
|
|
|
# |
|
38
|
|
|
|
|
|
|
#use strict; |
|
39
|
|
|
|
|
|
|
#use warnings; |
|
40
|
|
|
|
|
|
|
# |
|
41
|
|
|
|
|
|
|
#sub new { |
|
42
|
|
|
|
|
|
|
# my ($class, $source) = @_; |
|
43
|
|
|
|
|
|
|
# my $self = {}; |
|
44
|
|
|
|
|
|
|
# |
|
45
|
|
|
|
|
|
|
# $$self{BUFFER} = []; |
|
46
|
|
|
|
|
|
|
# $$self{BYTE} = 0; |
|
47
|
|
|
|
|
|
|
# |
|
48
|
|
|
|
|
|
|
# bless($self, $class); |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
# $self->open($source); |
|
51
|
|
|
|
|
|
|
# $self->init; |
|
52
|
|
|
|
|
|
|
# |
|
53
|
|
|
|
|
|
|
# return $self; |
|
54
|
|
|
|
|
|
|
#} |
|
55
|
|
|
|
|
|
|
# |
|
56
|
|
|
|
|
|
|
#sub next { |
|
57
|
|
|
|
|
|
|
# my ($self) = @_; |
|
58
|
|
|
|
|
|
|
# my $buffer = $$self{BUFFER}; |
|
59
|
|
|
|
|
|
|
# my $link; |
|
60
|
|
|
|
|
|
|
# |
|
61
|
|
|
|
|
|
|
# while(1) { |
|
62
|
|
|
|
|
|
|
# if (defined($link = pop(@$buffer))) { |
|
63
|
|
|
|
|
|
|
# last; |
|
64
|
|
|
|
|
|
|
# } |
|
65
|
|
|
|
|
|
|
# |
|
66
|
|
|
|
|
|
|
# #signals end of input |
|
67
|
|
|
|
|
|
|
# return undef unless $self->parse_more; |
|
68
|
|
|
|
|
|
|
# } |
|
69
|
|
|
|
|
|
|
# |
|
70
|
|
|
|
|
|
|
# return Parse::MediaWikiDump::external_link->new($link); |
|
71
|
|
|
|
|
|
|
#} |
|
72
|
|
|
|
|
|
|
# |
|
73
|
|
|
|
|
|
|
##private functions with OO interface |
|
74
|
|
|
|
|
|
|
#sub parse_more { |
|
75
|
|
|
|
|
|
|
# my ($self) = @_; |
|
76
|
|
|
|
|
|
|
# my $source = $$self{SOURCE}; |
|
77
|
|
|
|
|
|
|
# my $need_data = 1; |
|
78
|
|
|
|
|
|
|
# |
|
79
|
|
|
|
|
|
|
# while($need_data) { |
|
80
|
|
|
|
|
|
|
# my $line = <$source>; |
|
81
|
|
|
|
|
|
|
# |
|
82
|
|
|
|
|
|
|
# last unless defined($line); |
|
83
|
|
|
|
|
|
|
# |
|
84
|
|
|
|
|
|
|
# $$self{BYTE} += length($line); |
|
85
|
|
|
|
|
|
|
# |
|
86
|
|
|
|
|
|
|
# while($line =~ m/\((\d+),'(.*?)','(.*?)'\)[;,]/g) { |
|
87
|
|
|
|
|
|
|
# push(@{$$self{BUFFER}}, [$1, $2, $3]); |
|
88
|
|
|
|
|
|
|
# $need_data = 0; |
|
89
|
|
|
|
|
|
|
# } |
|
90
|
|
|
|
|
|
|
# } |
|
91
|
|
|
|
|
|
|
# |
|
92
|
|
|
|
|
|
|
# #if we still need data and we are here it means we ran out of input |
|
93
|
|
|
|
|
|
|
# if ($need_data) { |
|
94
|
|
|
|
|
|
|
# return 0; |
|
95
|
|
|
|
|
|
|
# } |
|
96
|
|
|
|
|
|
|
# |
|
97
|
|
|
|
|
|
|
# return 1; |
|
98
|
|
|
|
|
|
|
#} |
|
99
|
|
|
|
|
|
|
# |
|
100
|
|
|
|
|
|
|
#sub open { |
|
101
|
|
|
|
|
|
|
# my ($self, $source) = @_; |
|
102
|
|
|
|
|
|
|
# |
|
103
|
|
|
|
|
|
|
# if (ref($source) ne 'GLOB') { |
|
104
|
|
|
|
|
|
|
# die "could not open $source: $!" unless |
|
105
|
|
|
|
|
|
|
# open($$self{SOURCE}, $source); |
|
106
|
|
|
|
|
|
|
# |
|
107
|
|
|
|
|
|
|
# $$self{SOURCE_FILE} = $source; |
|
108
|
|
|
|
|
|
|
# } else { |
|
109
|
|
|
|
|
|
|
# $$self{SOURCE} = $source; |
|
110
|
|
|
|
|
|
|
# } |
|
111
|
|
|
|
|
|
|
# |
|
112
|
|
|
|
|
|
|
# binmode($$self{SOURCE}, ':utf8'); |
|
113
|
|
|
|
|
|
|
# |
|
114
|
|
|
|
|
|
|
# return 1; |
|
115
|
|
|
|
|
|
|
#} |
|
116
|
|
|
|
|
|
|
# |
|
117
|
|
|
|
|
|
|
#sub init { |
|
118
|
|
|
|
|
|
|
# my ($self) = @_; |
|
119
|
|
|
|
|
|
|
# my $source = $$self{SOURCE}; |
|
120
|
|
|
|
|
|
|
# my $found = 0; |
|
121
|
|
|
|
|
|
|
# |
|
122
|
|
|
|
|
|
|
# while(<$source>) { |
|
123
|
|
|
|
|
|
|
# if (m/^LOCK TABLES `externallinks` WRITE;/) { |
|
124
|
|
|
|
|
|
|
# $found = 1; |
|
125
|
|
|
|
|
|
|
# last; |
|
126
|
|
|
|
|
|
|
# } |
|
127
|
|
|
|
|
|
|
# } |
|
128
|
|
|
|
|
|
|
# |
|
129
|
|
|
|
|
|
|
# die "not a MediaWiki link dump file" unless $found; |
|
130
|
|
|
|
|
|
|
#} |
|
131
|
|
|
|
|
|
|
# |
|
132
|
|
|
|
|
|
|
#sub current_byte { |
|
133
|
|
|
|
|
|
|
# my ($self) = @_; |
|
134
|
|
|
|
|
|
|
# |
|
135
|
|
|
|
|
|
|
# return $$self{BYTE}; |
|
136
|
|
|
|
|
|
|
#} |
|
137
|
|
|
|
|
|
|
# |
|
138
|
|
|
|
|
|
|
#sub size { |
|
139
|
|
|
|
|
|
|
# my ($self) = @_; |
|
140
|
|
|
|
|
|
|
# |
|
141
|
|
|
|
|
|
|
# return undef unless defined $$self{SOURCE_FILE}; |
|
142
|
|
|
|
|
|
|
# |
|
143
|
|
|
|
|
|
|
# my @stat = stat($$self{SOURCE_FILE}); |
|
144
|
|
|
|
|
|
|
# |
|
145
|
|
|
|
|
|
|
# return $stat[7]; |
|
146
|
|
|
|
|
|
|
#} |
|
147
|
|
|
|
|
|
|
# |
|
148
|
|
|
|
|
|
|
#package Parse::MediaWikiDump::external_link; |
|
149
|
|
|
|
|
|
|
# |
|
150
|
|
|
|
|
|
|
##you must pass in a fully populated link array reference |
|
151
|
|
|
|
|
|
|
#sub new { |
|
152
|
|
|
|
|
|
|
# my ($class, $self) = @_; |
|
153
|
|
|
|
|
|
|
# |
|
154
|
|
|
|
|
|
|
# bless($self, $class); |
|
155
|
|
|
|
|
|
|
# |
|
156
|
|
|
|
|
|
|
# return $self; |
|
157
|
|
|
|
|
|
|
#} |
|
158
|
|
|
|
|
|
|
# |
|
159
|
|
|
|
|
|
|
#sub from { |
|
160
|
|
|
|
|
|
|
# my ($self) = @_; |
|
161
|
|
|
|
|
|
|
# return $$self[0]; |
|
162
|
|
|
|
|
|
|
#} |
|
163
|
|
|
|
|
|
|
# |
|
164
|
|
|
|
|
|
|
#sub to { |
|
165
|
|
|
|
|
|
|
# my ($self) = @_; |
|
166
|
|
|
|
|
|
|
# return $$self[1]; |
|
167
|
|
|
|
|
|
|
#} |
|
168
|
|
|
|
|
|
|
# |
|
169
|
|
|
|
|
|
|
#sub index { |
|
170
|
|
|
|
|
|
|
# my ($self) = @_; |
|
171
|
|
|
|
|
|
|
# return $$self[2]; |
|
172
|
|
|
|
|
|
|
#} |
|
173
|
|
|
|
|
|
|
# |
|
174
|
|
|
|
|
|
|
#sub timestamp { |
|
175
|
|
|
|
|
|
|
# my ($self) = @_; |
|
176
|
|
|
|
|
|
|
# return $$self[3]; |
|
177
|
|
|
|
|
|
|
# |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
__END__ |