Content deleted Content added
Updating published sources: EnDashRedirectCreator: * Apply {{tl|R avoided double redirect}} when appropriate. |
Updating published sources: EnDashRedirectCreator: * Supplemental BRFA to update old redirects as needed. |
||
Line 1:
{{ombox|type=notice|text= Approved 2016-03-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 74]]}}
{{ombox|type=notice|text= Supplemental BFRA approval requested 2020-06-11<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 80]]}}
<syntaxhighlight lang="perl">
package tasks::EnDashRedirectCreator;
Line 11 ⟶ 12:
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 74
Status: Approved 2016-03-08
+BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 80
+Status: BRFA
Created: 2016-03-03
Line 28 ⟶ 31:
use vars qw/@ISA/;
@ISA=qw/AnomieBOT::Task/;
my $brfa80 = 0;
my @skipNs = (
Line 77 ⟶ 82:
=for info
Approved 2016-03-08<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 74]]
=for info
Supplemental BFRA approval requested 2020-06-11<br />[[Wikipedia:Bots/Requests for approval/AnomieBOT 80]]
=cut
Line 111 ⟶ 119:
$dbh->do( q{SET NAMES 'utf8'} );
my $actorIds;
eval {
$actorIds = join( ',', @{ $dbh->selectcol_arrayref( "SELECT actor_id FROM actor_user WHERE actor_name = 'AnomieBOT'" ) } );
};
if ( $@ ) {
$api->warn( "Error fetching actor ID from replica: $@\n" );
return 300;
}
while ( 1 ) {
Line 124 ⟶ 141:
FROM page as p1
LEFT JOIN page AS p2 ON ( p1.page_namespace = p2.page_namespace AND REGEXP_REPLACE( CONVERT(p1.page_title USING utf8), '[$dashstr]', '-' ) = p2.page_title )
LEFT JOIN redirect AS r2 ON(r2.rd_from=p2.page_id)
WHERE
($dashcond) AND p1.page_namespace NOT IN ($skipNs)
AND (
p2.page_id IS NULL
} . ( $brfa80 ? qq{
OR (
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
) AND EXISTS( SELECT 1 FROM revision WHERE rev_page = p2.page_id AND rev_actor IN ($actorIds) AND rev_parent_id = 0 )
} : "" ) . qq{
)
$cont
ORDER BY p1.page_namespace, p1.page_title
LIMIT 50
Line 149 ⟶ 180:
my $from = $to;
$from =~ s/[$dashstr]/-/g;
$redirects{$
}
Line 155 ⟶ 186:
# Bypass double redirects and remove missing target pages
my $res = $api->query(
titles => join('|',
redirects => 1
);
Line 175 ⟶ 206:
}
}
while( my ($
my ($redir, $origtarget, $target, $fragment) = @$targets;
my %seen=( $target => 1 );
while ( exists( $map{$target} ) ) {
$fragment = $map{$target}[1] // $fragment;
$target = $map{$target}[0];
$redirects{$
if ( exists( $seen{$target} ) ) {
$api->warn("Redirect loop involving [[$target]]");
delete $redirects{$
last;
}
$seen{$target}=1;
}
delete $redirects{$
}
# Now, create the redirects
while( my ($
return 0 if $api->halting;
my ($redir, $origtarget, $target, $fragment) = @$targets;
my $tok=$api->edittoken($redir, EditRedir => 1, imageinfo => { prop => '', limit => 1 });
Line 208 ⟶ 239:
}
if ( !exists( $tok->{'missing'} ) ) {
if ( !$brfa80 ) {
$api->log("$redir already exists, skipping"); next;
}
my $res = $api->query(
titles => $redir,
prop => 'revisions',
rvprop => 'user',
rvdir => 'newer',
rvlimit => 1,
formatversion => 2,
);
my $user = $res->{'query'}{'pages'}[0]{'revisions'}[0]{'user'} // '';
if ( $user ne 'AnomieBOT' ) {
$api->log("$redir already exists and wasn't originally created by the bot, skipping");
next;
}
my $txt = $tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
if ( $txt =~ m!\{\{User:AnomieBOT/Auto-G8\|target=(.*?)\}\}! && $1 ne $origtarget ) {
$api->warn("[[$redir]] apparently exists for both [[$1]] and [[$origtarget]], not updating");
next;
}
}
if ( exists( $tok->{'imagerepository'} ) && $tok->{'imagerepository'} ne '' ) {
Line 252 ⟶ 304:
my $double = $origtarget eq $target ? '' : "{{R avoided double redirect|1=$origtarget}}";
my $txt = "#REDIRECT [[:$target]]\n{{Redirect shell|{{R from modification|1={{-r|$origtarget}}}}$double$tosection}}\n{{User:AnomieBOT/Auto-G8|target=$origtarget}}";
my
while ( my ($char, $what) = each %dashes ) {
}
my $what = join( @what > 2 ? ", " : " ", @what );
} else {
$summary = "Updating redirect to [[:$origtarget]]";
}
▲ $what[$#what] = 'and ' . $what[$#what] if @what > 1;
▲ my $what = join( @what > 2 ? ", " : " ", @what );
▲ my $summary="Redirecting to [[:$origtarget]] because titles with $what are hard to type";
$summary.=" (and resolving the double redirect to [[:$target]])" if $origtarget ne $target;
# Create/update page
$api->log("$summary in $redir");
my $r = $api->edit($tok, $txt, "$summary. $screwup", 0, 1);
|