Jump to content

Template:Bots/doc

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 2601:18e:c301:1e20:3c0f:166a:484a:a3ef (talk) at 01:53, 2 November 2021 (Typis). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Thomas.adams.mack@gmail.com

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.

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}}coumley626@outlook.com, rather than <nowiki>{{nobots}}</nowiki>, which will possibly be parsed as intending to ban 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.

= Incorrect syntax

{{bots|deny=Bot1|deny=Bot2}} INCORRECT

Instead, write:

{{bots|deny=Bot1,Bot2}}      CORRECT

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=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=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. 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.)
  4. Mass messages cannot be opted-out of by using {{bots|optout=all}}; users must explicitly opt out with {{bots|optout=MassMessage}}

Implementation

  • Pywikibot supports bots and nobots since r4096. The templates may be ignored using a parameter.

Land notice above of implementation may not include this feature.

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;

}

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