Add User::isBot() method
authorAaron Schulz <aschulz@wikimedia.org>
Sun, 8 May 2016 09:11:14 +0000 (02:11 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 11 May 2016 00:26:29 +0000 (17:26 -0700)
Global group and other extensions can hook into the hook
to flag global bots and the like.

Change-Id: I1290932fccb62508d2a8b7f94f056badadf6fdfc

RELEASE-NOTES-1.28
docs/hooks.txt
includes/user/User.php

index c950921..e365486 100644 (file)
@@ -11,6 +11,8 @@ production.
   user's language. If such access is attempted, an exception will be thrown.
 
 === New features in 1.28 ===
+* User::isBot() method for checking if an account is a bot role account.
+* Added a new hook, 'UserIsBot', to aid in determining if a user is a bot.
 
 
 === External library changes in 1.28 ===
index a7092ec..726500c 100644 (file)
@@ -3216,6 +3216,10 @@ $mime: (string) The uploaded file's MIME type, as detected by MediaWiki.
   representing the problem with the file, where the first element is the message
   key and the remaining elements are used as parameters to the message.
 
+'UserIsBot': when determining whether a user is a bot account
+$user: the user
+&$isBot: whether this is user a bot or not (boolean)
+
 'User::mailPasswordInternal': before creation and mailing of a user's new
 temporary password
 &$user: the user who sent the message out
index ee617a2..6ecd6b7 100644 (file)
@@ -3398,6 +3398,19 @@ class User implements IDBAccessObject {
                return !$this->isLoggedIn();
        }
 
+       /**
+        * @return bool Whether this user is flagged as being a bot role account
+        * @since 1.28
+        */
+       public function isBot() {
+               $isBot = false;
+               if ( !Hooks::run( "UserIsBot", [ $this, &$isBot ] ) ) {
+                       return $isBot;
+               }
+
+               return ( $isBot || in_array( 'bot', $this->getGroups() ) );
+       }
+
        /**
         * Check if user is allowed to access a feature / make an action
         *