Add stash option to /page/html & /revision/html endpoints. When this option is set, the PageBundle returned by Parsoid is stashed and an etag is returned that can later be used to make use of the stashed PageBundle. The stash is for now backed by the BagOStuff returned by ObjectCache::getLocalClusterInstance(). This patch adds additional data to the ParserOutput stored in ParserCache. Old entries lacking that data will be ignored. Bug: T267990 Co-Authored-by: Nikki <nnikkhoui@wikimedia.org> Change-Id: Id35f1423a69e3ff63e4f9883b3f7e3f9521d81d5
67 lines
1.8 KiB
PHP
67 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace MediaWiki\Tests\Rest\Handler;
|
|
|
|
use HashBagOStuff;
|
|
use MediaWiki\Edit\ParsoidOutputStash;
|
|
use MediaWiki\Edit\SimpleParsoidOutputStash;
|
|
use MediaWiki\Parser\Parsoid\ParsoidRenderID;
|
|
use MediaWiki\Rest\RequestData;
|
|
|
|
/**
|
|
* This trait is used in PageHTMLHandlerTest.php & RevisionHTMLHandlerTest.php
|
|
* to construct requests and perform stashing for the Parsoid Output stash feature.
|
|
*/
|
|
trait HTMLHandlerTestTrait {
|
|
|
|
private $parsoidOutputStash = null;
|
|
|
|
private function getParsoidOutputStash(): ParsoidOutputStash {
|
|
if ( !$this->parsoidOutputStash ) {
|
|
$this->parsoidOutputStash = new SimpleParsoidOutputStash( new HashBagOStuff() );
|
|
}
|
|
return $this->parsoidOutputStash;
|
|
}
|
|
|
|
/**
|
|
* @param string $page
|
|
* @param array $queryParams
|
|
*
|
|
* @return array
|
|
*/
|
|
private function executePageHTMLRequest( string $page, array $queryParams = [] ): array {
|
|
$handler = $this->newHandler();
|
|
$request = new RequestData( [
|
|
'pathParams' => [ 'title' => $page ],
|
|
'queryParams' => $queryParams,
|
|
] );
|
|
$result = $this->executeHandler( $handler,
|
|
$request,
|
|
[ 'format' => 'html' ] );
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
}
|
|
|
|
/**
|
|
* @param int $revId
|
|
* @param array $queryParams
|
|
*
|
|
* @return array
|
|
*/
|
|
private function executeRevisionHTMLRequest( int $revId, array $queryParams = [] ): array {
|
|
$handler = $this->newHandler();
|
|
$request = new RequestData( [
|
|
'pathParams' => [ 'id' => $revId ],
|
|
'queryParams' => $queryParams,
|
|
] );
|
|
$result = $this->executeHandler( $handler,
|
|
$request,
|
|
[ 'format' => 'html' ] );
|
|
$etag = $result->getHeaderLine( 'ETag' );
|
|
$stashKey = ParsoidRenderID::newFromETag( $etag );
|
|
|
|
return [ $result->getBody()->getContents(), $etag, $stashKey ];
|
|
}
|
|
}
|