| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\AbuseFilter\EditBox; |
| 4 |
|
| 5 |
use LogicException; |
| 6 |
use MediaWiki\Extension\AbuseFilter\AbuseFilterPermissionManager; |
| 7 |
use MediaWiki\Extension\AbuseFilter\KeywordsManager; |
| 8 |
use MediaWiki\Output\OutputPage; |
| 9 |
use MediaWiki\Permissions\Authority; |
| 10 |
use MessageLocalizer; |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
class EditBoxBuilderFactory { |
| 16 |
|
| 17 |
public const SERVICE_NAME = 'AbuseFilterEditBoxBuilderFactory'; |
| 18 |
|
| 19 |
|
| 20 |
private $afPermManager; |
| 21 |
|
| 22 |
|
| 23 |
private $keywordsManager; |
| 24 |
|
| 25 |
|
| 26 |
private $isCodeEditorLoaded; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
public function __construct( |
| 34 |
AbuseFilterPermissionManager $afPermManager, |
| 35 |
KeywordsManager $keywordsManager, |
| 36 |
bool $isCodeEditorLoaded |
| 37 |
) { |
| 38 |
$this->afPermManager = $afPermManager; |
| 39 |
$this->keywordsManager = $keywordsManager; |
| 40 |
$this->isCodeEditorLoaded = $isCodeEditorLoaded; |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function newEditBoxBuilder( |
| 51 |
MessageLocalizer $messageLocalizer, |
| 52 |
Authority $authority, |
| 53 |
OutputPage $output |
| 54 |
): EditBoxBuilder { |
| 55 |
return $this->isCodeEditorLoaded |
| 56 |
? $this->newAceBoxBuilder( $messageLocalizer, $authority, $output ) |
| 57 |
: $this->newPlainBoxBuilder( $messageLocalizer, $authority, $output ); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
public function newPlainBoxBuilder( |
| 67 |
MessageLocalizer $messageLocalizer, |
| 68 |
Authority $authority, |
| 69 |
OutputPage $output |
| 70 |
): PlainEditBoxBuilder { |
| 71 |
return new PlainEditBoxBuilder( |
| 72 |
$this->afPermManager, |
| 73 |
$this->keywordsManager, |
| 74 |
$messageLocalizer, |
| 75 |
$authority, |
| 76 |
$output |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
public function newAceBoxBuilder( |
| 87 |
MessageLocalizer $messageLocalizer, |
| 88 |
Authority $authority, |
| 89 |
OutputPage $output |
| 90 |
): AceEditBoxBuilder { |
| 91 |
if ( !$this->isCodeEditorLoaded ) { |
| 92 |
throw new LogicException( 'Cannot create Ace box without CodeEditor' ); |
| 93 |
} |
| 94 |
return new AceEditBoxBuilder( |
| 95 |
$this->afPermManager, |
| 96 |
$this->keywordsManager, |
| 97 |
$messageLocalizer, |
| 98 |
$authority, |
| 99 |
$output, |
| 100 |
$this->newPlainBoxBuilder( |
| 101 |
$messageLocalizer, |
| 102 |
$authority, |
| 103 |
$output |
| 104 |
) |
| 105 |
); |
| 106 |
} |
| 107 |
|
| 108 |
} |