Skip to content

Commit

Permalink
merge and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
James Michael DuPont authored and James Michael DuPont committed Aug 6, 2012
2 parents bf42166 + 0b6b830 commit 0355868
Show file tree
Hide file tree
Showing 7 changed files with 1,175 additions and 46 deletions.
2 changes: 2 additions & 0 deletions config.cfg.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
username:your speedy deletion user
userpass:your speedy deletion user password
746 changes: 746 additions & 0 deletions dumpgenerator_single.py

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions fixattackpages.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
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;

$mw->edit( {
action => 'delete', title => $pagename, reason => 'Attack Pages' } )
|| 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: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 "going to delete $_->{title}\n";
EditPage $mw, $_->{title};
}
}

}


GetPages;
70 changes: 70 additions & 0 deletions fixattackpages_deletionpedia.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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;
$mw->edit( {
action => 'delete', title => $pagename, reason => 'Attack Pages' } )
|| warn $mw->{error}->{code} . ': ' . $mw->{error}->{details};

}

sub GetPages {
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = 'http://deletionpedia.dbatley.com/w/api.php';

my $mw2 = MediaWiki::API->new();
$mw2->{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;

$mw2->login( { lgname => $username, lgpassword => $userpass } )
|| die $mw2->{error}->{code} . ': ' . $mw2->{error}->{details};


foreach my $cat (
"Deletionpedia:Pages_blanked_after_complaints",
"Deletionpedia:Blanked_pages",
"Deletionpedia:Dangerous_pages"
){
print "checking $cat\n";
# get a list of articles in category
my $articles = $mw->list ( {
action => 'query',
list => 'categorymembers',
# cmtitle => $cat,
cmcategory => $cat,
# cmlimit => 'max'
cmlimit => '50',


#http://deletionpedia.dbatley.com/w/api.php?format=json&action=query&cmcategory=Deletionpedia:Pages_blanked_after_complaints&cmlimit=50&list=categorymembers
} )
|| die $mw->{error}->{code} . ': ' . $mw->{error}->{details};

# and print the article titles
foreach (@{$articles}) {
print "going to delete $_->{title}\n";
EditPage $mw2, $_->{title};
}
}

}


GetPages;
121 changes: 121 additions & 0 deletions fixcopyrightvio.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
47 changes: 1 addition & 46 deletions speedydeletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,6 @@
from shove import Shove
file_store = Shove('file://wikiaupload')

# def signpage(site,pagename) :

# generator = [pywikibot.Page(
# site,
# pagename
# )]
# # Main Loop
# for page in generator:
# print "going to process %s" % page.urlname()
# try:
# text = page.get()
# except:
# text = ""

# m = re.search("==archived on speedy deletion wikia==" , text)
# if not(m):
# m = re.search("==archived==" , text)
# if not( m):
# summary="notification of speedy deletion page"
# newname =page.urlname()
# newname = newname.replace('Talk%3A', '')
# newtext= "==archived on speedy deletion wikia==\nThis endangered article has been archived here http://speedydeletion.wikia.com/wiki/%s so that it is not lost if deleted. Changes made after the archiving will not be copied.\n~~~~" % newname
# (text, newtext, always) = add_text(page, newtext, summary, regexSkip,
# regexSkipUrl, always, up, True, reorderEnabled=reorderEnabled,
# create=talkPage)
# else:
# print "skipping %s" % page.urlname()
# else:
# print "skipping %s" % page.urlname()

def main(*args):
genFactory = pagegenerators.GeneratorFactory()
# If xmlfilename is None, references will be loaded from the live wiki.
Expand All @@ -51,45 +21,33 @@ def main(*args):
# read command line parameters
for arg in pywikibot.handleArgs(*args):
xmlfilename = arg

print xmlfilename

insite = pywikibot.getSite("en","wikipedia")

importsite = "speedydeletion"

outsite = pywikibot.getSite("en",importsite)
outsite.forceLogin()

dump = xmlreader.XmlDump(xmlfilename)
count = 0
for entry in dump.parse():
# print file_store[entry.title]
title=entry.title.encode("ascii","ignore")


if re.search("^Wikipedia:" , entry.title):
pywikibot.output(u'skipping %s' % entry.title)
continue

if re.search("^User:" , entry.title):
pywikibot.output(u'skipping %s' % entry.title)
continue

if re.search("^User Talk:" , entry.title):
pywikibot.output(u'skipping %s' % entry.title)
continue

if re.search(".css$" , entry.title):
pywikibot.output(u'skipping %s' % entry.title)
continue

if re.search("^Main Page" , entry.title):
pywikibot.output(u'skipping %s' % entry.title)
continue

pywikibot.output(u'Considering %s' % entry.title)

try :
if (file_store[title] ) :
count = count +1
Expand All @@ -103,8 +61,7 @@ def main(*args):
try:
file_store[title] = 1
except KeyError :
pywikibot.output(u'key error saving article %s' % entry.title)

pywikibot.output(u'key error saving article %s' % entry.title)
else:
pywikibot.output(u'is not there, adding %s' % entry.title)
contents = entry.text
Expand All @@ -113,7 +70,6 @@ def main(*args):
contents = contents + "<noinclude>{{wikipedia-template|%s}}</noinclude>" % usernames
else:
contents = contents + "\n{{wikipedia-deleted|%s}}" % usernames

outpage._site=outsite
outpage.put(contents)
try :
Expand All @@ -125,7 +81,6 @@ def main(*args):
finally:
count = count + 1


if __name__ == "__main__":
try:
main()
Expand Down
Loading

0 comments on commit 0355868

Please sign in to comment.