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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: TalkTemplateMover: * In trial. d::Trial: * New function, trial_complete, to help with notifying of trial completion.
AnomieBOT (talk | contribs)
Updating published sources: TalkTemplateMover: * Supplemental BRFA to handle additional templates (initially {{tl|interwiki copy}}) approved.
 
(16 intermediate revisions by the same user not shown)
Line 1:
{{ombox|type=notice|text= ApprovalApproved requested2009-07-09<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 31]]}}
{{ombox|type=notice|text= Supplemental BRFA approved 2024-02-04<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 82]]}}
<sourcesyntaxhighlight lang="perl">
package tasks::TalkTemplateMover;
 
Line 7 ⟶ 8:
=begin metadata
 
Bot: AnomieBOT
Task: TalkTemplateMover
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 31
Status: InApproved trial (30 edits)2009-07-09
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 82
Rate: Max 6 edits/minute
+Status: Approved 2024-02-04
Created: 2009-06-18
 
Find transclusions of {{tl|translated page}} mistakenlyand placedother ontemplates articledocumented for talk pages
mistakenly placed on article pages, and move them to the corresponding talk page.
 
=end metadata
Line 31 ⟶ 34:
my $did_redir=0;
my %templates=(
'Template:Translated page' => 1,
'Template:Interwiki copy' => 1,
);
 
Line 50 ⟶ 54:
 
=for info
ApprovalApproved requested2009-07-09<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 31]]
 
=for info
Supplemental BRFA approved 2024-02-04<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 82]]
 
=cut
 
sub approved {
return 13;
}
 
Line 63 ⟶ 70:
 
$api->task('TalkTemplateMover', 0, 10, qw/d::Talk d::Templates d::Redirects d::Trial/);
my $screwup=' Errors?If this bot is making errors, please report it at [[User:'.$api->user.'/shutoff/TalkTemplateMover]]';
 
if(!$did_redir){
my %r=$api->redirects_toredirects_to_resolved(keys %templates);
if(exists($r{''})){
$api->warn("Failed to get template redirects: ".$r{''}{'error'}."\n");
Line 73 ⟶ 80:
%templates=%r;
 
my %skip=$api->redirects_toredirects_to_resolved(@skip_templates);
if(exists($skip{''})){
$api->warn("Could not load list of redirects for skip templates: ".$skip{''}{'error'}."\n");
Line 82 ⟶ 89:
$did_redir=1;
}
my $trialct=$api->store->{'trial count'} // 0;
return $api->trial_complete('AnomieBOT 31') if $trialct>=30;
 
my $iter=$api->iterator(
Line 89 ⟶ 94:
geititle => [ keys %templates ],
geinamespace => 0,
geilimit => 'max1000',
prop => 'revisions',
rvprop => 'content',
rvlimitrvslots => 1'main',
);
while(my $_=$iter->next){
return 0 if $api->halting;
 
Line 103 ⟶ 108:
 
my $title=$_->{'title'};
my $intxt=$_->{'revisions'}[0]{'slots'}{'main'}{'*'};
my %tmpl=();
my @moved=();
my $outtxt=$api->process_templates($intxt, sub {
my $name=shift;
shift; #my $params=shift;
my $wikitext=shift;
shift; # $data
Line 114 ⟶ 119:
 
return undef unless exists($templates{"Template:$name"});
$tmpl{key($wikitextapi,$name,$params)}=1$wikitext;
push @moved, "{{$name}}";
return '';
Line 122 ⟶ 127:
$moved[-1]='and '.$moved[-1] if @moved>1;
my $moved=join((@moved>2)?', ':' ', @moved);
my $tl_moved=$moved; $tl_moved=~s/\{\{/{{tl|/g;
 
$api->log("Moving $moved from $title to Talk:$title");
Line 135 ⟶ 140:
$api->warn("Failed to get edit token for $title: ".$tok1->{'error'}."\n");
return 60;
} elsif($tok1->{'revisions'}[0]{'slots'}{'main'}{'*'} ne $intxt){
$api->log("Page changed while processing! Skip for now.");
next;
Line 154 ⟶ 159:
}
 
my $intalk=$tok2->{'revisions'}[0]{'slots'}{'main'}{'*'} // '';
my $outtalk=$api->process_templates($intalk, sub {
shift; #my $name=shift;
shift; #my $params=shift;
my $wikitext=shift;
shift; # $data
shift; # $oname
 
deletereturn $tmpl{$wikitext}undef ifunless exists($tmpltemplates{"Template:$wikitextname"});
my $k=key($api,$name,$params);
delete $tmpl{$k} if exists($tmpl{$k});
return undef;
});
$outtalk=$self->tag($api, $outtalk, join("\n", keysvalues %tmpl)) if %tmpl;
my $summary="Moving $moved from the[[:$title]] articleper pagethat template's documentation";
if(!defined($tok1)){
$outtalk=~s/\s+$//;
Line 186 ⟶ 193:
return 60;
}
} else {
$api->store->{'trial count'}=++$trialct;
return $api->trial_completelog('AnomieBOT"No 31')edit ifto Talk:$trialct>=30title necessary");
}
if(defined($tok1)){
my $res=$api->edit($tok1, $outtxt, "Moving $moved to talk[[Talk:$title]] per that template's documentation. $screwup", 0, 1);
if($res->{'code'} ne 'success'){
$api->warn("Write failed on $title: $res->{error}\n");
return 60;
}
$api->store->{'trial count'}=++$trialct;
return $api->trial_complete('AnomieBOT 31') if $trialct>=30;
}
}
 
return 3600;
}
 
sub key {
my $api=shift;
my $name=shift;
my $params=shift;
 
my $k=$templates{"Template:$name"};
foreach ($api->process_paramlist(@$params)){
$_->{'name'}=~s/^\s+|\s+$//g;
$_->{'value'}=~s/^\s+|\s+$//g;
$k.='|'.$_->{'name'}.'='.$_->{'value'};
}
return $k;
}
 
Line 225 ⟶ 244:
 
$wikitext=_unstrip_templates($wikitext,$data);
my $tagtmp ="\x02".sha256_base64( $wikitext)."\x03";
utf8::encode( $tmp ) if utf8::is_utf8( $tmp );
my $tag="\x02".sha256_base64($tmp)."\x03";
$tag=~tr!+/=!-_!d;
$data->{$tag}=$wikitext;
Line 235 ⟶ 256:
my $templ=shift;
 
$wikitext=~s!(\x02[a-zA-Z0-9_-]+\x03)! exists($templ->{$1})?$templ->{$1}: // $1 !gioe;
return $wikitext;
}
Line 241 ⟶ 262:
1;
 
</syntaxhighlight>
</source>