-
Notifications
You must be signed in to change notification settings - Fork 6
/
fixcopyrightvio.pl
121 lines (95 loc) · 2.8 KB
/
fixcopyrightvio.pl
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
use warnings;
use strict;
use MediaWiki::API;
# http://seahttp://search.cpan.org/~dcollins/MediaWiki-Bot-2.3.1/lib/MediaWiki/Bot.pm
sub EditPage {
my $mw=shift;
my $pagename = shift;
my $ref = $mw->get_page( { title => $pagename } );
my $text= $ref->{'*'};
my $newtext = "{{copyvioblanked|$pagename}}\n";
my $linktext;
my $reftext;
unless ( $ref->{missing} ) {
my $timestamp = $ref->{timestamp};
my $count =0;
my $text2=$text;
while ($text2 =~ s/\[\s*(http:[^\s\|\}\]]+)\]/DONE/g) { $linktext .= "* {{copyviolink|$1}}\n"; }
# just grabe the raw http
while ($text2 =~ s/(http:[^\s\|\}\]]+)\]/DONE/g) { $linktext .= "* {{copyviolink|$1}}\n"; }
while ($text2 =~ s/(https:[^\s\|\}\]]+)\]/DONE/g) { $linktext .= "* {{copyviolink|$1}}\n"; }
while ($text2 =~ s/\=(http:[^\s\|\}\]]+)\}/DONE/g) { $linktext .= "* {{copyviolink|$1}}\n"; }
if ($linktext){
$newtext .= "==External Links==\n$linktext";
}
while ($text =~ m/<ref>([^\<]+)<\/ref>/g)
{
$reftext .= "*<ref>$1</ref>\n";
}
if ($reftext)
{
$newtext .= "==References==\n$reftext";
$newtext .= "\n<references/>\n";
}
#Creative CommonsAttribution-Share Alike 3.0 Unported license
print "NewText : $newtext";
if (1) {
$mw->edit(
{
action => 'edit',
title => $pagename,
basetimestamp => $timestamp, # to avoid edit conflicts
text => $newtext
}
)
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
}
}
}
sub GetPages {
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://speedydeletion.wikia.com/api.php';
my $username;
my $userpass;
open IN, "<config.cfg" or die;
while (<IN>)
{
if (/username:(.+)/)
{
$username=$1;
}
elsif (/userpass:(.+)/)
{
$userpass=$1;
}
}
close IN;
#print "User:$username Pass:$userpass\n";
die unless $username;
die unless $userpass;
$mw->login( { lgname => $username, lgpassword => $userpass } )
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
foreach my $cat (
"Category:CopyVioNotMentioned",
"Category:Possible_copyright_violations",
"Category:Articles_tagged_for_copyright_problems",
"Category:Candidates_for_speedy_deletion_as_copyright_violations",
"Category:All_copied_and_pasted_articles_and_sections",
"Category:Candidates_for_speedy_deletion_by_user", # we dont want to keep what the author does not want.
# "Category:Candidates_for_speedy_deletion_as_attack_pages"
){
# get a list of articles in category
my $articles = $mw->list ( {
action => 'query',
list => 'categorymembers',
cmtitle => $cat,
cmlimit => 'max' } )
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
# and print the article titles
foreach (@{$articles}) {
print "$_->{title}\n";
EditPage $mw, $_->{title};
}
}
}
GetPages;