Implementation ของ แม่แบบ:Bots

  • 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

PHP

function 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; }    return true;}

Perl

sub allowBots {    my($text, $user, $opt) = @_;    return 0 if $text =~ /{{nob[o]ts}}/;    return 1 if $text =~ /{{b[o]ts}}/;    if($text =~ /{{bots\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 =~ /{{bots\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 =~ /{{bots\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;}

C#

public static bool AllowBots(string text, string user){    return !Regex.Match(text, @"\{\{(nobots|bots\|(allow=none|deny=.*?" + user.Normalize() + @".*?|optout=all|deny=all))\}\}", RegexOptions.IgnoreCase).Success;}

Java

public static boolean AllowBots(String text, String user){      return !Regex.Match(text, "\\{\\{(nobots|bots\\|(allow=none|deny=.*?" + user.Normalize() + ".*?|optout=all|deny=all))\\}\\}", RegexOptions.IgnoreCase).Success;}

Python

def Allowbots(text, user):    if (re.search(r'\{\{(nobots|bots\|(allow=none|deny=.*?' + user + r'.*?|optout=all|deny=all))\}\}', text)):        return false    return true