Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / Permissions / RateLimitSubject.php
blobeafc14c7e66c12f78716f5049608b7ac67c92843
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
18 * @file
21 namespace MediaWiki\Permissions;
23 use MediaWiki\User\UserIdentity;
25 /**
26 * Represents the subject that rate limits are applied to.
28 * @unstable
29 * @since 1.39
31 class RateLimitSubject {
33 /**
34 * @var UserIdentity
36 private $user;
38 /**
39 * @var string|null
41 private $ip;
43 /**
44 * @var array
46 private $flags;
48 /** @var string Flag indicating the user is exempt from rate limits */
49 public const EXEMPT = 'exempt';
51 /** @var string Flag indicating the user is a newbie */
52 public const NEWBIE = 'newbie';
54 /**
55 * @internal
57 * @param UserIdentity $user
58 * @param string|null $ip
59 * @param array<string,bool> $flags
61 public function __construct( UserIdentity $user, ?string $ip, array $flags ) {
62 $this->user = $user;
63 $this->ip = $ip;
64 $this->flags = $flags;
67 public function getUser(): UserIdentity {
68 return $this->user;
71 public function getIP(): ?string {
72 return $this->ip;
75 /**
76 * Checks whether the given flag applies.
78 * @param string $flag
80 * @return bool
82 public function is( string $flag ) {
83 return !empty( $this->flags[$flag] );