--- csb.pl	2012-07-24 03:15:52.000000000 +0000
+++ csb.pl	2013-03-23 16:55:15.263013673 +0000
@@ -7,6 +7,7 @@
 use HTTP::Cookies;
 use HTML::Parse;
 use HTML::FormatText;
+use HTML::Entities qw(decode_entities);
 use URI::Escape qw(uri_escape uri_escape_utf8 uri_unescape);
 use JSON;
 use Net::OAuth;
@@ -361,20 +362,23 @@
 			 'list=recentchanges',
 			 $limit,
 			 'rctype=new',
-			 'rcnamespace=0',
+			 'rcnamespace=0|5',
 			 'format=xml');
     my @news;
     my $maxrid = 0;
     my $maxts;
     $last_revid = 0 if not defined $last_revid;
     foreach my $rc ($list =~ m/<rc [^>]*>/ogis) {
-	next if not $rc =~ m/title="([^"]*)" .*? revid="([0-9]+)" .* timestamp="([^"]*)"/ois;
-	last if $2 <= $last_revid;
-	if($2 > $maxrid) {
-	    $maxrid = $2;
-	    $maxts = $3;
+	next if not $rc =~ m/ns="(\d+)" title="([^"]*)" .*? revid="([0-9]+)" .* timestamp="([^"]*)"/ois;
+	last if $3 <= $last_revid;
+	if($3 > $maxrid) {
+	    $maxrid = $3;
+	    $maxts = $4;
 	}
-	push @news, $1;
+	if ($1 eq "5") {
+	    next if not $2 =~ /Wikipedia talk:Articles for creation\//;
+	}
+	push @news, $2;
     }
     if($maxrid > $last_revid) {
 	$last_revid = $maxrid;
@@ -503,6 +507,7 @@
     my $title = $_[0];
     $title =~ s/\(.*?\) *//;
     $title =~ s/ *$//;
+    $title =~ s/^Wikipedia talk:Articles for creation\///;
 
     $stat{'title'} = $title;
     $stat{'uri'} = { };
@@ -701,7 +706,7 @@
 
 sub TagPage($$$) {
     my($title, $type, $what) = @_;
-    my $tag = "{{csb-$type|1=$what}}";
+    my $tag = "{{User:MadmanBot/Csb-$type|1=$what}}";
 
     my $user = WPCreator($title);
     foreach my $ally (@allies) {
@@ -740,10 +745,12 @@
 	return "marked-copyvio"			if $text =~ m/{{copyvio/;
 	return "public-domain"			if $text =~ m/{{NIST-PT\s*[|}]/i;
 	return "public-domain"			if $text =~ m/{{USGS-gazetteer\s*[|}]/i;
+	return "public-domain"			if $text =~ m/{{Bryan\s*[|}]/i;
 #
 # End of customizable exclusions
 #
-	return "already-tagged"			if $text =~ m/{{csb-/;
+	return "already-tagged"			if $text =~ m/{{csb-/ or $text =~ m/{{User:MadmanBot\/Csb-/;
+	return "already-tagged"			if $type eq 'wikipage' && decode_entities($title) eq decode_entities($what);
 #	return "page-gone"			if length($text)<20;
 
 	ReportStatus('match', "Reporting copy");
@@ -751,18 +758,15 @@
 	if(WPTryEdit($ttl, $token, $more, $text, "Tagging possible copyvio of $what", 1))
 	  {
 	    return undef if ($user eq '') or not defined $user; # Page tagged - no user to notify?
-	    while(1) {
 		my $ec = WPEditcount($user);
 		my $who = (defined $ec and $ec>=500)? 'experienced': 'newbie';
 		my $which = (int(rand(2)))? 'current': 'test';
 		($ttl, $token, $more, $text) = WPStartEdit($user);
 		last if not defined $token;
-		$text = "{{subst:welcomelaws-$which}}\n" if not defined $text or $text eq '';
+		$text = "{{subst:User:MadmanBot/Welcomelaws-$which}}\n" if not defined $text or $text eq '';
 		$which = (int(rand(2)))? 'current': 'test';
-		$text .= "\n{{subst:csb-notice-$type-$who-$which|$title|url=$what}} ~~~~\n";
-		last if WPTryEdit($ttl, $token, $more, $text, "Notifying user of possible copyvio on $title ($who/$which)", undef);
-	    }
-	    while(1) {
+		$text .= "\n{{subst:User:MadmanBot/Csb-notice-$type-$who-$which|$title|url=$what}} ~~~~\n";
+		WPTryEdit($ttl, $token, $more, $text, "Notifying user of possible copyvio on $title ($who/$which)", undef);
 		my $rto = $config{ReportTo};
 		my(undef,undef,undef,$mday,$mon,$year,undef,undef,undef) = gmtime;
 		$today = sprintf("%04d-%02d-%02d", $year+1900, $mon+1, $mday);
@@ -771,16 +775,25 @@
 		last if not defined $token;
 		my $esctitle = $title;
 		$esctitle =~ s/[)(]/\\$1/g;
-		my $re = qr/{{La\|$esctitle}}/s;
-		last if $text =~ $re;
-		$text = "{{subst:Csb-day|$today}}\n\n" if not $text =~ /{{La/;
+		my $re = qr/{{La\/x\|$esctitle}}/s;
+		last if $text =~ $re or $text =~ qr/{{La\|$esctitle}}/s;
+		$text = "{{subst:User:MadmanBot/Csb-day|$today}}\n\n" if not $text =~ /{{La/;
 		if($type eq 'wikipage') {
-		    $text .= "\n* {{La|$title}} &mdash; [[$what]]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    if ($title =~ /^Wikipedia talk:/) {
+		        $param = $title =~ s/^Wikipedia talk://r;
+		        $text .= "\n* {{Lwt|$param}} &mdash; [[$what]]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    } else {
+		        $text .= "\n* {{La/x|$title}} &mdash; [[$what]]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    }
 		} else {
-		    $text .= "\n* {{La|$title}} &mdash; [$what $what]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    if ($title =~ /^Wikipedia talk:/) {
+		        $param = $title =~ s/^Wikipedia talk://r;
+		        $text .= "\n* {{Lwt|$param}} &mdash; [$what $what]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    } else {
+		        $text .= "\n* {{La/x|$title}} &mdash; [$what $what]. [[User:$BOT|$SHORT]] reporting at ~~~~~\n";
+		    }
 		}
-		last if WPTryEdit($ttl, $token, $more, $text, "Adding possible violation on [[$title]]", undef);
-	    }
+		WPTryEdit($ttl, $token, $more, $text, "Adding possible violation on [[$title]]", undef);
 	    return undef
 	  }
     }
@@ -821,10 +834,10 @@
 		foreach $l (split "\n", WPArticle("User:$BOT/manual")) {
 		    push @manuals, $1  if $l =~ m/\[\[([^]]*)]]$/;
 		}
-		while($#manuals >= 0) {
+		if($#manuals >= 0) {
 		    my ($ttl, $token, $more, $text) = WPStartEdit("User:$BOT/manual");
 		    $text =~ s/==Unprocessed requests==.*==Recent Results==/==Unprocessed requests==\n\n==Recent Results==/s;
-		    last if WPTryEdit($ttl, $token, $more, $text, "Removing pending requests", 1);
+		    WPTryEdit($ttl, $token, $more, $text, "Removing pending requests", 1);
 		}
 	    }
 	    if($#manuals>=0) {
@@ -839,11 +852,9 @@
 		} else {
 		    ReportStatus('nomatch', "No match");
 		}
-		while(1) {
-		    my ($ttl, $token, $more, $text) = WPStartEdit("User:$BOT/results");
-		    $text .= $result;
-		    last if WPTryEdit($ttl, $token, $more, $text, "Posting result of manual check", 1);
-		}
+		my ($ttl, $token, $more, $text) = WPStartEdit("User:$BOT/results");
+		$text .= $result;
+		WPTryEdit($ttl, $token, $more, $text, "Posting result of manual check", 1);
 	    } else {
 		ReportStatus('unknown', "Idle");
 		sleep 20;