Jump to content

User:Tweakbot/tweakbot.pl

From Wikipedia, the free encyclopedia
/Wikipedia.pm /Wikipedia/Page.pm /tweakbot.pl
#!/usr/bin/perl -w
use strict;

use constant USERNAME		=> 'Tweakbot';
use constant PASSWORD		=> ''; # password deleted

use constant COOKIES		=> 'tweakbot.txt';

use constant EDIT_SUMMARY	=> 'Tweakbot reporting for duty! (replaced depreciated template)';
use constant EDIT_MINOR		=> 1;

use Wikipedia;

my $wiki = Wikipedia->new(
	'username'	=> USERNAME,
	'password'	=> PASSWORD,
	'cookie_file'	=> COOKIES,
);

foreach my $pagename (@ARGV) {
	my $page = $wiki->get_page($pagename);
	my $old_contents = $page->contents;
	(my $new_contents = $old_contents) =~ s/\{\{ref-section\}\}/==References==\n{{Reflist}}/gi;
	unless ($new_contents eq $old_contents) {
		print STDERR "updating `$pagename'\n";
		print "$new_contents\n";
		$page->put_contents($new_contents, EDIT_SUMMARY, EDIT_MINOR);
	} else {
		print STDERR "nothing to do for `$pagename'\n";
	}
}