GuildWiki:Bot tasks/Builds redlinks rewrite

Description
This script rewrites orphaned links to the old Build: namespace articles, pointing them instead to the appropriate article on the PvX Wiki.


 * Language: Perl
 * Uses the module Perlwikipedia for most wiki interface tasks.
 * Throttle: 360 edits/hour (10 seconds between edits)
 * Process:
 * Scans Special:Wantedpages for links to builds, which are identified by beginning with "Team" or a profession abbreviation followed by a slash, such as "W/".
 * Checks a correspondence file (to be compiled by Ereanor) for the new name of the build on PvX Wiki.
 * For each build redlink found, scans Special:Whatlinkshere for that link and gets a list of the articles containing that specific redlink.
 * For each article containing a build redlink, edits the article to rewrite the link as follows:

Code
use strict;
 * 1) !/usr/bin/perl

use Perlwikipedia;

my %corr; open (INF, "corr.txt") or die "can't open file: $!\n"; while () { my ($old, $new) = split /;/; $corr{$old} = $new; } close (INF);
 * 1) Read Ereanor's correspondence file

my $user = 'Bot ishmael'; my $pass = $ARGV[0]; my $editor = Perlwikipedia->new($user); $editor->set_wiki('guildwars.wikia.com',''); $editor->login($user, $pass);
 * 1) Create a Perlwikipedia object and login

$editor->{debug} = 1;
 * 1) Turn debugging on, to see what the bot is doing

my $is_minor = 1; my $edit_summary='Builds redlinks rewrite by Bot ishmael';
 * 1) Editing options

my @builds = builds_from_wantedpages; # Custom function not from Perlwikipedia; see below
 * 1) Pull all build redlinks from Special:Wantedpages

foreach my $buildname (@builds) { # Get the new buildname my $new_buildname = $corr{$buildname}; # Get the list of articles linking to this build my @what_links_here = $editor->what_links_here($buildname); foreach my $article (@what_links_here) { # Get the text of the article my $text = $editor->get_text($article); # Rewrite the links $text =~ s/\[\[$buildname\]\]/\[\[PvX:Build:$new_buildname\|\]\]/g; # Save the article $editor->edit($article, $text, $edit_summary, $is_minor); # Wait 10 seconds before making another edit sleep 10; } }



sub builds_from_wantedpages { my @links;

my $res = $editor->_get( 'Special:Wantedpages', 'view',       "&limit=5" ); unless ($res) { return 1; } my $content = $res->decoded_content; while ( $content =~ m{<a href="/index.php\?title=(.*?)&amp;action=edit"}g ) {		my $title = $1; $title =~ s/^Build://; # Only pass through titles that look like build articles if (			$title =~ m{^Team} || $title =~ m{^W/} || $title =~ m{^R/} || $title =~ m{^Me/} || $title =~ m{^Mo/} || $title =~ m{^N/}			|| $title =~ m{^E/} || $title =~ m{^A/} || $title =~ m{^Rt/} || $title =~ m{^D/} || $title =~ m{^P/}			) {       	push @links, $title; }   }

return @links; }

__END__