User:AnomieBOT/source/tasks/ITNCArchiver.pm

marker in ".$tok->{'title'}.", so I don't know where to insert the archive. Please replace it. Thanks!");           $b0rken=1;            next;        }

$api->log("$summary to ".$tok->{'title'}); my $r=$api->edit($tok, $txt, "$summary. $screwup", 0, 1); if($r->{'code'} ne 'success'){ $api->warn("Write failed on $tok->{title}: ".$r->{'error'}."\n"); $b0rken=1; next; }

# Archival succeeded, so remove the sections-to-archive from the store delete $a->{$k}; $api->store->{'archive'}=$a; }

# Now, we need to update the archive listing {       $tok=$api->edittoken("Wikipedia:In the news/Candidates/Archives"); if($tok->{'code'} eq 'shutoff'){ $api->warn("Task disabled: ".$tok->{'content'}."\n"); return 300; }       if($tok->{'code'} ne 'success'){ $api->warn("Failed to get edit token for Wikipedia:In the news/Candidates/Archives: ".$tok->{'error'}."\n"); $b0rken=1; last; }

my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'} // ''; $intxt=~s/^\s+|\s+$//g;

unless($intxt=~/.*/s){ $api->warn("Failed to find link markers in Wikipedia:In the news/Candidates/Archives\n"); $api->whine("Cannot update In the news/Candidates/Archives", "I could not find the  and   markers in In the news/Candidates/Archives, so I don't know where to insert the links. Please replace them. Thanks!"); $b0rken=1; last; }

my %links=; my $re='^Wikipedia:In the news/Candidates/(('.join('|',@months[1..12]).')(?:–(?:'.join('|',@months[1..12]).'))?\s+(\d+))$'; $re=qr/$re/; my $i=$api->iterator(           list        => 'allpages',            apnamespace => 4,            apprefix    => 'In the news/Candidates/',            aplimit     => 'max'        ); while($_=$i->next){ if(!$_->{'_ok_'}){ $api->warn("Could not retrieve pages from iterator: ".$_->{'error'}."\n"); return 60; }           $_=$_->{'title'}; next unless /$re/; my ($x,$m,$y)=($1,$2,$3); for(my $i=1; $i<@months; $i++){ $m=$i if $m eq $months[$i]; }           $links{sprintf("%04d-%02d", $y, $m)}=(($m==1)?"\n":"")."$x"; }       my @links=; for my $k (sort keys %links){ push @links, $links{$k}; }       my $links=join(" &bull; ", @links); $links=~s/^\s+|\s+$//g; $links="\n$links"; my $outtxt=$intxt; $outtxt=~s/.*/\n$links\n/s;

if($intxt ne $outtxt){ $api->log("Updating ".$tok->{'title'}); my $r=$api->edit($tok, $outtxt, "Updating archive page list. $screwup", 0, 1); if($r->{'code'} ne 'success'){ $api->warn("Write failed on $tok->{title}: ".$r->{'error'}."\n"); $b0rken=1; }       }    }

# Retry if broken, otherwise go again tomorrow my $t=86400-(time%86400); $t=300 if($b0rken && $t>300); return $t; }

1;