User:AnomieBOT/source/tasks/TemplateTalkRedirectCreator.pm: Difference between revisions

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: TemplateTalkRedirectCreator: * Use continuation in database query, so the bot doesn't wind up uselessly looping forever if more than 500 invalid pages pile up at the beginning of the list.
AnomieBOT (talk | contribs)
Updating published sources: TemplateTalkRedirectCreator: * Update summary to mention /styles.css subpages.
 
(10 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= ApprovalApproved requested2013-11-05<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 71]]}}
<syntaxhighlight lang="perl">
package tasks::TemplateTalkRedirectCreator;
Line 10:
Task: TemplateTalkRedirectCreator
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 71
Status: BRFAApproved 2013-11-05
Created: 2013-10-08
 
Create redirects for non-existing talk pages of certain pages:
* Template pages ending in "/doc", "/sandbox", "/testcases", "/TemplateData", or "/TemplateDatastyles.css"
* Module pages ending in "/doc", "/sandbox", or "/styles.css"
 
=end metadata
Line 26:
use AnomieBOT::Task;
use Data::Dumper;
use Time::HiRes;
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;
Line 35 ⟶ 36:
'%/testcases',
'%/TemplateData',
'%/styles.css',
],
'Module' => [
'%/doc',
'%/sandbox',
# Not %/testcases though, those talk pages are often (ab)used to run the tests.
'%/styles.css',
],
);
Line 43 ⟶ 48:
sub mapTitle {
my $title = shift;
return $1 if $title=~m!^(Template talk:.+)/(?:doc|sandbox|testcases|TemplateData|styles\.css)$!;
return $1 if $title=~m!^(Module talk:.+)/(?:doc|sandbox|styles\.css)$!;
return undef;
}
Line 58 ⟶ 63:
 
=for info
ApprovalApproved requested2013-11-05<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 71]]
 
=cut
 
sub approved {
return 03;
}
 
Line 80 ⟶ 85:
my $where = join( ' OR ', @where );
 
my ($dbh, $schema);
eval {
($dbh, $schema) = $api->connectToReplica( 'enwiki' );
};
if ( $@ ) {
Line 99 ⟶ 104:
# Load the list of redirects needing creation
my @rows;
my $t0 = Time::HiRes::time();
eval {
@rows = @{ $dbh->selectall_arrayref( qq{
Line 113 ⟶ 119:
return 300;
}
my $t1 = Time::HiRes::time();
$api->log( 'DB query took ' . ($t1-$t0) . ' seconds' );
last unless @rows;
 
my %redirects = ();
for my $row (@rows) {
utf8::decode( $row->{'title'} ); # Data from database is binary
my $title = $rns{$row->{'ns'}+1} . ':' . $row->{'title'};
$title =~ s/_/ /g;
Line 185 ⟶ 194:
}
 
my $txt = "#REDIRECT [[$target]]\n\n{{Redirect category shell|\n{{R from remote talk page}}\n}}";
my $summary="Redirecting to [[$target]] to avoid decentralized discussion";
 
Line 192 ⟶ 201:
my $r = $api->edit($tok, $txt, $summary, 0, 1);
if($r->{'code'} ne 'success'){
$api->warn("Write failed on $redir: ".$r->{'error'}."\n");
next;
}