ઢાંચો:Nobots/doc: આવૃત્તિઓ વચ્ચેનો તફાવત

Content deleted Content added
નવું પાનું : {{documentation subpage}} <!-- EDIT TEMPLATE DOCUMENTATION BELOW THIS LINE --> These templates tell bots and automated editing tools/scripts that they s...
 
નાનું Bot: Replace deprecated <source> tag and "enclose" parameter [https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2020-April/002284.html]
 
લીટી ૭૫:
=== Example implementations ===
==== PHP ====
<sourcesyntaxhighlight lang="php">
function allowBots( $text ) {
global $user;
લીટી ૮૬:
return true;
}
</syntaxhighlight>
</source>
 
==== Perl ====
 
<sourcesyntaxhighlight lang="perl">
sub allowBots {
my($text, $user, $opt) = @_;
લીટી ૧૧૪:
return 1;
}
</syntaxhighlight>
</source>
 
==== VB.NET ====
<sourcesyntaxhighlight lang="vbnet">
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
</syntaxhighlight>
</source>
 
==== C# ====
<sourcesyntaxhighlight lang="csharp">
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);
}
</syntaxhighlight>
</source>
 
==== Java ====
<sourcesyntaxhighlight lang="java">
public static boolean allowBots(String text, String user)
{
return !text.matches("(?si).*\\{\\{(nobots|bots\\|(allow=none|deny=(.*?" + user + ".*?|all)|optout=all))\\}\\}.*");
}
</syntaxhighlight>
</source>
 
==== JavaScript ====
<sourcesyntaxhighlight lang="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+"\\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);
}
</syntaxhighlight>
</source>
 
==== Python ====
<sourcesyntaxhighlight lang="python">
def allow_bots(text, user):
if (re.search(r'\{\{(nobots|bots\|(allow=none|deny=.*?'+user+r'.*?|optout=all|deny=all))\}\}', text)):
return False
return True
</syntaxhighlight>
</source>
 
==See also==