line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MediaWiki::CleanupHTML; |
2
|
|
|
|
|
|
|
$MediaWiki::CleanupHTML::VERSION = '0.0.5'; |
3
|
1
|
|
|
1
|
|
67512
|
use 5.008; |
|
1
|
|
|
|
|
14
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
525
|
use HTML::TreeBuilder::XPath; |
|
1
|
|
|
|
|
66248
|
|
|
1
|
|
|
|
|
10
|
|
9
|
1
|
|
|
1
|
|
65
|
use Scalar::Util (qw(blessed)); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
688
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new |
14
|
|
|
|
|
|
|
{ |
15
|
1
|
|
|
1
|
1
|
11800
|
my $class = shift; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
3
|
my $self = bless {}, $class; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
5
|
$self->_init(@_); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
9
|
return $self; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _is_processed |
25
|
|
|
|
|
|
|
{ |
26
|
3
|
|
|
3
|
|
9
|
my $self = shift; |
27
|
|
|
|
|
|
|
|
28
|
3
|
100
|
|
|
|
13
|
if (@_) |
29
|
|
|
|
|
|
|
{ |
30
|
2
|
|
|
|
|
53
|
$self->{_is_processed} = shift; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
3
|
|
|
|
|
11
|
return $self->{_is_processed}; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _fh |
37
|
|
|
|
|
|
|
{ |
38
|
2
|
|
|
2
|
|
3
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
2
|
100
|
|
|
|
6
|
if (@_) |
41
|
|
|
|
|
|
|
{ |
42
|
1
|
|
|
|
|
5
|
$self->{_fh} = shift; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
9
|
return $self->{_fh}; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _tree |
49
|
|
|
|
|
|
|
{ |
50
|
7
|
|
|
7
|
|
15
|
my $self = shift; |
51
|
|
|
|
|
|
|
|
52
|
7
|
100
|
|
|
|
22
|
if (@_) |
53
|
|
|
|
|
|
|
{ |
54
|
2
|
|
|
|
|
43
|
$self->{_tree} = shift; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
7
|
|
|
|
|
853
|
return $self->{_tree}; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _init |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
1
|
|
3
|
my ( $self, $args ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
1
|
50
|
|
|
|
4
|
if ( !exists( $args->{'fh'} ) ) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
|
|
|
|
0
|
Carp::confess( |
67
|
|
|
|
|
|
|
"MediaWiki::CleanupHTML->new was not passed a filehandle."); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
4
|
$self->_fh( $args->{fh} ); |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
10
|
my $tree = HTML::TreeBuilder::XPath->new; |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
319
|
$self->_tree($tree); |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
2
|
$self->_tree->parse_file( $self->_fh ); |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
965736
|
$self->_is_processed(0); |
79
|
|
|
|
|
|
|
|
80
|
1
|
|
|
|
|
5
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _process |
84
|
|
|
|
|
|
|
{ |
85
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
86
|
|
|
|
|
|
|
|
87
|
1
|
50
|
|
|
|
5
|
if ( $self->_is_processed() ) |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
|
|
0
|
return; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
|
|
6
|
my $tree = $self->_tree; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
{ |
95
|
1
|
|
|
|
|
16
|
my @nodes = $tree->findnodes('//div[@class="editsection"]'); |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
727166
|
foreach my $n (@nodes) |
98
|
|
|
|
|
|
|
{ |
99
|
0
|
|
|
|
|
0
|
$n->detach(); |
100
|
0
|
|
|
|
|
0
|
$n->delete(); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
{ |
105
|
1
|
|
|
|
|
2
|
my @nodes = map { $tree->findnodes( '//h' . $_ ) } ( 2 .. 4 ); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
462205
|
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
226234
|
foreach my $h2 (@nodes) |
108
|
|
|
|
|
|
|
{ |
109
|
30
|
|
|
|
|
273
|
my $a_tag = $h2->left(); |
110
|
30
|
50
|
66
|
|
|
4624
|
if ( blessed($a_tag) |
|
|
|
33
|
|
|
|
|
111
|
|
|
|
|
|
|
&& $a_tag->tag() eq "a" |
112
|
|
|
|
|
|
|
&& $a_tag->attr('name') ) |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
|
|
0
|
my $id = $a_tag->attr('name'); |
115
|
0
|
|
|
|
|
0
|
$h2->attr( 'id', $id ); |
116
|
0
|
|
|
|
|
0
|
$a_tag->detach(); |
117
|
0
|
|
|
|
|
0
|
$a_tag->delete(); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
1
|
|
|
|
|
7
|
my (@divs_to_delete) = ( |
123
|
|
|
|
|
|
|
$tree->findnodes('//div[@class="printfooter"]'), |
124
|
|
|
|
|
|
|
$tree->findnodes('//div[@id="catlinks"]'), |
125
|
|
|
|
|
|
|
$tree->findnodes('//div[@class="visualClear"]'), |
126
|
|
|
|
|
|
|
$tree->findnodes('//div[@id="column-one"]'), |
127
|
|
|
|
|
|
|
$tree->findnodes('//div[@id="footer"]'), |
128
|
|
|
|
|
|
|
$tree->findnodes('//head//style'), |
129
|
|
|
|
|
|
|
$tree->findnodes('//script'), |
130
|
|
|
|
|
|
|
); |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
|
|
4056420
|
foreach my $div (@divs_to_delete) |
133
|
|
|
|
|
|
|
{ |
134
|
14
|
|
|
|
|
1264
|
$div->detach(); |
135
|
14
|
|
|
|
|
452
|
$div->delete(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
14
|
$self->_is_processed(1); |
139
|
|
|
|
|
|
|
|
140
|
1
|
|
|
|
|
8
|
return; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub print_into_fh |
145
|
|
|
|
|
|
|
{ |
146
|
1
|
|
|
1
|
1
|
1816
|
my ( $self, $fh ) = @_; |
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
|
|
6
|
$self->_process(); |
149
|
|
|
|
|
|
|
|
150
|
1
|
|
|
|
|
2
|
print {$fh} $self->_tree->as_XML(); |
|
1
|
|
|
|
|
7
|
|
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub destroy_resources |
155
|
|
|
|
|
|
|
{ |
156
|
2
|
|
|
2
|
1
|
551221
|
my $self = shift; |
157
|
|
|
|
|
|
|
|
158
|
2
|
|
|
|
|
8
|
$self->_tree->delete(); |
159
|
1
|
|
|
|
|
42608
|
$self->_tree( undef() ); |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
4
|
return; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub DESTROY |
165
|
|
|
|
|
|
|
{ |
166
|
1
|
|
|
1
|
|
558
|
my $self = shift; |
167
|
|
|
|
|
|
|
|
168
|
1
|
|
|
|
|
4
|
$self->destroy_resources(); |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
return; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
1; # End of MediaWiki::CleanupHTML |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
__END__ |