mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/AbuseFilter.git
synced 2024-12-14 06:50:02 +00:00
ca23e9f06b
Protected variables will cause the filter using them to become protected as well. `af_hidden` can be used to track this flag, as it is a TINYINT and can be converted into a bitmask with no schema changes. This is not a backwards-compatible change, as now all checks must check the `hidden` flag specifically or otherwise will be cast to true if any flag is set. To support this change: - "hidden" is considered a flag set in the `af_hidden`. This is a change in concept with no need for updates to the column values, as there is currently only one flag in the bitmask. - `Flag`s store the bitmask as well as the state of single flags and can return either. - Any checks against the `af_hidden` value no longer check a boolean value and instead now check the `hidden` flag value. Bug: T363906 Change-Id: I358205cb1119cf1e4004892c37e36e0c0a864f37
106 lines
1.9 KiB
PHP
106 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Filter;
|
|
|
|
/**
|
|
* (Mutable) value object to represent flags that can be *manually* set on a filter.
|
|
*/
|
|
class Flags {
|
|
/** @var bool */
|
|
private $enabled;
|
|
/** @var bool */
|
|
private $deleted;
|
|
/** @var bool */
|
|
private $hidden;
|
|
/** @var int */
|
|
private $privacyLevel;
|
|
/** @var bool */
|
|
private $global;
|
|
|
|
public const FILTER_PUBLIC = 0b00;
|
|
public const FILTER_HIDDEN = 0b01;
|
|
|
|
/**
|
|
* @param bool $enabled
|
|
* @param bool $deleted
|
|
* @param int $hidden
|
|
* @param bool $global
|
|
*/
|
|
public function __construct( bool $enabled, bool $deleted, int $hidden, bool $global ) {
|
|
$this->enabled = $enabled;
|
|
$this->deleted = $deleted;
|
|
$this->hidden = (bool)( self::FILTER_HIDDEN & $hidden );
|
|
$this->privacyLevel = $hidden;
|
|
$this->global = $global;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function getEnabled(): bool {
|
|
return $this->enabled;
|
|
}
|
|
|
|
/**
|
|
* @param bool $enabled
|
|
*/
|
|
public function setEnabled( bool $enabled ): void {
|
|
$this->enabled = $enabled;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function getDeleted(): bool {
|
|
return $this->deleted;
|
|
}
|
|
|
|
/**
|
|
* @param bool $deleted
|
|
*/
|
|
public function setDeleted( bool $deleted ): void {
|
|
$this->deleted = $deleted;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function getHidden(): bool {
|
|
return $this->hidden;
|
|
}
|
|
|
|
/**
|
|
* @param bool $hidden
|
|
*/
|
|
public function setHidden( bool $hidden ): void {
|
|
$this->hidden = $hidden;
|
|
$this->updatePrivacyLevel();
|
|
}
|
|
|
|
private function updatePrivacyLevel() {
|
|
$hidden = $this->hidden ? self::FILTER_HIDDEN : 0;
|
|
$this->privacyLevel = $hidden;
|
|
}
|
|
|
|
/**
|
|
* @return int
|
|
*/
|
|
public function getPrivacyLevel(): int {
|
|
return $this->privacyLevel;
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function getGlobal(): bool {
|
|
return $this->global;
|
|
}
|
|
|
|
/**
|
|
* @param bool $global
|
|
*/
|
|
public function setGlobal( bool $global ): void {
|
|
$this->global = $global;
|
|
}
|
|
}
|