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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: CommonsFileTemplateFixer: * Approved for trial. * Needs a bunch of code to handle the conditions of the trial, though.
AnomieBOT (talk | contribs)
Updating published sources: CommonsFileTemplateFixer: * Handle the possibility of too many categories to query with the edit token. AnomieBOT::API: * Fix adding of the xxlimit parameter for stuff queried with the edit token. Apparently this was broken since 2017, sigh.
 
(2 intermediate revisions by the same user not shown)
Line 201:
keys %goodcopycats,
);
my $qcatlimit = $api->paramLimit( 'query+categories', 'categories' );
 
if ( ! $self->{'iter'} ) {
$api->log( "Beginning " . ( $docopybotuntil ? 'bot-copy' : 'main' ) . " run" );
$self->{'broken'} = 0;
$self->{'iter'} = $api->iterator(
Line 213 ⟶ 215:
cllimit => 'max',
);
} else {
$api->log( "Continuing " . ( $docopybotuntil ? 'bot-copy' : 'main' ) . " run" );
}
 
Line 238 ⟶ 242:
next if ( $self->{'iter'}->iterval eq $r{'Template:Copy to Wikimedia Commons'} && ( $api->store->{"copyCheckTs:$title"} // 0 ) ge $copyCheckTs );
 
my $tok=$api->edittoken( $title, EditRedir => 1, imageinfoduplicatefiles => {1, propcategories => 'sha1'( },@qcats categories => $qcatlimit ? 1 : { categories => join( '|', @qcats ) } ) );
if ( $tok->{'code'} eq 'shutoff' ) {
$api->warn( "Task disabled: " . $tok->{'content'} . "\n" );
Line 368 ⟶ 372:
} elsif ( $tpl eq $r{'Template:Copy to Wikimedia Commons'} ) {
# Already on Commons?
my @dups = map { my $sha1x = 'File:' . $tok_->{'imageinfoname'}[0]; $x =~ s/_/ /g; $x; } grep { exists( $_->{'sha1shared'} //) } @{ $tok->{'duplicatefiles'} // [] };
if ( $sha1 ne ''@dups ) {
my@dups = ( $title ) if ( grep { $_ eq $title } @dups ); # Prefer matching title.
if ( defined( $cachetrialtasks{'dups'}{$sha11} )= ) {1;
 
@dups = @{ $cache{'dups'}{$sha1} };
}if else( $isKeepLocal ) {
my $resd = $capi->query(dups[0];
list $trialtasks{15} => 'allimages',1;
push @summary, "remove {{Copy aisha1to Wikimedia Commons}}, on Commons as => [[c:$sha1,d]] but tagged {{Keep local}} here";
ailimit =>return 'max',;
formatversion => 2,
);
if ( $res->{'code'} ne 'success' ) {
$api->warn( "Failed to fetch duplicates for $title (sha $sha1): " . $res->{'error'} . "\n" );
$fail = 1;
return undef;
}
@dups = map { $_->{'title'} } @{ $res->{'query'}{'allimages'} };
$cache{'dups'}{$sha1} = \@dups;
}
if ( @dups ) {
@dups = ( $title ) if ( grep { $_ eq $title } @dups ); # Prefer matching title.
$trialtasks{1} = 1;
 
push @summary, "removereplace {{Copy to Wikimedia Commons}} with {{Now Commons}}, on Commons as " . join( " ", map { "[[c:$d_]]" but tagged {{Keep local}} here"@dups );
if ( $isKeepLocal ) {
my $dsidx = $dups[0]#summary;
my $trialtasks{15}@ret = 1();
ifforeach (my $d (@dups ) {
push @summary, "remove {{Copy to Wikimedia Commons}}, on Commons as [[c:$d]] but tagged {{Keep local}} here";
$summary[$sidx] .= ' (and return 'dedupe)' if $sidx >= 0 && $hasNowCommons{$d} // 0;
$sidx = -1 if $hasNowCommons{$d} // 0;
next if ( $isKeepLocalhasNowCommons{$d} )// {0; # Dedupe
$cache{'dups'}hasNowCommons{$sha1d} = \@dups1;
 
push# @summary,Check "replaceif {{Copyit's toalready Wikimediaup Commons}}for with {{Now Commons}},deletion on Commons as " . join( " ", map { "[[c:$_]]" } @dups );
my $sidx = $#summarycfile;
myif @ret =( defined( $cache{'info'}{$d} ); ) {
foreach my $dcfile (@dups)= $cache{'info'}{$d};
} else $summary[$sidx] .= ' (and dedupe)' if $sidx >= 0 && $hasNowCommons{$d} // 0;
$sidxcfile = $self-1>get_commons_file_info( if$capi, $hasNowCommons{$d} // 0);
next if $hasNowCommons{$d}( //! 0;$cfile #) Dedupe{
$hasNowCommons{$d}fail = 1;
return undef;
 
# Check if it's already up for deletion on Commons.
my $cfile;
if ( defined( $cache{'info'}{$d} ) ) {
$cfile = $cache{'info'}{$d};
} else {
$cfile = $self->get_commons_file_info( $capi, $d );
if ( ! $cfile ) {
$fail = 1;
return undef;
}
$cache{'info'}{$d} = $cfile;
}
if ( @{ $cfile->{'templates'} // [] } ) {
my $t = $cfile->{'title'};
$trialtasks{7} = 1;
push @summary, "replace {{Now Commons}} with {{Nominated for deletion on Commons}} as [[c:$t]] is nominated for deletion";
$summary[$#summary] .= ' (and dedupe)' if $hasDelNomOnCommons{$t} // 0;
next if $hasDelNomOnCommons{$t} // 0; # Dedupe
$hasDelNomOnCommons{$t} = 1;
$t =~ s/^File://;
$t = "1=$t" if $t =~ /=/;
push @ret, "{{Nominated for deletion on Commons|$t}}";
} else {
$d = "1=$d" if $d =~ /=/;
push @ret, "{{Now Commons|$d|date=" . strftime( '%-d %B %Y', gmtime ) . "|bot=" . $api->user . "}}";
}
@dups = @{ $cache{'dupsinfo'}{$sha1d} }= $cfile;
);}
if ( @{ $rescfile->{'codetemplates'} ne// 'success'[] } ) {
@dups = map { my $_->{'title'}t } @{= $rescfile->{'querytitle'}{'allimages'} };
formatversion$trialtasks{7} => 2,1;
push @summary, "replace {{Now Commons}} with {{Nominated for deletion on Commons}} as [[c:$t]] is nominated for deletion";
$summary[$#summary] .= ' (and dedupe)' if $hasDelNomOnCommons{$t} // 0;
next $cfile =if $cache{'info'}hasDelNomOnCommons{$dt} // 0; # Dedupe
$trialtaskshasDelNomOnCommons{1$t} = 1;
$failt =~ 1s/^File://;
my$t = "1=$cfilet" if $t =~ /=/;
#push Check@ret, if it's already up"{{Nominated for deletion on Commons.|$t}}";
} else {
if$d ( defined(= $cache{'info'}{"1=$d}" )if $d )=~ {/=/;
push @ret, "{{Now Commons|$d|date=" . strftime( '%-d %B %Y', gmtime ) . "|bot=" . $api->user . "}}";
}
return join( "\n", @ret );
}
return join( "\n", @ret } else {);
}
 
Line 533 ⟶ 517:
}
 
$api->log( "Finished " . ( $docopybotuntil ? 'bot-copy' : 'main' ) . " run" );
$self->{'iter'} = undef;