Introduce PageRestHelperFactory
This allows extensions like VisualEditor to safely instantiate REST helper objects. It also reduces the number of services that need to be injected into REST handlers from route definitions. Change-Id: I10af85b2da96568cfffd03867d1cb299645fb371
This commit is contained in:
parent
a845a4764c
commit
2ec1791d40
18 changed files with 261 additions and 203 deletions
|
|
@ -1692,6 +1692,7 @@ $wgAutoloadLocalClasses = [
|
|||
'MediaWiki\\Rest\\Handler\\PageHTMLHandler' => __DIR__ . '/includes/Rest/Handler/PageHTMLHandler.php',
|
||||
'MediaWiki\\Rest\\Handler\\PageHistoryCountHandler' => __DIR__ . '/includes/Rest/Handler/PageHistoryCountHandler.php',
|
||||
'MediaWiki\\Rest\\Handler\\PageHistoryHandler' => __DIR__ . '/includes/Rest/Handler/PageHistoryHandler.php',
|
||||
'MediaWiki\\Rest\\Handler\\PageRestHelperFactory' => __DIR__ . '/includes/Rest/Handler/PageRestHelperFactory.php',
|
||||
'MediaWiki\\Rest\\Handler\\PageSourceHandler' => __DIR__ . '/includes/Rest/Handler/PageSourceHandler.php',
|
||||
'MediaWiki\\Rest\\Handler\\ParsoidFormatHelper' => __DIR__ . '/includes/Rest/Handler/ParsoidFormatHelper.php',
|
||||
'MediaWiki\\Rest\\Handler\\ParsoidHandler' => __DIR__ . '/includes/Rest/Handler/ParsoidHandler.php',
|
||||
|
|
|
|||
|
|
@ -111,6 +111,7 @@ use MediaWiki\Permissions\RestrictionStore;
|
|||
use MediaWiki\Preferences\PreferencesFactory;
|
||||
use MediaWiki\Preferences\SignatureValidatorFactory;
|
||||
use MediaWiki\ResourceLoader\ResourceLoader;
|
||||
use MediaWiki\Rest\Handler\PageRestHelperFactory;
|
||||
use MediaWiki\Revision\ArchivedRevisionLookup;
|
||||
use MediaWiki\Revision\ContributionsLookup;
|
||||
use MediaWiki\Revision\RevisionFactory;
|
||||
|
|
@ -1382,6 +1383,14 @@ class MediaWikiServices extends ServiceContainer {
|
|||
return $this->getService( 'PageProps' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageRestHelperFactory
|
||||
* @since 1.40
|
||||
*/
|
||||
public function getPageRestHelperFactory(): PageRestHelperFactory {
|
||||
return $this->getService( 'PageRestHelperFactory' );
|
||||
}
|
||||
|
||||
/**
|
||||
* @return PageStore
|
||||
* @since 1.36
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@
|
|||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Content;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use InvalidArgumentException;
|
||||
use Language;
|
||||
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
||||
|
|
@ -72,7 +71,7 @@ class HtmlInputTransformHelper {
|
|||
/** @var PageIdentity|null */
|
||||
private $page = null;
|
||||
|
||||
/** @var IBufferingStatsdDataFactory */
|
||||
/** @var StatsdDataFactoryInterface */
|
||||
private $stats;
|
||||
|
||||
/** @var array|null */
|
||||
|
|
@ -382,6 +381,19 @@ class HtmlInputTransformHelper {
|
|||
return $this->transform;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set metrics sink.
|
||||
*
|
||||
* @param StatsdDataFactoryInterface $stats
|
||||
*/
|
||||
public function setMetrics( StatsdDataFactoryInterface $stats ) {
|
||||
$this->stats = $stats;
|
||||
|
||||
if ( $this->transform ) {
|
||||
$this->transform->setMetrics( $stats );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Supply information about the revision and rendering that was the original basis of
|
||||
* the input HTML. This is used to apply selective serialization (selser), if possible.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace MediaWiki\Rest\Handler;
|
|||
use Content;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use Language;
|
||||
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
||||
use LogicException;
|
||||
use MediaWiki\Edit\ParsoidOutputStash;
|
||||
use MediaWiki\Edit\SelserContext;
|
||||
|
|
@ -108,13 +109,13 @@ class HtmlOutputRendererHelper {
|
|||
|
||||
/**
|
||||
* @param ParsoidOutputStash $parsoidOutputStash
|
||||
* @param IBufferingStatsdDataFactory $statsDataFactory
|
||||
* @param StatsdDataFactoryInterface $statsDataFactory
|
||||
* @param ParsoidOutputAccess $parsoidOutputAccess
|
||||
* @param HtmlTransformFactory $htmlTransformFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ParsoidOutputStash $parsoidOutputStash,
|
||||
IBufferingStatsdDataFactory $statsDataFactory,
|
||||
StatsdDataFactoryInterface $statsDataFactory,
|
||||
ParsoidOutputAccess $parsoidOutputAccess,
|
||||
HtmlTransformFactory $htmlTransformFactory
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Config;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\Page\ExistingPageRecord;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
|
|
@ -26,8 +27,16 @@ use Wikimedia\ParamValidator\ParamValidator;
|
|||
class PageContentHelper {
|
||||
private const MAX_AGE_200 = 5;
|
||||
|
||||
/** @var Config */
|
||||
protected $config;
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
public const CONSTRUCTOR_OPTIONS = [
|
||||
MainConfigNames::RightsUrl,
|
||||
MainConfigNames::RightsText,
|
||||
];
|
||||
|
||||
/** @var ServiceOptions */
|
||||
protected $options;
|
||||
|
||||
/** @var RevisionLookup */
|
||||
protected $revisionLookup;
|
||||
|
|
@ -51,18 +60,23 @@ class PageContentHelper {
|
|||
protected $pageRecord = false;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param ServiceOptions|Config $options
|
||||
* @param RevisionLookup $revisionLookup
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param PageLookup $pageLookup
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
$options,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup
|
||||
) {
|
||||
$this->config = $config;
|
||||
if ( $options instanceof Config ) {
|
||||
// Temporary compatibility hack for VisualEditor.
|
||||
$options = new ServiceOptions( self::CONSTRUCTOR_OPTIONS, $options );
|
||||
}
|
||||
|
||||
$this->options = $options;
|
||||
$this->revisionLookup = $revisionLookup;
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->pageLookup = $pageLookup;
|
||||
|
|
@ -228,8 +242,8 @@ class PageContentHelper {
|
|||
->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
|
||||
->getModel(),
|
||||
'license' => [
|
||||
'url' => $this->config->get( MainConfigNames::RightsUrl ),
|
||||
'title' => $this->config->get( MainConfigNames::RightsText )
|
||||
'url' => $this->options->get( MainConfigNames::RightsUrl ),
|
||||
'title' => $this->options->get( MainConfigNames::RightsText )
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,21 +2,14 @@
|
|||
|
||||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Config;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use LogicException;
|
||||
use MediaWiki\Edit\ParsoidOutputStash;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\ExistingPageRecord;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
use MediaWiki\Page\RedirectStore;
|
||||
use MediaWiki\Parser\Parsoid\HtmlTransformFactory;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\Response;
|
||||
use MediaWiki\Rest\SimpleHandler;
|
||||
use MediaWiki\Rest\StringStream;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use TitleFormatter;
|
||||
use Wikimedia\Assert\Assert;
|
||||
|
||||
|
|
@ -42,30 +35,14 @@ class PageHTMLHandler extends SimpleHandler {
|
|||
private $redirectStore;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup,
|
||||
ParsoidOutputStash $parsoidOutputStash,
|
||||
IBufferingStatsdDataFactory $statsDataFactory,
|
||||
ParsoidOutputAccess $parsoidOutputAccess,
|
||||
HtmlTransformFactory $htmlTransformFactory,
|
||||
RedirectStore $redirectStore
|
||||
RedirectStore $redirectStore,
|
||||
PageRestHelperFactory $helperFactory
|
||||
) {
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->redirectStore = $redirectStore;
|
||||
$this->contentHelper = new PageContentHelper(
|
||||
$config,
|
||||
$revisionLookup,
|
||||
$titleFormatter,
|
||||
$pageLookup
|
||||
);
|
||||
$this->htmlHelper = new HtmlOutputRendererHelper(
|
||||
$parsoidOutputStash,
|
||||
$statsDataFactory,
|
||||
$parsoidOutputAccess,
|
||||
$htmlTransformFactory
|
||||
);
|
||||
$this->contentHelper = $helperFactory->newPageContentHelper();
|
||||
$this->htmlHelper = $helperFactory->newHtmlOutputRendererHelper();
|
||||
}
|
||||
|
||||
protected function postValidationSetup() {
|
||||
|
|
|
|||
100
includes/Rest/Handler/PageRestHelperFactory.php
Normal file
100
includes/Rest/Handler/PageRestHelperFactory.php
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Edit\ParsoidOutputStash;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
use MediaWiki\Parser\Parsoid\HtmlTransformFactory;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use TitleFormatter;
|
||||
|
||||
/**
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* @param ServiceOptions $options
|
||||
* @param RevisionLookup $revisionLookup
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param PageLookup $pageLookup
|
||||
* @param ParsoidOutputStash $parsoidOutputStash
|
||||
* @param StatsdDataFactoryInterface $statsDataFactory
|
||||
* @param ParsoidOutputAccess $parsoidOutputAccess
|
||||
* @param HtmlTransformFactory $htmlTransformFactory
|
||||
*/
|
||||
public function __construct(
|
||||
ServiceOptions $options,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup,
|
||||
ParsoidOutputStash $parsoidOutputStash,
|
||||
StatsdDataFactoryInterface $statsDataFactory,
|
||||
ParsoidOutputAccess $parsoidOutputAccess,
|
||||
HtmlTransformFactory $htmlTransformFactory
|
||||
) {
|
||||
$this->options = $options;
|
||||
$this->revisionLookup = $revisionLookup;
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->pageLookup = $pageLookup;
|
||||
$this->parsoidOutputStash = $parsoidOutputStash;
|
||||
$this->stats = $statsDataFactory;
|
||||
$this->parsoidOutputAccess = $parsoidOutputAccess;
|
||||
$this->htmlTransformFactory = $htmlTransformFactory;
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
public function newHtmlOutputRendererHelper(): HtmlOutputRendererHelper {
|
||||
return new HtmlOutputRendererHelper(
|
||||
$this->parsoidOutputStash,
|
||||
$this->stats,
|
||||
$this->parsoidOutputAccess,
|
||||
$this->htmlTransformFactory
|
||||
);
|
||||
}
|
||||
|
||||
public function newHtmlInputTransformHelper( $envOptions = [] ): HtmlInputTransformHelper {
|
||||
return new HtmlInputTransformHelper(
|
||||
$this->stats,
|
||||
$this->htmlTransformFactory,
|
||||
$this->parsoidOutputStash,
|
||||
$this->parsoidOutputAccess,
|
||||
$envOptions
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,14 +2,11 @@
|
|||
|
||||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Config;
|
||||
use LogicException;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
use MediaWiki\Page\PageReference;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\Response;
|
||||
use MediaWiki\Rest\SimpleHandler;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use TitleFormatter;
|
||||
use Wikimedia\Assert\Assert;
|
||||
|
||||
|
|
@ -26,19 +23,9 @@ class PageSourceHandler extends SimpleHandler {
|
|||
/** @var PageContentHelper */
|
||||
private $contentHelper;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup
|
||||
) {
|
||||
public function __construct( TitleFormatter $titleFormatter, PageRestHelperFactory $helperFactory ) {
|
||||
$this->titleFormatter = $titleFormatter;
|
||||
$this->contentHelper = new PageContentHelper(
|
||||
$config,
|
||||
$revisionLookup,
|
||||
$titleFormatter,
|
||||
$pageLookup
|
||||
);
|
||||
$this->contentHelper = $helperFactory->newPageContentHelper();
|
||||
}
|
||||
|
||||
protected function postValidationSetup() {
|
||||
|
|
|
|||
|
|
@ -304,14 +304,16 @@ abstract class ParsoidHandler extends Handler {
|
|||
}
|
||||
}
|
||||
|
||||
$helper = new HtmlInputTransformHelper(
|
||||
$this->siteConfig->metrics() ?: $services->getStatsdDataFactory(),
|
||||
$services->getHtmlTransformFactory(),
|
||||
$services->getParsoidOutputStash(),
|
||||
$services->getParsoidOutputAccess(),
|
||||
$helper = $services->getPageRestHelperFactory()->newHtmlInputTransformHelper(
|
||||
$attribs['envOptions']
|
||||
);
|
||||
|
||||
$metrics = $this->siteConfig->metrics();
|
||||
|
||||
if ( $metrics ) {
|
||||
$helper->setMetrics( $metrics );
|
||||
}
|
||||
|
||||
$parameters = $attribs['opts'] + $attribs;
|
||||
$body = $attribs['opts'];
|
||||
|
||||
|
|
|
|||
|
|
@ -119,8 +119,8 @@ class RevisionContentHelper extends PageContentHelper {
|
|||
'title' => $this->titleFormatter->getPrefixedText( $page ),
|
||||
],
|
||||
'license' => [
|
||||
'url' => $this->config->get( MainConfigNames::RightsUrl ),
|
||||
'title' => $this->config->get( MainConfigNames::RightsText )
|
||||
'url' => $this->options->get( MainConfigNames::RightsUrl ),
|
||||
'title' => $this->options->get( MainConfigNames::RightsText )
|
||||
],
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -2,20 +2,12 @@
|
|||
|
||||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Config;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use LogicException;
|
||||
use MediaWiki\Edit\ParsoidOutputStash;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
use MediaWiki\Parser\Parsoid\HtmlTransformFactory;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\Response;
|
||||
use MediaWiki\Rest\SimpleHandler;
|
||||
use MediaWiki\Rest\StringStream;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use TitleFormatter;
|
||||
use Wikimedia\Assert\Assert;
|
||||
|
||||
/**
|
||||
|
|
@ -34,28 +26,9 @@ class RevisionHTMLHandler extends SimpleHandler {
|
|||
/** @var RevisionContentHelper */
|
||||
private $contentHelper;
|
||||
|
||||
public function __construct(
|
||||
Config $config,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup,
|
||||
ParsoidOutputStash $parsoidOutputStash,
|
||||
IBufferingStatsdDataFactory $statsDataFactory,
|
||||
ParsoidOutputAccess $parsoidOutputAccess,
|
||||
HtmlTransformFactory $htmlTransformFactory
|
||||
) {
|
||||
$this->contentHelper = new RevisionContentHelper(
|
||||
$config,
|
||||
$revisionLookup,
|
||||
$titleFormatter,
|
||||
$pageLookup
|
||||
);
|
||||
$this->htmlHelper = new HtmlOutputRendererHelper(
|
||||
$parsoidOutputStash,
|
||||
$statsDataFactory,
|
||||
$parsoidOutputAccess,
|
||||
$htmlTransformFactory
|
||||
);
|
||||
public function __construct( PageRestHelperFactory $helperFactory ) {
|
||||
$this->contentHelper = $helperFactory->newRevisionContentHelper();
|
||||
$this->htmlHelper = $helperFactory->newHtmlOutputRendererHelper();
|
||||
}
|
||||
|
||||
protected function postValidationSetup() {
|
||||
|
|
|
|||
|
|
@ -2,15 +2,11 @@
|
|||
|
||||
namespace MediaWiki\Rest\Handler;
|
||||
|
||||
use Config;
|
||||
use LogicException;
|
||||
use MediaWiki\Page\PageLookup;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\Response;
|
||||
use MediaWiki\Rest\SimpleHandler;
|
||||
use MediaWiki\Revision\RevisionLookup;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use TitleFormatter;
|
||||
|
||||
/**
|
||||
* A handler that returns page source and metadata for the following routes:
|
||||
|
|
@ -23,23 +19,10 @@ class RevisionSourceHandler extends SimpleHandler {
|
|||
private $contentHelper;
|
||||
|
||||
/**
|
||||
* @param Config $config
|
||||
* @param RevisionLookup $revisionLookup
|
||||
* @param TitleFormatter $titleFormatter
|
||||
* @param PageLookup $pageLookup
|
||||
* @param PageRestHelperFactory $helperFactory
|
||||
*/
|
||||
public function __construct(
|
||||
Config $config,
|
||||
RevisionLookup $revisionLookup,
|
||||
TitleFormatter $titleFormatter,
|
||||
PageLookup $pageLookup
|
||||
) {
|
||||
$this->contentHelper = new RevisionContentHelper(
|
||||
$config,
|
||||
$revisionLookup,
|
||||
$titleFormatter,
|
||||
$pageLookup
|
||||
);
|
||||
public function __construct( PageRestHelperFactory $helperFactory ) {
|
||||
$this->contentHelper = $helperFactory->newRevisionContentHelper();
|
||||
}
|
||||
|
||||
protected function postValidationSetup() {
|
||||
|
|
|
|||
|
|
@ -36,10 +36,7 @@
|
|||
"path": "/v1/revision/{id}",
|
||||
"class": "MediaWiki\\Rest\\Handler\\RevisionSourceHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "source"
|
||||
},
|
||||
|
|
@ -47,14 +44,7 @@
|
|||
"path": "/v1/revision/{id}/html",
|
||||
"class": "MediaWiki\\Rest\\Handler\\RevisionHTMLHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore",
|
||||
"ParsoidOutputStash",
|
||||
"StatsdDataFactory",
|
||||
"ParsoidOutputAccess",
|
||||
"HtmlTransformFactory"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "html"
|
||||
},
|
||||
|
|
@ -62,14 +52,7 @@
|
|||
"path": "/v1/revision/{id}/with_html",
|
||||
"class": "MediaWiki\\Rest\\Handler\\RevisionHTMLHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore",
|
||||
"ParsoidOutputStash",
|
||||
"StatsdDataFactory",
|
||||
"ParsoidOutputAccess",
|
||||
"HtmlTransformFactory"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "with_html"
|
||||
},
|
||||
|
|
@ -77,10 +60,7 @@
|
|||
"path": "/v1/revision/{id}/bare",
|
||||
"class": "MediaWiki\\Rest\\Handler\\RevisionSourceHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "bare"
|
||||
},
|
||||
|
|
@ -129,10 +109,8 @@
|
|||
"path": "/v1/page/{title}",
|
||||
"class": "MediaWiki\\Rest\\Handler\\PageSourceHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "source"
|
||||
},
|
||||
|
|
@ -140,10 +118,8 @@
|
|||
"path": "/v1/page/{title}/bare",
|
||||
"class": "MediaWiki\\Rest\\Handler\\PageSourceHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore"
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "bare"
|
||||
},
|
||||
|
|
@ -151,15 +127,9 @@
|
|||
"path": "/v1/page/{title}/html",
|
||||
"class": "MediaWiki\\Rest\\Handler\\PageHTMLHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore",
|
||||
"ParsoidOutputStash",
|
||||
"StatsdDataFactory",
|
||||
"ParsoidOutputAccess",
|
||||
"HtmlTransformFactory",
|
||||
"RedirectStore"
|
||||
"RedirectStore",
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "html"
|
||||
},
|
||||
|
|
@ -167,15 +137,9 @@
|
|||
"path": "/v1/page/{title}/with_html",
|
||||
"class": "MediaWiki\\Rest\\Handler\\PageHTMLHandler",
|
||||
"services": [
|
||||
"MainConfig",
|
||||
"RevisionLookup",
|
||||
"TitleFormatter",
|
||||
"PageStore",
|
||||
"ParsoidOutputStash",
|
||||
"StatsdDataFactory",
|
||||
"ParsoidOutputAccess",
|
||||
"HtmlTransformFactory",
|
||||
"RedirectStore"
|
||||
"RedirectStore",
|
||||
"PageRestHelperFactory"
|
||||
],
|
||||
"format": "with_html"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -133,6 +133,7 @@ use MediaWiki\Preferences\SignatureValidator;
|
|||
use MediaWiki\Preferences\SignatureValidatorFactory;
|
||||
use MediaWiki\ResourceLoader\MessageBlobStore;
|
||||
use MediaWiki\ResourceLoader\ResourceLoader;
|
||||
use MediaWiki\Rest\Handler\PageRestHelperFactory;
|
||||
use MediaWiki\Revision\ArchivedRevisionLookup;
|
||||
use MediaWiki\Revision\ContributionsLookup;
|
||||
use MediaWiki\Revision\MainSlotRoleHandler;
|
||||
|
|
@ -1204,6 +1205,19 @@ return [
|
|||
);
|
||||
},
|
||||
|
||||
'PageRestHelperFactory' => static function ( MediaWikiServices $services ): PageRestHelperFactory {
|
||||
return new PageRestHelperFactory(
|
||||
new ServiceOptions( PageRestHelperFactory::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ),
|
||||
$services->getRevisionLookup(),
|
||||
$services->getTitleFormatter(),
|
||||
$services->getPageStore(),
|
||||
$services->getParsoidOutputStash(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$services->getParsoidOutputAccess(),
|
||||
$services->getHtmlTransformFactory()
|
||||
);
|
||||
},
|
||||
|
||||
'PageStore' => static function ( MediaWikiServices $services ): PageStore {
|
||||
return $services->getPageStoreFactory()->getPageStore();
|
||||
},
|
||||
|
|
|
|||
|
|
@ -5,14 +5,16 @@ namespace MediaWiki\Tests\Rest\Handler;
|
|||
use DeferredUpdates;
|
||||
use Exception;
|
||||
use HashBagOStuff;
|
||||
use HashConfig;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Json\JsonCodec;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MainConfigSchema;
|
||||
use MediaWiki\Parser\ParserCacheFactory;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Rest\Handler\HtmlOutputRendererHelper;
|
||||
use MediaWiki\Rest\Handler\PageContentHelper;
|
||||
use MediaWiki\Rest\Handler\PageHTMLHandler;
|
||||
use MediaWiki\Rest\Handler\PageRestHelperFactory;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\RequestData;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
|
|
@ -109,16 +111,31 @@ class PageHTMLHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
$services->getParsoidPageConfigFactory()
|
||||
);
|
||||
|
||||
$helperFactory = $this->createNoOpMock(
|
||||
PageRestHelperFactory::class,
|
||||
[ 'newPageContentHelper', 'newHtmlOutputRendererHelper' ]
|
||||
);
|
||||
|
||||
$helperFactory->method( 'newPageContentHelper' )
|
||||
->willReturn( new PageContentHelper(
|
||||
new ServiceOptions( PageContentHelper::CONSTRUCTOR_OPTIONS, $config ),
|
||||
$services->getRevisionLookup(),
|
||||
$services->getTitleFormatter(),
|
||||
$services->getPageStore()
|
||||
) );
|
||||
|
||||
$helperFactory->method( 'newHtmlOutputRendererHelper' )
|
||||
->willReturn( new HtmlOutputRendererHelper(
|
||||
$this->getParsoidOutputStash(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$parsoidOutputAccess,
|
||||
$services->getHtmlTransformFactory()
|
||||
) );
|
||||
|
||||
$handler = new PageHTMLHandler(
|
||||
new HashConfig( $config ),
|
||||
$services->getRevisionLookup(),
|
||||
$services->getTitleFormatter(),
|
||||
$services->getPageStore(),
|
||||
$this->getParsoidOutputStash(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$parsoidOutputAccess,
|
||||
$services->getHtmlTransformFactory(),
|
||||
$services->getRedirectStore()
|
||||
$services->getRedirectStore(),
|
||||
$helperFactory
|
||||
);
|
||||
|
||||
return $handler;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ namespace MediaWiki\Tests\Rest\Handler;
|
|||
|
||||
use BagOStuff;
|
||||
use Exception;
|
||||
use HashConfig;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\Rest\Handler\PageSourceHandler;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\RequestData;
|
||||
|
|
@ -36,6 +36,11 @@ class PageSourceHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
'text',
|
||||
'content'
|
||||
];
|
||||
|
||||
$this->overrideConfigValues( [
|
||||
MainConfigNames::RightsUrl => 'https://example.com/rights',
|
||||
MainConfigNames::RightsText => 'some rights',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,13 +50,8 @@ class PageSourceHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
private function newHandler( BagOStuff $cache = null ): PageSourceHandler {
|
||||
$handler = new PageSourceHandler(
|
||||
new HashConfig( [
|
||||
'RightsUrl' => 'https://example.com/rights',
|
||||
'RightsText' => 'some rights',
|
||||
] ),
|
||||
$this->getServiceContainer()->getRevisionLookup(),
|
||||
$this->getServiceContainer()->getTitleFormatter(),
|
||||
$this->getServiceContainer()->getPageStore()
|
||||
$this->getServiceContainer()->getPageRestHelperFactory()
|
||||
);
|
||||
|
||||
return $handler;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,15 @@ namespace MediaWiki\Tests\Rest\Handler;
|
|||
use DeferredUpdates;
|
||||
use Exception;
|
||||
use HashBagOStuff;
|
||||
use HashConfig;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
use MediaWiki\Json\JsonCodec;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MainConfigSchema;
|
||||
use MediaWiki\Parser\ParserCacheFactory;
|
||||
use MediaWiki\Parser\Parsoid\ParsoidOutputAccess;
|
||||
use MediaWiki\Rest\Handler\HtmlOutputRendererHelper;
|
||||
use MediaWiki\Rest\Handler\PageRestHelperFactory;
|
||||
use MediaWiki\Rest\Handler\RevisionContentHelper;
|
||||
use MediaWiki\Rest\Handler\RevisionHTMLHandler;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\RequestData;
|
||||
|
|
@ -19,7 +21,6 @@ use MediaWiki\Revision\RevisionRecord;
|
|||
use MediaWikiIntegrationTestCase;
|
||||
use MWTimestamp;
|
||||
use NullStatsdDataFactory;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
use WANObjectCache;
|
||||
|
|
@ -27,7 +28,6 @@ use Wikimedia\Message\MessageValue;
|
|||
use Wikimedia\Parsoid\Core\ClientError;
|
||||
use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
|
||||
use Wikimedia\Parsoid\Parsoid;
|
||||
use Wikimedia\UUID\GlobalIdGenerator;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Rest\Handler\RevisionHTMLHandler
|
||||
|
|
@ -69,14 +69,6 @@ class RevisionHTMLHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
* @return RevisionHTMLHandler
|
||||
*/
|
||||
private function newHandler( ?Parsoid $parsoid = null ): RevisionHTMLHandler {
|
||||
/** @var GlobalIdGenerator|MockObject $idGenerator */
|
||||
$idGenerator = $this->createNoOpMock( GlobalIdGenerator::class, [ 'newUUIDv1' ] );
|
||||
$idGenerator->method( 'newUUIDv1' )->willReturnCallback(
|
||||
static function () {
|
||||
return 'uuid' . ++self::$uuidCounter;
|
||||
}
|
||||
);
|
||||
|
||||
$parserCacheFactoryOptions = new ServiceOptions( ParserCacheFactory::CONSTRUCTOR_OPTIONS, [
|
||||
'CacheEpoch' => '20200202112233',
|
||||
'OldRevisionParserCacheExpireTime' => 60 * 60,
|
||||
|
|
@ -111,25 +103,39 @@ class RevisionHTMLHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
$parserCacheFactory,
|
||||
$services->getPageStore(),
|
||||
$services->getRevisionLookup(),
|
||||
$idGenerator,
|
||||
$services->getGlobalIdGenerator(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$parsoid ?? new Parsoid(
|
||||
$services->get( 'ParsoidSiteConfig' ),
|
||||
$services->get( 'ParsoidDataAccess' )
|
||||
),
|
||||
$services->get( 'ParsoidSiteConfig' ),
|
||||
$services->get( 'ParsoidDataAccess' )
|
||||
),
|
||||
$services->getParsoidSiteConfig(),
|
||||
$services->getParsoidPageConfigFactory()
|
||||
);
|
||||
|
||||
$helperFactory = $this->createNoOpMock(
|
||||
PageRestHelperFactory::class,
|
||||
[ 'newRevisionContentHelper', 'newHtmlOutputRendererHelper' ]
|
||||
);
|
||||
|
||||
$helperFactory->method( 'newRevisionContentHelper' )
|
||||
->willReturn( new RevisionContentHelper(
|
||||
new ServiceOptions( RevisionContentHelper::CONSTRUCTOR_OPTIONS, $config ),
|
||||
$services->getRevisionLookup(),
|
||||
$services->getTitleFormatter(),
|
||||
$services->getPageStore()
|
||||
) );
|
||||
|
||||
$helperFactory->method( 'newHtmlOutputRendererHelper' )
|
||||
->willReturn( new HtmlOutputRendererHelper(
|
||||
$this->getParsoidOutputStash(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$parsoidOutputAccess,
|
||||
$services->getHtmlTransformFactory()
|
||||
) );
|
||||
|
||||
$handler = new RevisionHTMLHandler(
|
||||
new HashConfig( $config ),
|
||||
$services->getRevisionLookup(),
|
||||
$services->getTitleFormatter(),
|
||||
$services->getPageStore(),
|
||||
$this->getParsoidOutputStash(),
|
||||
$services->getStatsdDataFactory(),
|
||||
$parsoidOutputAccess,
|
||||
$services->getHtmlTransformFactory()
|
||||
$helperFactory
|
||||
);
|
||||
|
||||
return $handler;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ namespace MediaWiki\Tests\Rest\Handler;
|
|||
|
||||
use BagOStuff;
|
||||
use Exception;
|
||||
use HashConfig;
|
||||
use MediaWiki\Rest\Handler\RevisionSourceHandler;
|
||||
use MediaWiki\Rest\LocalizedHttpException;
|
||||
use MediaWiki\Rest\RequestData;
|
||||
|
|
@ -36,6 +35,11 @@ class RevisionSourceHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
'text',
|
||||
'content'
|
||||
];
|
||||
|
||||
$this->overrideConfigValues( [
|
||||
'RightsUrl' => 'https://example.com/rights',
|
||||
'RightsText' => 'some rights',
|
||||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -45,13 +49,7 @@ class RevisionSourceHandlerTest extends MediaWikiIntegrationTestCase {
|
|||
*/
|
||||
private function newHandler( BagOStuff $cache = null ): RevisionSourceHandler {
|
||||
$handler = new RevisionSourceHandler(
|
||||
new HashConfig( [
|
||||
'RightsUrl' => 'https://example.com/rights',
|
||||
'RightsText' => 'some rights',
|
||||
] ),
|
||||
$this->getServiceContainer()->getRevisionLookup(),
|
||||
$this->getServiceContainer()->getTitleFormatter(),
|
||||
$this->getServiceContainer()->getPageStore()
|
||||
$this->getServiceContainer()->getPageRestHelperFactory()
|
||||
);
|
||||
|
||||
return $handler;
|
||||
|
|
|
|||
Loading…
Reference in a new issue