#!/usr/bin/perl -w# Handle the recent list in TFAs#useEnglish;usestrict;useutf8;usewarnings;useCarp;useData::Dumper;useFile::Basenameqw(dirname);useFile::Spec;useMediaWiki::Bot;usePOSIX;binmode(STDERR,':utf8');binmode(STDOUT,':utf8');my$editor=MediaWiki::Bot->new({host=>'en.wikipedia.org',protocol=>'https',})ordie"new MediaWiki::Bot failed";my$dirname=dirname(__FILE__,'.pl');push@INC,$dirname;requireCred;my$cred=newCred();my$log=$cred->log;suberror_exit($){my@message=@ARG;if($editor->{error}->{code}){push@message,' (',$editor->{error}->{code},') : ',$editor->{error}->{details};}croak@message;}subdate($){my($day)=@ARG;my$date=strftime("%B %d, %Y",gmtime($day));$date=~s/ 0/ /;# Get rid of the spacereturn$date;}my%tfa;my$today=time();my$one_day=24*60*60;my$three_days_ago=$today-3*$one_day;$editor->login({username=>$cred->user,password=>$cred->password})orerror_exit('login failed');for(my$day=$today+60*$one_day;$day>$three_days_ago;$day-=$one_day){my$date=date($day);my$tfa="Wikipedia:Today's featured article/$date";my$text=$editor->get_text($tfa)ornext;my($article)=$text=~ /'''\[\[(.+)\]\]'''/;$tfa{$date}=$article;}for(my$day=$today+60*$one_day;$day>$today;$day-=$one_day){my$this_day=date($day);my$tfa="Wikipedia:Today's featured article/$date";my$text=$editor->get_text($tfa)orerror_exit("unable to fetch $tfa");my@matches=$text=~ /(\[\[\]\])/g;my$matches=scalar@matches;nextDAYunless$matches==3;formy$prev(1..3){my$prev_date=date($day-$prev*$one_day);my$prev_tfa=$tfa{$prev_date};nextDAYunlessdefined$prev_tfa;$text=~s/\[\[\]\]/[[$prev_tfa]]/;}$editor->edit({page=>$tfa,text=>$text,summary=>'update recently featured list',minor=>0,})orerror_exit("unable to edit '$tfa'");}exit0;