Content deleted Content added
Updating published sources: SafesubstFixer: * New task, BRFA filed. |
Updating published sources: General: * Update for the addition of 'rvslots'. DatedCategoryDeleterTest: * Disable. It's clear that task won't be needed. BrokenRedirectDeleter: * Handle pages with newlines before the <code>#REDIRECT</code>. |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1:
{{ombox|type=notice|text= BRFA
<
package tasks::SafesubstFixer;
Line 7:
=begin metadata
Bot: AnomieBOT
Task: SafesubstFixer
BRFA: Wikipedia:Bots/Requests for approval/AnomieBOT 37
Status:
Created: 2010-04-20
OnDemand: true
Replace <code><nowiki>{{{subst|}}}</nowiki></code> in specifically named templates with <code><nowiki><includeonly>safesubst:</includeonly></nowiki></code>. If appropriate, may also insert <code><nowiki><includeonly>safesubst:</includeonly></nowiki></code> into <code><nowiki>{{#if</nowiki></code> and other parser functions, or specifically named template invocations.
Line 36 ⟶ 37:
=for info
BRFA
=cut
sub approved {
return
}
Line 55 ⟶ 56:
# Replacements
my @re=(
qr/\{\{\{subst\|\}\}\}/, '<includeonly>safesubst:</includeonly>',
qr/\{\{#if/, '{{<includeonly>safesubst:</includeonly>#if',
qr/\{\{#switch/, '{{<includeonly>safesubst:</includeonly>#switch',
);
my $summary="Replacing {{{subst|}}} with <includeonly>safesubst:</includeonly> (and inserting it into parser function calls) per [[Wikipedia talk:Template messages/User talk namespace#safesubst:|request]]";
Line 99 ⟶ 100:
# Get page text
my $intxt=$tok->{'revisions'}[0]{'slots'}{'main'}{'*'};
# Perform the replacements
Line 108 ⟶ 109:
$outtxt=~s/$search/$repl/g;
}
$outtxt=~s!<includeonly>(.*?)</includeonly>! fix_nested_noinclude($1) !ge;
$outtxt=$api->replace_nowiki($outtxt, $nowiki);
Line 127 ⟶ 129:
# No more pages to check
return undef;
}
sub fix_nested_noinclude {
my $x=shift;
return $x=~/(.*)<includeonly>safesubst:/ ? "<includeonly>${1}safesubst:</includeonly><includeonly>" : "<includeonly>$x</includeonly>";
}
1;
</syntaxhighlight>
|