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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: PERTableUpdater: * On CAT:ESP, mark MediaWiki, user script, and most Title Blacklist entries as red instead of yellow.
AnomieBOT (talk | contribs)
Updating published sources: PERTableUpdater: * Create User:AnomieBOT/EDITREQTable for Category:Requested edits.
Line 13:
Created: 2011-12-01
 
Update [[User:AnomieBOT/PERTable]], [[User:AnomieBOT/SPERTable]], and [[User:AnomieBOT/SPERTableEDITREQTable]].
 
=end metadata
Line 68:
 
my $screwup=' Errors? [[User:'.$api->user.'/shutoff/PERTableUpdater]]';
 
# Upgrade
if(exists($api->store->{"pages0"})){
$api->store->{"PER pages"}=$api->store->{"pages0"};
delete $api->store->{"pages0"};
}
if(exists($api->store->{"pages1"})){
$api->store->{"SPER pages"}=$api->store->{"pages1"};
delete $api->store->{"pages1"};
}
 
# First, load MediaWiki:Titleblacklist to catch pages protected by
Line 108 ⟶ 118:
}
 
my @data=(
[10,'PER','Wikipedia protected edit requests','protected','editprotected',[qw/red red clear yellow/]],
[10,'SPER','Wikipedia semi-protected edit requests','semi-protected','editsemiprotected',[qw/red clear red red/]],
[ 0,'EDITREQ','Requested edits','COI','requestedit',[qw/clear yellow red red/]],
);
my $starttime=time;
for my $sperdata (0,1@data){
my ($greenns,$tag,$cat,$type,$tgt,$colors)=@$data;
my $iter=$api->iterator(
generator => 'categorymembers',
gcmtitle => $sper?'"Category:Wikipedia semi-protected edit requests':'Category:Wikipedia protected edit requests'$cat",
gcmlimit => 'max',
prop => 'info',
);
my %oldpages=%{$api->store->{'pages'."$spertag pages"}//{}};
my %pages=();
while(my $p=$iter->next){
if(!$p->{'_ok_'}){
$api->warn("Failed to retrieve members for ".($sper?'CAT:SEP':'CAT:EP')."$tag: ".$p->{'error'}."\n");
return 60;
}
Line 141 ⟶ 157:
delete $pages{$t}{'logtitle'};
}
$api->store->{'pages'."$spertag pages"}=\%pages;
 
if(%pages){
Line 151 ⟶ 167:
while(my $p=$iter->next){
if(!$p->{'_ok_'}){
$api->warn("Failed to retrieve members for ".($sper?'CAT:SEP':'CAT:EP')."$tag: ".$p->{'error'}."\n");
return 60;
}
Line 166 ⟶ 182:
# Highest score by int value "wins".
my $protscore=-1;
$pd->{'color'}='red';
$pd->{'prottype'}='Not protected';
$pd->{'reason'}='';
if($p->{'ns'}==8){
$pd->{'color'}='yellow' unless $sper;
$pd->{'prottype'}='MediaWiki page';
$protscore=8;
} elsif($p->{'ns'}==2 && $t=~m!/.*\.js$!){
$pd->{'color'}='yellow' unless $sper;
$pd->{'prottype'}='User JS page';
$protscore=2;
} elsif($p->{'ns'}==2 && $t=~m!/.*\.css$!){
$pd->{'color'}='yellow' unless $sper;
$pd->{'prottype'}='User CSS page';
$protscore=2;
Line 186 ⟶ 198:
my $sc=exists($data->{'opts'}{'autoconfirmed'})?0:4;
next if $sc<$protscore;
$pd->{'color'}='yellow' unless(exists($data->{'opts'}{'autoconfirmed'}) != $sper);
$pd->{'prottype'}=$data->{'source'};
my $line=$data->{'line'};
Line 201 ⟶ 212:
$sc|=1 unless exists($pp->{'source'});
next if $sc<$protscore;
$pd->{'color'}=($p->{'ns'}==10?'green':'clear') if($pp->{'level'} eq ($sper?'autoconfirmed':'sysop'));
if(exists($pp->{'source'})){
$pg=$pp->{'source'};
Line 214 ⟶ 224:
$pd->{'reason'}='';
}
 
$pd->{'color'}='red'$colors->[0];
if($protscore>=0){
$pd->{'color'}='yellow' unless $spercolors->[1];
$pd->{'color'}='yellow' unless$colors->[3] if($sperprotscore & 2);
$pd->{'color'}='yellow' unless$colors->[2] if($sperprotscore & 4);
$pd->{'color'}=$colors->[3] if($protscore & 8);
}
$pd->{'color'}='green' if($ppd->{'nscolor'}==10?'green': eq 'clear') if(&& $ppp->{'levelns'} eq (==$sper?'autoconfirmed':'sysop')greenns);
 
if($pd->{'reason'} eq ''){
Line 255 ⟶ 274:
my $ct=scalar keys %pages;
my $s=($ct==1?'':'s');
my $typepg=($sper?'semi-protected'User:AnomieBOT/'.$tag.'protectedTable');
$txt.=qq(! $ct [[:Category:Wikipedia $type edit requestscat|$type edit request$s]] <div style="float:right;white-space:nowrap">[[$pg|v]]&middot;<span class="plainlinks">[//en.wikipedia.org/w/index.php?title=$pg&action=history h]</span></div>\n);
my $pg='User:AnomieBOT/'.($sper?'SPERTable':'PERTable');
$txt.=qq(! $ct [[:Category:Wikipedia $type edit requests|$type edit request$s]] <div style="float:right;white-space:nowrap">[[$pg|v]]&middot;<span class="plainlinks">[//en.wikipedia.org/w/index.php?title=$pg&action=history h]</span></div>\n);
$txt.=qq(|-\n);
$txt.=qq(|\n);
Line 265 ⟶ 283:
$txt.=qq(! Protection level\n);
$txt.=qq(! class = "unsortable" | Last protection log entry\n);
my $tgt=$sper?'editsemiprotected':'editprotected';
for my $p (sort { $a->{'touched'} <=> $b->{'touched'} } values %pages){
my $c=$colors{$p->{'color'}};
Line 298 ⟶ 315:
$intxt=~s#<!--TS-->.*<!--/TS-->#<!--TS-->~~~~~<!--/TS-->#g;
if($intxt ne $txt){
$api->log("UpadtingUpdating $pg ($ct request$s)");
my $r=$api->edit($tok, $txt, "Update table ($ct request$s)", 0, 0);
if($r->{'code'} ne 'success'){