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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: EnDashRedirectCreator: * Don't try to update non-redirects. * When updating redirects, preserve various templates. * When updating redirects, preserve manually added categories. * Update the disabled code for someday adding missing {{tlu|User:AnomieBOT/Auto-G8}} transclusions to prioritize new creations over those fixes.
AnomieBOT (talk | contribs)
Updating published sources: EnDashRedirectCreator: * Add disabled code for finding redirects missing {{tl|R avoided double redirect}}. * Reorganize queries. * Supplemental BRFA for all this disabled code.
 
(One intermediate revision by the same user not shown)
Line 1:
{{ombox|type=notice|text= Approved 2016-03-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 74]]}}
{{ombox|type=notice|text= Supplemental BFRA approved 2020-06-19<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 80]]}}
{{ombox|type=notice|text= Supplemental BFRA approval requested 2025-08-23<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 86]]}}
<syntaxhighlight lang="perl">
package tasks::EnDashRedirectCreator;
Line 14 ⟶ 15:
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 80
+Status: Approved 2020-06-19
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 86
+Status: BRFA
Created: 2016-03-03
 
Line 75 ⟶ 78:
=for info
Supplemental BFRA approved 2020-06-19<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 80]]
 
=for info
Supplemental BFRA approval requested 2025-08-23<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 86]]
 
=cut
Line 87 ⟶ 93:
$api->task('EnDashRedirectCreator', 0, 10, qw/d::Redirects d::IWNS d::Talk d::Timestamp d::Templates/);
my $screwup=' Errors? [[User:'.$api->user.'/shutoff/EnDashRedirectCreator]]';
 
my $BRFA86 = 0;
 
my %ns = $api->namespace_map();
Line 175 ⟶ 183:
}
 
my $targetid;
# TODO: Make a BRFA to enable this.
eval {
( $targetid ) = $dbh->selectrow_array( "SELECT lt_id FROM linktarget WHERE lt_namespace=2 AND lt_title = 'AnomieBOT/Auto-G8'" );
};
if ( $@ ) {
$api->warn( "Error fetching linktarget ID from replica: $@\n" );
return 300;
}
 
my $autoG8Mismatch = '0=1';
my $needAvoidedRedir = '0=1';
my $needAutoG8 = '0=1';
if ( 0$BRFA86 && $dofixupuntil ) {
$autoG8Mismatch = "EXISTS( SELECT 1 FROM externallinks WHERE el_from = p2.page_id AND el_to_domain_index = 'urn:.' and el_to_path = 'x-anomiebot-auto-g8-mismatch:endash' )";
my $targetid;
$needAutoG8 = "templatelinks.tl_from IS NULL";
eval {
$needAvoidedRedir = "r1.rd_from IS (NOT $targetidNULL )AND =NOT $dbh->selectrow_arrayEXISTS( "SELECT lt_id1 FROM linktargetcategorylinks WHERE lt_namespacecl_from=2p2.page_id AND lt_title cl_to= 'AnomieBOT/Auto-G8Avoided_double_redirects'" )";
};
 
if ( $@ ) {
my $botOwned = "revision.rev_page IS NOT NULL";
$api->warn( "Error fetching linktarget ID from replica: $@\n" );
if ( $BRFA86 ) return 300;{
$botOwned = "( $botOwned OR templatelinks.tl_from IS NOT NULL )";
}
$needAutoG8 = "NOT EXISTS( SELECT 1 FROM templatelinks WHERE tl_from=p2.page_id AND tl_target_id=$targetid )";
}
 
Line 203 ⟶ 220:
LEFT JOIN redirect AS r1 ON(r1.rd_from=p1.page_id)
LEFT JOIN redirect AS r2 ON(r2.rd_from=p2.page_id)
LEFT JOIN revision ON (rev_page = p2.page_id AND rev_actor IN ($actorIds) AND rev_parent_id = 0)
$needAutoG8 = "NOT EXISTS( SELECT 1 FROM LEFT JOIN templatelinks WHEREON (tl_from=p2.page_id AND tl_target_id=$targetid )";
WHERE
($dashcond) AND p1.page_namespace NOT IN ($skipNs)
AND (
p2.page_id IS NULL
OR $botOwned AND (
r2.rd_namespace != COALESCE( r1.rd_namespace, p1.page_namespace )
OR r2.rd_title != COALESCE( r1.rd_title, p1.page_title )
OR r2.rd_fragment != r1.rd_fragment
OR $autoG8Mismatch
OR $needAutoG8
) AND EXISTS( SELECT 1OR FROM revision WHERE rev_page = p2.page_id AND rev_actor IN ($actorIds) AND rev_parent_id = 0 )needAvoidedRedir
)
)
$cont
Line 324 ⟶ 345:
 
my $txt = $tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
if ( $txt =~ m!\{\{User:AnomieBOT/Auto-G8\|(?:[^{}|]*\|)?target=(.*?)\}\}! && $1 ne $origtarget ) {
my $oldtarget = $1;
my $tmp = $oldtarget;
Line 426 ⟶ 447:
$rextra = "\n{{R from ASCII-only}}$rextra" if $redir =~ /^[ -~]+$/;
$rextra = "\n{{R avoided double redirect|1=$origtarget}}$rextra" if $origtarget ne $target;
my $txt = "#REDIRECT [[:$target]]\n\n${extrabefore}{{Redirect category shell|\n{{R from alternative hyphenation|1={{-r|1=$origtarget}}}}$rextra\n}}\n{{User:AnomieBOT/Auto-G8|endash|target=$origtarget}}$extra";
my $summary;
if ( exists( $tok->{'missing'} ) ) {