<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
use MediaWiki::Bot;
our $VERSION = '1.0.1';

=head1 COPYING

Copyright (C) 2006, 2007 by Dan Collins &lt;DCOLLINS@cpan.org&gt;

This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

=cut

$editor=new MediaWiki::Bot('Bot/WP/EN/ST47/CSDWarnBot', "&amp;assert=bot", "ST47");
open(FH, './pass'); 
$password=&lt;FH&gt;;
chomp($password);
close FH;
$editor-&gt;login('CSDWarnBot', $password);

#First, we need a list of pages
@pages=$editor-&gt;get_pages_in_category('Category:Candidates for speedy deletion');

#Ok. Here's how it works.
#First, figure out the deletion reason
#Use an assoc.array to figure out what to do with it
#Warn the user
%templates=("db-web" =&gt; "User:CSDWarnBot/web-warn",
"db-empty" =&gt; "User:CSDWarnBot/empty-warn",
"db-nocontext" =&gt; "User:CSDWarnBot/empty-warn",
"db-foreign" =&gt; "User:CSDWarnBot/foreign-warn",
"db-notenglish" =&gt; "User:CSDWarnBot/foreign-warn",
"db-nocontent" =&gt; "User:CSDWarnBot/empty-warn",
"db-blankcsd" =&gt; "User:CSDWarnBot/blank-warn",
"db-transwiki" =&gt; "User:CSDWarnBot/transwiki-warn",
"db-attack" =&gt; "User:CSDWarnBot/attack-warn",
"db-band" =&gt; "User:CSDWarnBot/nn-warn",
"db-club" =&gt; "User:CSDWarnBot/nn-warn",
"db-bio" =&gt; "User:CSDWarnBot/nn-warn",
"db-inc" =&gt; "User:CSDWarnBot/nn-warn",
"db-shoutout" =&gt; "User:CSDWarnBot/nn-warn",
"db-catempty" =&gt; "User:CSDWarnBot/catempty-warn",
"db-c2" =&gt; "User:CSDWarnBot/c2-warn",
"db-catfd" =&gt; "User:CSDWarnBot/catfd-warn",
"db-pagemove" =&gt; "User:CSDWarnBot/pagemove-warn",
"db-nonsense" =&gt; "User:CSDWarnBot/nonsense-warn",
"db-spam" =&gt; "User:CSDWarnBot/spam-warn",
"db-copyvio" =&gt; "User:CSDWarnBot/copyvio-warn",
"db-g12" =&gt; "User:CSDWarnBot/copyvio-warn",
"db-test" =&gt; "User:CSDWarnBot/test-warn",
"db-vandalism" =&gt; "User:CSDWarnBot/vandalism-warn",
"db-repost" =&gt; "User:CSDWarnBot/repost-warn",
"db-disambig" =&gt; "User:CSDWarnBot/disambig-warn",
"db-redundantimage" =&gt; "User:CSDWarnBot/badname-warn",
"db-noimage" =&gt; "User:CSDWarnBot/noimage-warn",
"db-noncom" =&gt; "User:CSDWarnBot/noncom-warn",
"db-ccnoncom" =&gt; "User:CSDWarnBot/noncom-warn",
"db-unksource" =&gt; "User:CSDWarnBot/unksource-warn",
"db-norat" =&gt; "User:CSDWarnBot/norat-warn",
"db-badfairuse" =&gt; "User:CSDWarnBot/badfairuse-warn",
"duplicate" =&gt; "User:CSDWarnBot/badname-warn",
"db-emptyportal" =&gt; "User:CSDWarnBot/emptyportal-warn",
"db-redirnone" =&gt; "User:CSDWarnBot/redirnone-warn",
"db-redirtypo" =&gt; "User:CSDWarnBot/redirtypo-warn",
"csd-c3" =&gt; "User:CSDWarnBot/catfd-warn",
"cc-by-nc-sa" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-nd-nc" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-nc" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-nc-2.0" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-nc-sa-2.0" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-nd-nc-2.0" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-2.0-nc-nd" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-nc-nd-2.0" =&gt; "User:CSDWarnBot/noncom-warn",
"db-contact" =&gt; "User:CSDWarnBot/empty-warn",
"db-i2" =&gt; "User:CSDWarnBot/noimage-warn",
"db-i1" =&gt; "User:CSDWarnBot/badname-warn",
"communityUseOnly" =&gt; "User:CSDWarnBot/noncom-warn",
"cc-by-nc-nd-2.5-it" =&gt; "User:CSDWarnBot/noncom-warn",
"db-disparage" =&gt; "User:CSDWarnBot/disparage-warn",
"db-u3" =&gt; "User:CSDWarnBot/u3-warn");

open(FH, '.CWB');
foreach $record (&lt;FH&gt;) {
	chomp($record);
	$warned{$record}++; #Pages we've already seen.
}
close FH;

MAIN: foreach (@pages) {
	$warntemplate="";
	$page=$_;
	print "-"x80;
	print "$page\n";
	$pagetext=$editor-&gt;get_text($page);
	$pagetext='' if $pagetext==2;
	#Now, let's iterate through the templates until we find one we can use
	TT: while ($pagetext=~/\{\{(.+?)[\|\}]/g) {
		$template=$1;
#		print "$template\n";
		foreach (keys %templates) { #This loop could be done with a single $templates{lc($template)}
			$testing=$_;
#			print ":$testing\n";
			if (lc($template) eq lc($testing)) {
				$warntemplate=$templates{$testing};
				print "$template\n";
				print "$warntemplate\n";
				last TT;
			}
		}
	}
	if ($warntemplate) {
		@hist=$editor-&gt;get_users($page, 50);
		unless (@hist) {next MAIN}
		if (scalar(@hist) &gt;= 48) {next MAIN}
		$user1=shift(@hist);
		$user=pop(@hist);
		$user2=shift(@hist);
		print "$user, $user1\n";
		if (($user eq $user1) or (not $user1)) {print "No other contributors\n"; next MAIN;}
		if ($user=~/ecretlondon/) {next MAIN;} #Optout.
		$ut="User talk:$user";
		$utt=$editor-&gt;get_text($ut);
		$utt='' if $utt==2;
		next MAIN if $utt==1;
		($pagenons=$page)=~s/.+:(.+)/\1/; #There was a time I knew what this did. Not anymore. I believe the assignment returns the left side, if that helps.
		if ($utt=~/$page/i) {
			print "Warned\n";
			next;
		}
		if ($utt=~/\Q$page\E/i) { #Why can't we use one single regex?
			print "Warned\n";
			next;
		}
		if ($utt=~/:$pagenons/i) {
			print "Warned\n";
			next;
		}
		if ($utt=~/\Q:$pagenons\E/i) {
			print "Warned\n";
			next;
		}
		if ($utt=~/User:CSDWarnBot/s) {
			print "Not spamming\n";
			next;
		}
		if ($utt=~/\{nobots/i) { #I can't be bothered to implement the full exclusion standard. If you're using nobots and you want these messages, fuck you.
			print "Bot excluded from page\n";
			next;
		}
		if ($warned{lc($pagenons)}) {
			print "Flood control\n";
			next;
		}
		$warned{lc($pagenons)}++;
		$utt .= "\n\n{{subst:$warntemplate|$page}} ~~~~";
		$editor-&gt;edit($ut, $utt, "Regarding [[$page]]");
		print "Sent!\n";
	}
}

open(FH, "&gt;.CWB"); #This text file is probably fucking huge.
foreach (keys %warned) { 
	print FH "$_\n";
}
close FH;

=head1 NAME

CSDWarnBot, a Wikipedia bot for advising users of pages which are tagged 
for speedy deletion.

=pod SCRIPT CATEGORIES

Web

=cut
</pre></body></html>