| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Filter; |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
class Flags { |
| 9 |
|
| 10 |
private $enabled; |
| 11 |
|
| 12 |
private $deleted; |
| 13 |
|
| 14 |
private $hidden; |
| 15 |
|
| 16 |
private $protected; |
| 17 |
|
| 18 |
private $privacyLevel; |
| 19 |
|
| 20 |
private $global; |
| 21 |
|
| 22 |
public const FILTER_PUBLIC = 0b00; |
| 23 |
public const FILTER_HIDDEN = 0b01; |
| 24 |
public const FILTER_USES_PROTECTED_VARS = 0b10; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public function __construct( bool $enabled, bool $deleted, int $privacyLevel, bool $global ) { |
| 33 |
$this->enabled = $enabled; |
| 34 |
$this->deleted = $deleted; |
| 35 |
$this->hidden = (bool)( self::FILTER_HIDDEN & $privacyLevel ); |
| 36 |
$this->protected = (bool)( self::FILTER_USES_PROTECTED_VARS & $privacyLevel ); |
| 37 |
$this->privacyLevel = $privacyLevel; |
| 38 |
$this->global = $global; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public function getEnabled(): bool { |
| 45 |
return $this->enabled; |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function setEnabled( bool $enabled ): void { |
| 52 |
$this->enabled = $enabled; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function getDeleted(): bool { |
| 59 |
return $this->deleted; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function setDeleted( bool $deleted ): void { |
| 66 |
$this->deleted = $deleted; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function getHidden(): bool { |
| 73 |
return $this->hidden; |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function setHidden( bool $hidden ): void { |
| 80 |
$this->hidden = $hidden; |
| 81 |
$this->updatePrivacyLevel(); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function getProtected(): bool { |
| 88 |
return $this->protected; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public function setProtected( bool $protected ): void { |
| 95 |
$this->protected = $protected; |
| 96 |
$this->updatePrivacyLevel(); |
| 97 |
} |
| 98 |
|
| 99 |
private function updatePrivacyLevel() { |
| 100 |
$hidden = $this->hidden ? self::FILTER_HIDDEN : 0; |
| 101 |
$protected = $this->protected ? self::FILTER_USES_PROTECTED_VARS : 0; |
| 102 |
$this->privacyLevel = $hidden | $protected; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public function getPrivacyLevel(): int { |
| 109 |
return $this->privacyLevel; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public function getGlobal(): bool { |
| 116 |
return $this->global; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function setGlobal( bool $global ): void { |
| 123 |
$this->global = $global; |
| 124 |
} |
| 125 |
} |