From f7af8f6724c43f6fdf2c745e88f798bdf90c4839 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 8 May 2016 02:11:14 -0700 Subject: [PATCH] Add User::isBot() method Global group and other extensions can hook into the hook to flag global bots and the like. Change-Id: I1290932fccb62508d2a8b7f94f056badadf6fdfc --- RELEASE-NOTES-1.28 | 2 ++ docs/hooks.txt | 4 ++++ includes/user/User.php | 13 +++++++++++++ 3 files changed, 19 insertions(+) diff --git a/RELEASE-NOTES-1.28 b/RELEASE-NOTES-1.28 index c950921731..e3654869c4 100644 --- a/RELEASE-NOTES-1.28 +++ b/RELEASE-NOTES-1.28 @@ -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 === diff --git a/docs/hooks.txt b/docs/hooks.txt index a7092ec9e1..726500ca95 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/user/User.php b/includes/user/User.php index ee617a2caf..6ecd6b7ee1 100644 --- a/includes/user/User.php +++ b/includes/user/User.php @@ -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 * -- 2.20.1