| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\Filter; |
| 4 |
|
| 5 |
use Wikimedia\Assert\Assert; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
class AbstractFilter { |
| 12 |
|
| 13 |
protected $specs; |
| 14 |
|
| 15 |
protected $flags; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
protected $actions; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
protected $actionsCallback; |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function __construct( |
| 34 |
Specs $specs, |
| 35 |
Flags $flags, |
| 36 |
$actions |
| 37 |
) { |
| 38 |
$this->specs = clone $specs; |
| 39 |
$this->flags = clone $flags; |
| 40 |
Assert::parameterType( 'callable|array', $actions, '$actions' ); |
| 41 |
if ( is_callable( $actions ) ) { |
| 42 |
$this->actionsCallback = $actions; |
| 43 |
} elseif ( is_array( $actions ) ) { |
| 44 |
$this->setActions( $actions ); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
public function getSpecs(): Specs { |
| 52 |
return clone $this->specs; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
public function getFlags(): Flags { |
| 59 |
return clone $this->flags; |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
public function getRules(): string { |
| 66 |
return $this->specs->getRules(); |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
public function getComments(): string { |
| 73 |
return $this->specs->getComments(); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function getName(): string { |
| 80 |
return $this->specs->getName(); |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function getActionsNames(): array { |
| 88 |
return $this->specs->getActionsNames(); |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
public function getGroup(): string { |
| 95 |
return $this->specs->getGroup(); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public function isEnabled(): bool { |
| 102 |
return $this->flags->getEnabled(); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public function isDeleted(): bool { |
| 109 |
return $this->flags->getDeleted(); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
public function isHidden(): bool { |
| 116 |
return $this->flags->getHidden(); |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public function isProtected(): bool { |
| 123 |
return $this->flags->getProtected(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
public function getPrivacyLevel(): int { |
| 130 |
return $this->flags->getPrivacyLevel(); |
| 131 |
} |
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
public function isGlobal(): bool { |
| 137 |
return $this->flags->getGlobal(); |
| 138 |
} |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public function getActions(): array { |
| 144 |
if ( $this->actions === null ) { |
| 145 |
$this->setActions( call_user_func( $this->actionsCallback ) ); |
| 146 |
|
| 147 |
$this->actionsCallback = null; |
| 148 |
} |
| 149 |
return $this->actions; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
protected function setActions( array $actions ): void { |
| 156 |
$this->actions = $actions; |
| 157 |
$this->specs->setActionsNames( array_keys( $actions ) ); |
| 158 |
} |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
public function __clone() { |
| 164 |
$this->specs = clone $this->specs; |
| 165 |
$this->flags = clone $this->flags; |
| 166 |
} |
| 167 |
|
| 168 |
} |