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

Content deleted Content added
AnomieBOT (talk | contribs)
Updating published sources: TaskRedirectChecker: * New task, no BRFA required as it only affects the bot's own userspace.
 
AnomieBOT (talk | contribs)
Updating published sources: TaskRedirectChecker: * Canonicalize redirect titles
Line 76:
next unless $txt=~/$re\[\[([^]#]+)#([^]]+)\]\]/;
my ($title,$anchor)=($1,$2);
 
# Ask MediaWiki to canonicalize the title for us, because the actual
# normalization can depend on various factors.
my $res=$api->query(titles=>$title);
if($res->{'code'} ne 'success'){
$api->warn("Failed to get canonical name for $title: ".$res->{'error'}."\n");
return 60;
}
$title=$res->{'query'}{'normalized'}[0]{'to'} // $title;
 
# Add a "dummy" section for the anchor we're actually looking for,
# because the encoded anchors returned in "sections" varies based on
# server settings. Note this doesn't support {{anchor}} or the like.
my $res=$api->query(action=>'parse',title=>$title,text=>"__TOC__\n== XXX $anchor ==\n\n{{:$title}}",prop=>'sections');
if($res->{'code'} ne 'success'){
$api->warn("Failed to retrieve section list for $title: ".$res->{'error'});