2022-08-29 10:44:06 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace MediaWiki\Extension\VisualEditor;
|
|
|
|
|
2022-08-28 19:25:04 +00:00
|
|
|
use MediaWiki\Permissions\Authority;
|
2023-01-16 13:11:20 +00:00
|
|
|
use MediaWiki\Rest\Handler\Helper\PageRestHelperFactory;
|
2022-08-28 19:25:04 +00:00
|
|
|
use RequestContext;
|
2022-08-29 10:44:06 +00:00
|
|
|
|
2022-09-04 09:00:14 +00:00
|
|
|
/**
|
|
|
|
* @since 1.40
|
|
|
|
*/
|
2022-08-29 10:44:06 +00:00
|
|
|
class VisualEditorParsoidClientFactory {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal For use by ServiceWiring.php only or when locating the service
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public const SERVICE_NAME = 'VisualEditor.ParsoidClientFactory';
|
|
|
|
|
2023-04-24 19:10:30 +00:00
|
|
|
private PageRestHelperFactory $pageRestHelperFactory;
|
2022-08-29 10:44:06 +00:00
|
|
|
|
|
|
|
public function __construct(
|
2022-11-18 19:46:23 +00:00
|
|
|
PageRestHelperFactory $pageRestHelperFactory
|
2022-08-29 10:44:06 +00:00
|
|
|
) {
|
2022-11-18 19:46:23 +00:00
|
|
|
$this->pageRestHelperFactory = $pageRestHelperFactory;
|
2022-08-29 10:44:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-04 09:00:14 +00:00
|
|
|
* Create a ParsoidClient for accessing Parsoid.
|
|
|
|
*
|
|
|
|
* @param string|string[]|false $cookiesToForward
|
2022-08-28 19:25:04 +00:00
|
|
|
* @param Authority|null $performer
|
2022-09-04 09:00:14 +00:00
|
|
|
*
|
|
|
|
* @return ParsoidClient
|
2022-08-29 10:44:06 +00:00
|
|
|
*/
|
2022-10-19 12:43:26 +00:00
|
|
|
public function createParsoidClient(
|
2023-07-10 07:57:45 +00:00
|
|
|
/* Kept for compatibility with other extensions */ $cookiesToForward,
|
2022-11-18 19:46:23 +00:00
|
|
|
?Authority $performer = null
|
2022-10-19 12:43:26 +00:00
|
|
|
): ParsoidClient {
|
2022-08-28 19:25:04 +00:00
|
|
|
if ( $performer === null ) {
|
|
|
|
$performer = RequestContext::getMain()->getAuthority();
|
|
|
|
}
|
2022-09-04 09:00:14 +00:00
|
|
|
|
2023-07-10 07:57:45 +00:00
|
|
|
return $this->createDirectClient( $performer );
|
2022-10-13 10:05:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a ParsoidClient for accessing Parsoid.
|
|
|
|
*
|
|
|
|
* @param Authority $performer
|
|
|
|
*
|
|
|
|
* @return ParsoidClient
|
|
|
|
*/
|
|
|
|
private function createDirectClient( Authority $performer ): ParsoidClient {
|
2022-09-04 09:00:14 +00:00
|
|
|
return new DirectParsoidClient(
|
2022-11-18 19:46:23 +00:00
|
|
|
$this->pageRestHelperFactory,
|
2022-08-28 19:25:04 +00:00
|
|
|
$performer
|
2022-08-29 10:44:06 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|