mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
2c1989c338
Change-Id: I7a3c5ef6435a38ef136e830b343dc19166659ef0
62 lines
1.4 KiB
PHP
62 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Extension\VisualEditor;
|
|
|
|
use MediaWiki\Permissions\Authority;
|
|
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
|
|
use RequestContext;
|
|
|
|
/**
|
|
* @since 1.40
|
|
*/
|
|
class VisualEditorParsoidClientFactory {
|
|
|
|
/**
|
|
* @internal For use by ServiceWiring.php only or when locating the service
|
|
* @var string
|
|
*/
|
|
public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory';
|
|
|
|
private PageRestHelperFactory $pageRestHelperFactory;
|
|
|
|
public function __construct(
|
|
PageRestHelperFactory $pageRestHelperFactory
|
|
) {
|
|
$this->pageRestHelperFactory = $pageRestHelperFactory;
|
|
}
|
|
|
|
/**
|
|
* Create a ParsoidClient for accessing Parsoid.
|
|
*
|
|
* @param string|string[]|false $cookiesToForward
|
|
* @param Authority|null $performer
|
|
*
|
|
* @return ParsoidClient
|
|
*/
|
|
public function createParsoidClient(
|
|
/* Kept for compatibility with other extensions */ $cookiesToForward,
|
|
?Authority $performer = null
|
|
): ParsoidClient {
|
|
if ( $performer === null ) {
|
|
$performer = RequestContext::getMain()->getAuthority();
|
|
}
|
|
|
|
return $this->createDirectClient( $performer );
|
|
}
|
|
|
|
/**
|
|
* Create a ParsoidClient for accessing Parsoid.
|
|
*
|
|
* @param Authority $performer
|
|
*
|
|
* @return ParsoidClient
|
|
*/
|
|
private function createDirectClient( Authority $performer ): ParsoidClient {
|
|
return new DirectParsoidClient(
|
|
$this->pageRestHelperFactory,
|
|
$performer
|
|
);
|
|
}
|
|
|
|
}
|