2020-09-19 13:37:58 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\AbuseFilter\Filter;
|
|
|
|
|
2023-11-16 18:52:51 +00:00
|
|
|
use LogicException;
|
2020-09-19 13:37:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Value object representing a filter that can be mutated (i.e. provides setters); this representation can
|
|
|
|
* be used to modify an existing database filter before saving it back to the DB.
|
|
|
|
*/
|
|
|
|
class MutableFilter extends Filter {
|
|
|
|
/**
|
|
|
|
* Convenience shortcut to get a 'default' filter, using the defaults for the editing interface.
|
|
|
|
*
|
|
|
|
* @return self
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public static function newDefault(): self {
|
2020-09-19 13:37:58 +00:00
|
|
|
return new self(
|
|
|
|
new Specs(
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
'',
|
|
|
|
[],
|
|
|
|
''
|
|
|
|
),
|
|
|
|
new Flags(
|
|
|
|
true,
|
|
|
|
false,
|
2024-05-16 10:40:53 +00:00
|
|
|
Flags::FILTER_PUBLIC,
|
2020-09-19 13:37:58 +00:00
|
|
|
false
|
|
|
|
),
|
2020-09-20 11:30:59 +00:00
|
|
|
[],
|
2020-09-19 13:37:58 +00:00
|
|
|
new LastEditInfo(
|
|
|
|
0,
|
|
|
|
'',
|
|
|
|
''
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Filter $filter
|
|
|
|
* @return self
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public static function newFromParentFilter( Filter $filter ): self {
|
2020-09-19 13:37:58 +00:00
|
|
|
return new self(
|
|
|
|
$filter->getSpecs(),
|
|
|
|
$filter->getFlags(),
|
2020-09-20 11:30:59 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable One is guaranteed to be set
|
|
|
|
$filter->actions ?? $filter->actionsCallback,
|
2020-09-19 13:37:58 +00:00
|
|
|
$filter->getLastEditInfo(),
|
|
|
|
$filter->getID(),
|
|
|
|
$filter->getHitCount(),
|
|
|
|
$filter->isThrottled()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $rules
|
|
|
|
*/
|
|
|
|
public function setRules( string $rules ): void {
|
|
|
|
$this->specs->setRules( $rules );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $comments
|
|
|
|
*/
|
|
|
|
public function setComments( string $comments ): void {
|
|
|
|
$this->specs->setComments( $comments );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function setName( string $name ): void {
|
|
|
|
$this->specs->setName( $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-11-16 18:52:51 +00:00
|
|
|
* @throws LogicException if $actions are already set; use $this->setActions to update names
|
2020-09-19 13:37:58 +00:00
|
|
|
* @param string[] $actionsNames
|
|
|
|
*/
|
|
|
|
public function setActionsNames( array $actionsNames ): void {
|
|
|
|
if ( $this->actions !== null ) {
|
2023-11-16 18:52:51 +00:00
|
|
|
throw new LogicException( 'Cannot set actions names with actions already set' );
|
2020-09-19 13:37:58 +00:00
|
|
|
}
|
|
|
|
$this->specs->setActionsNames( $actionsNames );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $group
|
|
|
|
*/
|
|
|
|
public function setGroup( string $group ): void {
|
|
|
|
$this->specs->setGroup( $group );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $enabled
|
|
|
|
*/
|
|
|
|
public function setEnabled( bool $enabled ): void {
|
|
|
|
$this->flags->setEnabled( $enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $deleted
|
|
|
|
*/
|
|
|
|
public function setDeleted( bool $deleted ): void {
|
|
|
|
$this->flags->setDeleted( $deleted );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $hidden
|
|
|
|
*/
|
|
|
|
public function setHidden( bool $hidden ): void {
|
|
|
|
$this->flags->setHidden( $hidden );
|
|
|
|
}
|
|
|
|
|
2024-05-23 14:49:17 +00:00
|
|
|
/**
|
|
|
|
* @param bool $protected
|
|
|
|
*/
|
|
|
|
public function setProtected( bool $protected ): void {
|
|
|
|
$this->flags->setProtected( $protected );
|
|
|
|
}
|
|
|
|
|
2020-09-19 13:37:58 +00:00
|
|
|
/**
|
|
|
|
* @param bool $global
|
|
|
|
*/
|
|
|
|
public function setGlobal( bool $global ): void {
|
|
|
|
$this->flags->setGlobal( $global );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @note This also updates action names
|
|
|
|
* @param array[] $actions
|
|
|
|
*/
|
2021-07-21 18:51:12 +00:00
|
|
|
public function setActions( array $actions ): void {
|
2020-09-19 13:37:58 +00:00
|
|
|
parent::setActions( $actions );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $id
|
|
|
|
*/
|
|
|
|
public function setUserID( int $id ): void {
|
|
|
|
$this->lastEditInfo->setUserID( $id );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function setUserName( string $name ): void {
|
|
|
|
$this->lastEditInfo->setUserName( $name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $timestamp
|
|
|
|
*/
|
|
|
|
public function setTimestamp( string $timestamp ): void {
|
|
|
|
$this->lastEditInfo->setTimestamp( $timestamp );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int|null $id
|
|
|
|
*/
|
|
|
|
public function setID( ?int $id ): void {
|
|
|
|
$this->id = $id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $hitCount
|
|
|
|
*/
|
|
|
|
public function setHitCount( int $hitCount ): void {
|
|
|
|
$this->hitCount = $hitCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param bool $throttled
|
|
|
|
*/
|
|
|
|
public function setThrottled( bool $throttled ): void {
|
|
|
|
$this->throttled = $throttled;
|
|
|
|
}
|
|
|
|
}
|