Template:Bots/doc
This is a documentation subpage for Template:Bots. It may contain usage information, categories and other content that is not part of the original template page. |
These templates tell bots and automated editing tools/scripts that they should or should not edit that page. The templates can be used to block most bots (all bots that have implemented this functionality) or specific bots by name or function. For example, this can be used to opt-in or opt-out from user talk bot messages or to cause maintenance bots to avoid certain pages. These templates should be used carefully outside userspace to avoid blocking useful bot edits.
Explicitly opting-in has the advantage of possibly receiving useful changes or targeted posts that might otherwise be skipped by the bot assuming a default "opt-out" behavior. Users should be aware that by opting-out of bot posts, they will not be notified of matters relating to material they have edited or uploaded, which are tagged or scanned by bots per policy.
In particular, in the encyclopedia spaces:
- Avoid using the template as a blunt instrument
- Address the root problem with the bot owner or bot community
- Remove the template tag once the underlying problem has been resolved.
Syntax:
change{{nobots}} Ban all compliant bots (shortcut) {{bots}} Allow all bots (shortcut)
{{bots|allow=<botlist>}} Ban all compliant bots not in the list {{bots|deny=<botlist>}} Ban all compliant bots in the list
Where <botlist> is a comma-delimited string of bot usernames (AWB can be used for all AWB-based bots): {{bots|allow=HagermanBot,Werdnabot}} {{bots|deny=AWB}}
<botlist> can also be "none" or "all" as in the following examples: {{bots|allow=all}} Allow all bots {{bots|allow=none}} Ban all compliant bots
{{bots|deny=all}} Ban all compliant bots {{bots|deny=none}} Allow all bots
Bots are not bound to observe the nobots tag; it will depend on their functionality, their owners and their terms of approval. The bots that currently support exclusion are listed at exclusion compliant bots.
Incorrect Syntax
changeThis syntax looks correct, but depending on the individual bot may not have the intended effect. This statement may deny neither Bot1 nor Bot2, only one of the two bots, or both bots as intended.
{{bots|deny=Bot1|deny=Bot2}} INCORRECT
Instead, write:
{{bots|deny=Bot1,Bot2}} CORRECT
Implementation
change- Pywikipediabot supports bots and nobots since r4096. The templates may be ignored using a parameter.
- Since version 3.2.0.0 AutoWikiBrowser fully supports {{bots}} and {{nobots}}. Additionally, pseudo-username AWB can be specified to ban all AWB-based bots from the page. However, AWB has an option to ignore these templates.
- Opt out message notification was introduced here April 3, 2008. Individual bot/script implementation will vary and notice above of implementation may not include this feature.
Example implementations
changePHP
changefunction allowBots( $text ) {
global $user;
if (preg_match('/\{\{(nobots|bots\|allow=none|bots\|deny=all|bots\|optout=all|bots\|deny=.*?'.preg_quote($user,'/').'.*?)\}\}/iS',$text))
return false;
if (preg_match('/\{\{(bots\|allow=all|bots\|allow=.*?'.preg_quote($user,'/').'.*?)\}\}/iS', $text))
return true;
if (preg_match('/\{\{(bots\|allow=.*?)\}\}/iS', $text))
return false;
return true;
}
Perl
changesub allowBots {
my($text, $user, $opt) = @_;
return 0 if $text =~ /{{[nN]obots}}/;
return 1 if $text =~ /{{[bB]ots}}/;
if($text =~ /{{[bB]ots\s*\|\s*allow\s*=\s*(.*?)\s*}}/s){
return 1 if $1 eq 'all';
return 0 if $1 eq 'none';
my @bots = split(/\s*,\s*/, $1);
return (grep $_ eq $user, @bots)?1:0;
}
if($text =~ /{{[bB]ots\s*\|\s*deny\s*=\s*(.*?)\s*}}/s){
return 0 if $1 eq 'all';
return 1 if $1 eq 'none';
my @bots = split(/\s*,\s*/, $1);
return (grep $_ eq $user, @bots)?0:1;
}
if(defined($opt) && $text =~ /{{[bB]ots\s*\|\s*optout\s*=\s*(.*?)\s*}}/s){
return 0 if $1 eq 'all';
my @opt = split(/\s*,\s*/, $1);
return (grep $_ eq $opt, @opt)?0:1;
}
return 1;
}
VB.NET
changePublic Shared Function AllowBots(ByVal text As String, ByVal user As String) As Boolean
Return Not Regex.IsMatch(text, "\{\{(nobots|bots\|(allow=none|deny=(?!none).*(" & user.Normalize() & "|all)|optout=all))\}\}", RegexOptions.IgnoreCase)
End Function
C#
changepublic static bool AllowBots(string text, string user)
{
return !Regex.IsMatch(text, @"\{\{(nobots|bots\|(allow=none|deny=(?!none).*(" + user.Normalize() + @"|all)|optout=all))\}\}", RegexOptions.IgnoreCase);
}
Java
changepublic static boolean allowBots(String text, String user)
{
return !text.matches("(?si).*\\{\\{(nobots|bots\\|(allow=none|deny=(.*?" + user + ".*?|all)|optout=all))\\}\\}.*");
}
JavaScript
changefunction allowBots(text, user){
if (!new RegExp("\\{\\{\\s*(nobots|bots[^}]*)\\s*\\}\\}", "i").test(text)) return true;
return (new RegExp("\\{\\{\\s*bots\\s*\\|\\s*deny\\s*=\\s*([^}]*,\\s*)*"+user+"\\s*(?=[,\\}])[^}]*\\s*\\}\\}", "i").test(text)) ? false : new RegExp("\\{\\{\\s*((?!nobots)|bots(\\s*\\|\\s*allow\\s*=\\s*((?!none)|([^}]*,\\s*)*"+user+"\\s*(?=[,\\}])[^}]*|all))?|bots\\s*\\|\\s*deny\\s*=\\s*(?!all)[^}]*|bots\\s*\\|\\s*optout=(?!all)[^}]*)\\s*\\}\\}", "i").test(text);
}
Python
changedef allow_bots(text, user):
return not re.search(r'\{\{(nobots|bots\|(allow=none|deny=.*?' + user + r'.*?|optout=all|deny=all))\}\}', text)
See also
change- Template:Bots at Meta.