2022-11-18 16:55:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
2023-01-13 21:30:21 +00:00
|
|
|
namespace MediaWiki\Rest\Handler\Helper;
|
2022-11-18 16:55:18 +00:00
|
|
|
|
|
|
|
|
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
|
|
|
|
use MediaWiki\Config\ServiceOptions;
|
2022-11-24 21:54:11 +00:00
|
|
|
use MediaWiki\Content\IContentHandlerFactory;
|
2022-11-18 16:55:18 +00:00
|
|
|
use MediaWiki\Edit\ParsoidOutputStash;
|
2023-06-16 18:56:48 +00:00
|
|
|
use MediaWiki\Languages\LanguageConverterFactory;
|
2022-11-24 21:54:11 +00:00
|
|
|
use MediaWiki\Languages\LanguageFactory;
|
2022-11-18 16:55:18 +00:00
|
|
|
use MediaWiki\Page\PageLookup;
|
2023-06-11 16:56:29 +00:00
|
|
|
use MediaWiki\Page\RedirectStore;
|
2022-11-18 16:55:18 +00:00
|
|
|
use MediaWiki\Parser\Parsoid\HtmlTransformFactory;
|
|
|
|
|
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
2023-06-11 16:56:29 +00:00
|
|
|
use MediaWiki\Rest\RequestInterface;
|
|
|
|
|
use MediaWiki\Rest\ResponseFactory;
|
|
|
|
|
use MediaWiki\Rest\Router;
|
2022-11-18 16:55:18 +00:00
|
|
|
use MediaWiki\Revision\RevisionLookup;
|
2023-09-18 14:26:53 +00:00
|
|
|
use MediaWiki\Title\TitleFormatter;
|
2022-11-18 16:55:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 1.40 Factory for helper objects designed for sharing logic between REST handlers that deal with page content.
|
|
|
|
|
*/
|
|
|
|
|
class PageRestHelperFactory {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @internal
|
|
|
|
|
*/
|
|
|
|
|
public const CONSTRUCTOR_OPTIONS = PageContentHelper::CONSTRUCTOR_OPTIONS;
|
|
|
|
|
|
|
|
|
|
private ServiceOptions $options;
|
|
|
|
|
private RevisionLookup $revisionLookup;
|
|
|
|
|
private TitleFormatter $titleFormatter;
|
|
|
|
|
private PageLookup $pageLookup;
|
|
|
|
|
private ParsoidOutputStash $parsoidOutputStash;
|
|
|
|
|
private StatsdDataFactoryInterface $stats;
|
|
|
|
|
private ParsoidOutputAccess $parsoidOutputAccess;
|
|
|
|
|
private HtmlTransformFactory $htmlTransformFactory;
|
2022-11-24 21:54:11 +00:00
|
|
|
private IContentHandlerFactory $contentHandlerFactory;
|
|
|
|
|
private LanguageFactory $languageFactory;
|
2023-06-11 16:56:29 +00:00
|
|
|
private RedirectStore $redirectStore;
|
2023-06-16 18:56:48 +00:00
|
|
|
private LanguageConverterFactory $languageConverterFactory;
|
2022-11-18 16:55:18 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param ServiceOptions $options
|
|
|
|
|
* @param RevisionLookup $revisionLookup
|
|
|
|
|
* @param TitleFormatter $titleFormatter
|
|
|
|
|
* @param PageLookup $pageLookup
|
|
|
|
|
* @param ParsoidOutputStash $parsoidOutputStash
|
|
|
|
|
* @param StatsdDataFactoryInterface $statsDataFactory
|
|
|
|
|
* @param ParsoidOutputAccess $parsoidOutputAccess
|
|
|
|
|
* @param HtmlTransformFactory $htmlTransformFactory
|
2022-11-24 21:54:11 +00:00
|
|
|
* @param IContentHandlerFactory $contentHandlerFactory
|
|
|
|
|
* @param LanguageFactory $languageFactory
|
2023-06-11 16:56:29 +00:00
|
|
|
* @param RedirectStore $redirectStore
|
2023-06-16 18:56:48 +00:00
|
|
|
* @param LanguageConverterFactory $languageConverterFactory
|
2022-11-18 16:55:18 +00:00
|
|
|
*/
|
|
|
|
|
public function __construct(
|
|
|
|
|
ServiceOptions $options,
|
|
|
|
|
RevisionLookup $revisionLookup,
|
|
|
|
|
TitleFormatter $titleFormatter,
|
|
|
|
|
PageLookup $pageLookup,
|
|
|
|
|
ParsoidOutputStash $parsoidOutputStash,
|
|
|
|
|
StatsdDataFactoryInterface $statsDataFactory,
|
|
|
|
|
ParsoidOutputAccess $parsoidOutputAccess,
|
2022-11-24 21:54:11 +00:00
|
|
|
HtmlTransformFactory $htmlTransformFactory,
|
|
|
|
|
IContentHandlerFactory $contentHandlerFactory,
|
2023-06-11 16:56:29 +00:00
|
|
|
LanguageFactory $languageFactory,
|
2023-06-16 18:56:48 +00:00
|
|
|
RedirectStore $redirectStore,
|
|
|
|
|
LanguageConverterFactory $languageConverterFactory
|
2022-11-18 16:55:18 +00:00
|
|
|
) {
|
|
|
|
|
$this->options = $options;
|
|
|
|
|
$this->revisionLookup = $revisionLookup;
|
|
|
|
|
$this->titleFormatter = $titleFormatter;
|
|
|
|
|
$this->pageLookup = $pageLookup;
|
|
|
|
|
$this->parsoidOutputStash = $parsoidOutputStash;
|
|
|
|
|
$this->stats = $statsDataFactory;
|
|
|
|
|
$this->parsoidOutputAccess = $parsoidOutputAccess;
|
|
|
|
|
$this->htmlTransformFactory = $htmlTransformFactory;
|
2022-11-24 21:54:11 +00:00
|
|
|
$this->contentHandlerFactory = $contentHandlerFactory;
|
|
|
|
|
$this->languageFactory = $languageFactory;
|
2023-06-11 16:56:29 +00:00
|
|
|
$this->redirectStore = $redirectStore;
|
2023-06-16 18:56:48 +00:00
|
|
|
$this->languageConverterFactory = $languageConverterFactory;
|
2022-11-18 16:55:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newRevisionContentHelper(): RevisionContentHelper {
|
|
|
|
|
return new RevisionContentHelper(
|
|
|
|
|
$this->options,
|
|
|
|
|
$this->revisionLookup,
|
|
|
|
|
$this->titleFormatter,
|
|
|
|
|
$this->pageLookup
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function newPageContentHelper(): PageContentHelper {
|
|
|
|
|
return new PageContentHelper(
|
|
|
|
|
$this->options,
|
|
|
|
|
$this->revisionLookup,
|
|
|
|
|
$this->titleFormatter,
|
|
|
|
|
$this->pageLookup
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-19 20:09:04 +00:00
|
|
|
/**
|
|
|
|
|
* Should we ignore page id mismatches between page and revision objects
|
|
|
|
|
* in HTML/pagebundle requests? Mismatches arise because of page moves.
|
|
|
|
|
* This is recommended only for handling calls to internal APIs.
|
|
|
|
|
*/
|
|
|
|
|
public function newHtmlOutputRendererHelper(
|
|
|
|
|
bool $lenientRevHandling = false
|
|
|
|
|
): HtmlOutputRendererHelper {
|
2022-11-18 16:55:18 +00:00
|
|
|
return new HtmlOutputRendererHelper(
|
|
|
|
|
$this->parsoidOutputStash,
|
|
|
|
|
$this->stats,
|
|
|
|
|
$this->parsoidOutputAccess,
|
2022-11-24 21:54:11 +00:00
|
|
|
$this->htmlTransformFactory,
|
|
|
|
|
$this->contentHandlerFactory,
|
2023-10-19 20:09:04 +00:00
|
|
|
$this->languageFactory,
|
|
|
|
|
$lenientRevHandling
|
2022-11-18 16:55:18 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-22 12:58:57 +00:00
|
|
|
public function newHtmlMessageOutputHelper(): HtmlMessageOutputHelper {
|
|
|
|
|
return new HtmlMessageOutputHelper();
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 16:55:18 +00:00
|
|
|
public function newHtmlInputTransformHelper( $envOptions = [] ): HtmlInputTransformHelper {
|
|
|
|
|
return new HtmlInputTransformHelper(
|
|
|
|
|
$this->stats,
|
|
|
|
|
$this->htmlTransformFactory,
|
|
|
|
|
$this->parsoidOutputStash,
|
|
|
|
|
$this->parsoidOutputAccess,
|
|
|
|
|
$envOptions
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-11 16:56:29 +00:00
|
|
|
/**
|
|
|
|
|
* @since 1.41
|
|
|
|
|
*/
|
|
|
|
|
public function newPageRedirectHelper(
|
|
|
|
|
ResponseFactory $responseFactory,
|
|
|
|
|
Router $router,
|
|
|
|
|
string $route,
|
|
|
|
|
RequestInterface $request
|
|
|
|
|
): PageRedirectHelper {
|
|
|
|
|
return new PageRedirectHelper(
|
|
|
|
|
$this->redirectStore,
|
|
|
|
|
$this->titleFormatter,
|
|
|
|
|
$responseFactory,
|
|
|
|
|
$router,
|
|
|
|
|
$route,
|
2023-06-16 18:56:48 +00:00
|
|
|
$request,
|
|
|
|
|
$this->languageConverterFactory
|
2023-06-11 16:56:29 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-18 16:55:18 +00:00
|
|
|
}
|