| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Extension\VisualEditor; |
| 4 |
|
| 5 |
use MediaWiki\Context\RequestContext; |
| 6 |
use MediaWiki\Permissions\Authority; |
| 7 |
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
class VisualEditorParsoidClientFactory { |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory'; |
| 18 |
|
| 19 |
private PageRestHelperFactory $pageRestHelperFactory; |
| 20 |
|
| 21 |
public function __construct( |
| 22 |
PageRestHelperFactory $pageRestHelperFactory |
| 23 |
) { |
| 24 |
$this->pageRestHelperFactory = $pageRestHelperFactory; |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function createParsoidClient( |
| 36 |
$cookiesToForward, |
| 37 |
?Authority $performer = null |
| 38 |
): ParsoidClient { |
| 39 |
if ( $performer === null ) { |
| 40 |
$performer = RequestContext::getMain()->getAuthority(); |
| 41 |
} |
| 42 |
|
| 43 |
return $this->createDirectClient( $performer ); |
| 44 |
} |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
private function createDirectClient( Authority $performer ): ParsoidClient { |
| 50 |
return new DirectParsoidClient( |
| 51 |
$this->pageRestHelperFactory, |
| 52 |
$performer |
| 53 |
); |
| 54 |
} |
| 55 |
|
| 56 |
} |