1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
<?php
namespace MediaWiki\Extension\AbuseFilter\Filter;
use LogicException;
/**
* 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
*/
public static function newDefault(): self {
return new self(
new Specs(
'',
'',
'',
[],
''
),
new Flags(
true,
false,
Flags::FILTER_PUBLIC,
false
),
[],
new LastEditInfo(
0,
'',
''
)
);
}
/**
* @param Filter $filter
* @return self
*/
public static function newFromParentFilter( Filter $filter ): self {
return new self(
$filter->getSpecs(),
$filter->getFlags(),
// @phan-suppress-next-line PhanTypeMismatchArgumentNullable One is guaranteed to be set
$filter->actions ?? $filter->actionsCallback,
$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 );
}
/**
* @throws LogicException if $actions are already set; use $this->setActions to update names
* @param string[] $actionsNames
*/
public function setActionsNames( array $actionsNames ): void {
if ( $this->actions !== null ) {
throw new LogicException( 'Cannot set actions names with actions already set' );
}
$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 );
}
/**
* @param bool $protected
*/
public function setProtected( bool $protected ): void {
$this->flags->setProtected( $protected );
}
/**
* @param bool $global
*/
public function setGlobal( bool $global ): void {
$this->flags->setGlobal( $global );
}
/**
* @note This also updates action names
* @param array[] $actions
*/
public function setActions( array $actions ): void {
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;
}
}
|