Jump to content
 







Main menu
   


Navigation  



Main page
Contents
Current events
Random article
About Wikipedia
Contact us
Donate
 




Contribute  



Help
Learn to edit
Community portal
Recent changes
Upload file
 








Search  

































Create account

Log in
 









Create account
 Log in
 




Pages for logged out editors learn more  



Contributions
Talk
 



















Contents

   



(Top)
 


1 Important notes  





2 Syntax  





3 Message notification opt out  



3.1  Restrictions of messages that can be opted out  







4 Incorrect syntax  





5 Implementation  



5.1  Example implementations  



5.1.1  PHP  





5.1.2  Perl  





5.1.3  VB.NET  





5.1.4  C#  





5.1.5  Java  





5.1.6  JavaScript  





5.1.7  Python  









6 See also  














Template:Bots






Afrikaans
العربية

تۆرکجه
Basa Bali

Banjar
 / Bân-lâm-gú
Башҡортса
Беларуская

Български
Boarisch
ChiShona
Dansk
الدارجة
Deitsch
Deutsch
Diné bizaad
Dolnoserbski
Eesti
Эрзянь
Español
Esperanto
Euskara
Føroyskt
Français
Gagauz


Hausa
Հայերեն
ि
Hornjoserbsce
Hrvatski
Ido
Ilokano
Bahasa Indonesia
Interlingue
Ирон
Íslenska
Italiano
עברית
Jawa
Ikirundi
Кырык мары
Лакку
Latina
Latviešu
Лезги
Lietuvių
Magyar
Македонски



مصرى
Bahasa Melayu
Minangkabau
 / Mìng-dĕ̤ng-nḡ
Монгол

Na Vosa Vakaviti
Nederlands
Nedersaksies


Нохчийн
Nordfriisk
Norsk bokmål
ି
ि
Pälzisch
Перем коми

Plattdüütsch
Polski
Português
Ripoarisch
Română
Русиньскый
Русский


Scots
Sesotho sa Leboa
Shqip

Simple English
سنڌي
Slovenščina
Словѣньскъ / 
Ślůnski
کوردی
Српски / srpski
Srpskohrvatski / српскохрватски
Suomi
Svenska
ி
Taqbaylit
Tarandíne
Татарча / tatarça
 

Tetun


Türkçe
Удмурт
Basa Ugi
Українська
اردو
Vepsän kel
Tiếng Vit

ייִדיש

Zeêuws

 

Edit links
 









Template
Talk
 

















Read
View source
View history
 








Tools
   


Actions  



Read
View source
View history
 




General  



What links here
Related changes
Upload file
Special pages
Permanent link
Page information
Get shortened URL
Download QR code
Wikidata item
 




Print/export  



Download as PDF
Printable version
 




In other projects  



Wikimedia Commons
Wikimedia Foundation
Meta-Wiki
Wikibooks
Wikidata
Wikinews
Wikiquote
Wikiversity
 
















Appearance
   

 





Permanently protected template

From Wikipedia, the free encyclopedia
 


The Bots and Nobots templates tell bots and other automated editing tools and scripts that they either should or should not edit a page that has the template. 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 receiving useful changes or targeted posts a bot might otherwise skip by following "opt-out" behavior by default. 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:

Important notes

Most bots will NOT understand these templates when they are indirectly transcluded.

Most bots will not disregard the template if it is inside of <nowiki>...</nowiki> tags. For example, if you are discussing the templates with another editor, please use the {{tl}} template, e.g. {{tl|nobots}}, which will show {{nobots}}, rather than <nowiki>{{nobots}}</nowiki>, which will possibly be parsed as intending to exclude bots from the page.

A list of transclusions is at User:AnomieBOT/Nobots Hall of Shame

Syntax

{{nobots}}                Ban all compliant bots (shortcut that takes no parameters)
{{bots}}                  Allow all bots (shortcut that takes no parameters)
{{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=SineBot,Legobot}}
  {{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 template; 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.

Message notification opt out

Another option is to opt out of specific types of messages for users who wish to be notified of certain problems, but not others. Users should be aware that by opting-out of specific notification posts, they will not be notified of matters relating to material they have edited or uploaded, which are tagged per policy. Actions (such as deletion) may be executed without you being notified as a result. By applying this to your own user talk page, you agree to this consequence. Applying this to a user talk page other than your own will be considered vandalism. All bots and scripts that leave messages on a user's talk page are encouraged to add this capability.

By adding this to a user's talk page, a user may still receive these messages by non-compliant bots or scripts, or humans who add the tag manually.

{{bots|optout=all}}            Opt out of all messages (see limitations below).
{{bots|optout=nosource}}       Opt out of no source messages.
{{bots|optout=nolicense}}      Opt out of no license messages.
{{bots|optout=orfud}}          Opt out of orphaned fair use messages.
{{bots|optout=npd}}            Opt out of no permission messages.
{{bots|optout=norationale}}    Opt out of no rationale messages.
{{bots|optout=replaceable}}    Opt out of replaceable fair use messages.
{{bots|optout=bettersource}}   Opt out of better source request messages.
{{bots|optout=afd}}            Opt out of articles for deletion messages or variant forms.
{{bots|optout=ifd}}            Opt out of images for deletion messages or variant.
{{bots|optout=prod}}           Opt out of prod warning.
{{bots|optout=MassMessage}}    Opt out of Mass messages.

Items can be combined by putting a comma between options

{{bots|optout=nosource,nolicense}}                 Opt out of no source, and no license messages.
{{bots|optout=orfud,norationale,replaceable}}      Opt out of fair use messages.

Restrictions of messages that can be opted out

Some message notifications are not allowed to be opted out. These include:

  1. Copyright violation notifications
  2. Vandalism (and other) warning notices.
  3. User:SineBot's notices for not signing posts
  4. Any message tag that isn't included as a way of opting out above. (Is there one that should be included? Leave a message on the talk page.)
  5. Mass messages cannot be opted-out of by using {{bots|optout=all}}; users must explicitly opt out with {{bots|optout=MassMessage}}

Incorrect syntax

These syntaxes look correct, but depending on the individual bot may not have the intended effect.

INCORRECT CORRECT Notes
{{bots|deny=Bot1|deny=Bot2}} {{bots|deny=Bot1,Bot2}} This statement may deny neither Bot1 nor Bot2, only one of the two bots, or both bots as intended. Under a strict interpretation, it would deny a bot named "Bot1|deny=Bot2".
{{bots|allow=Bot1}}{{bots|allow=Bot2}} {{bots|allow=Bot1,Bot2}} This statement may allow neither Bot1 nor Bot2, only one of the two bots, or both bots as intended. Under a strict interpretation, each bot should be denied by the template not mentioning it.
{{bots|deny=Bot1}}{{bots|deny=Bot2}} {{bots|deny=Bot1,Bot2}} While this should work, some bots may process only the first or last instance of {{bots|deny=...}} in a page.
{{bots|allow=Bot1|deny=Bot2}} {{bots|allow=Bot1}} This statement may not deny Bot2, and may not allow Bot1. Under a strict interpretation, it would allow only a bot named "Bot1|deny=Bot2".
{{bots|deny=all,Bot1}} {{bots|deny=all}} This statement may not deny some bots. The "all" keyword is not documented as being able to be used in comma syntax.
{{nobots|deny=all}} {{nobots}} This statement may not deny some bots. The {{nobots}} redirect takes no parameters.
{{nobots|deny=Bot1}} {{bots|deny=Bot1}} This statement may not deny Bot1, or may deny other bots too. The {{nobots}} redirect takes no parameters.
{{nobots|allow=Bot1}} {{bots|allow=Bot1}} This statement may not deny some bots, or may deny Bot1. The {{nobots}} redirect takes no parameters.
{{bots|deny=all|optout=MassMessage}} {{bots|deny=all}}{{bots|optout=MassMessage}} This statement may not deny some bots. Under a strict interpretation, it would deny a bot named "all|optout=MassMessage".
{{nobots|optout=afd}} {{bots|optout=afd}} This statement may not opt out of afd messages, or may deny other bots too. The {{nobots}} redirect takes no parameters.
{{bots|optout=all,afd}} {{bots|optout=all}} This statement may not deny some bots. The "all" keyword is not documented as being able to be used in comma syntax.

Note there's currently no 100% reliable method to opt out of "all" and "MassMessage" due to the non-standard way "optout=MassMessage" works by setting a category, but {{bots|optout=all}}{{bots|optout=MassMessage}} is probably your best bet (or fix the template to apply the category on "optout=all" too).

{{bots}}{{bots|deny=Bot1}} {{bots|deny=Bot1}} This statement may not deny Bot1. It's unclear what the priority should be between "allow all bots" and "deny Bot1".
{{bots|allow=all}}{{bots|deny=Bot1}} {{bots|deny=Bot1}} This statement may not deny Bot1. It's unclear what the priority should be between "allow all bots" and "deny Bot1".
{{bots|allow=Bot1}}{{bots|deny=Bot1}} {{bots|deny=all}} This statement may not deny Bot1. The first statement should deny all bots except Bot1 while the second should deny Bot1, but Bot1 may stop as soon as it sees the "allow".

Implementation

Example implementations

PHP

function allowBots( $text, $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

sub allow_bots {
    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

Public 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#

public 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

public static boolean allowBots(String text, String user)
{
      return !text.matches("(?si).*\\{\\{(nobots|bots\\|(allow=none|deny=([^\\}]*?" + user + "[^\\}]*?|all)|optout=all))\\}\\}.*");
}

JavaScript

function 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.replace(/([\(\)\*\+\?\.\-\:\!\=\/\^\$])/g, "\\$1") + "\\s*(?=[,\\}])[^}]*\\s*\\}\\}", "i").test(text)) ? false : new RegExp("\\{\\{\\s*((?!nobots)|bots(\\s*\\|\\s*allow\\s*=\\s*((?!none)|([^}]*,\\s*)*" + user.replace(/([\(\)\*\+\?\.\-\:\!\=\/\^\$])/g, "\\$1") + "\\s*(?=[,\\}])[^}]*|all))?|bots\\s*\\|\\s*deny\\s*=\\s*(?!all)[^}]*|bots\\s*\\|\\s*optout=(?!all)[^}]*)\\s*\\}\\}", "i").test(text);
}

Python

This code assumes that the mwparserfromhell library was installed and imported in the current script.

def allow_bots(text, user):
 user = user.lower().strip()
 text = mwparserfromhell.parse(text)
 for tl in text.filter_templates():
  if tl.name.matches(['bots', 'nobots']):
   break
 else:
  return True
 for param in tl.params:
  bots = [x.lower().strip() for x in param.value.split(",")]
  if param.name == 'allow':
   if ''.join(bots) == 'none': return False
   for bot in bots:
    if bot in (user, 'all'):
     return True
  elif param.name == 'deny':
   if ''.join(bots) == 'none': return True
   for bot in bots:
    if bot in (user, 'all'):
     return False
 if (tl.name.matches('nobots') and len(tl.params) == 0):
  return False
 return True

See also


Retrieved from "https://en.wikipedia.org/w/index.php?title=Template:Bots&oldid=1233326681"

Categories: 
Templates based on the String Lua module
Wikipedia utility templates
Wikipedia bot-related templates
Wikipedia exclusion compliance
Templates with no visible output
Hidden category: 
Wikipedia template-protected templates
 



This page was last edited on 8 July 2024, at 13:57 (UTC).

Text is available under the Creative Commons Attribution-ShareAlike License 4.0; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy. Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.



Privacy policy

About Wikipedia

Disclaimers

Contact Wikipedia

Code of Conduct

Developers

Statistics

Cookie statement

Mobile view



Wikimedia Foundation
Powered by MediaWiki