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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: EnDashRedirectCreator: * Don't try to create TemplateStyles redirects, it won't work anyway.
AnomieBOT (talk | contribs)
Updating published sources: EnDashRedirectCreator: * Rework code to make it easy to add more dashes/hyphens to create redirects for.
Line 59:
14 => 1, # Category, not eligible for CSD:R2
100 => 1, # Portal, not eligible for CSD:R2
);
 
my %dashes = (
'–' => 'en-dashes',
);
 
Line 99 ⟶ 103:
my $cont = $self->{'dbcontinue'} // '';
my $skipNs = join( ',', @skipNs );
my $dashstr = join( '', keys %dashes );
my $dashcond = join( ' OR ', map { "p1.page_title LIKE '%$_%'" } keys %dashes );
 
# Spend a max of 5 minutes on this task before restarting
my $endtime=time()+300;
 
$dbh->do( q{SET NAMES 'utf8'} );
 
while ( 1 ) {
Line 110 ⟶ 118:
eval {
@rows = @{ $dbh->selectall_arrayref( qq{
SET STATEMENT max_statement_time=300 FOR
SELECT p1.page_namespace AS ns, p1.page_title AS title
FROM page as p1
LEFT JOIN page AS p2 ON ( p1.page_namespace = p2.page_namespace AND REPLACEREGEXP_REPLACE( CONVERT(p1.page_title USING utf8), '[$dashstr]', '-' ) = p2.page_title )
WHERE p1.page_title LIKE '%–%'($dashcond) AND p2.page_id IS NULL AND p1.page_namespace NOT IN ($skipNs) $cont
ORDER BY p1.page_namespace, p1.page_title
LIMIT 50
Line 135 ⟶ 144:
$to =~ s/_/ /g;
my $from = $to;
$from =~ s/[$dashstr]/-/g;
$redirects{$from} = [ $to, $to, undef ];
}
Line 238 ⟶ 247:
my $tosection = defined( $fragment ) ? '{{R to section}}' : '';
my $txt = "#REDIRECT [[:$target]]\n{{Redirect shell|{{R from modification|1={{-r|$origtarget}}}}$tosection}}\n{{User:AnomieBOT/Auto-G8|target=$origtarget}}";
my $summary@what ="Redirecting to [[:$origtarget]] because titles with en-dashes are hard to type"();
while ( my ($char, $what) = each %dashes ) {
push @what, $what if $origtarget =~ /$char/;
}
$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;