35use Wikimedia\Parsoid\Config\SiteConfig;
36use Wikimedia\Parsoid\Core\ClientError;
37use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
57 private SiteConfig $siteConfig;
73 SiteConfig $siteConfig,
76 $this->parsoidParserFactory = $parsoidParserFactory;
77 $this->parserOutputAccess = $parserOutputAccess;
78 $this->pageLookup = $pageLookup;
79 $this->revisionLookup = $revisionLookup;
80 $this->siteConfig = $siteConfig;
81 $this->contentHandlerFactory = $contentHandlerFactory;
98 $handler = $this->contentHandlerFactory->getContentHandler( $model );
107 return $this->siteConfig->getContentModelHandler( $model ) !==
null;
124 bool $lenientRevHandling =
false
126 [ $page, $revision, $uncacheable ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
129 if ( $uncacheable ) {
130 $options |= ParserOutputAccess::OPT_NO_UPDATE_CACHE;
133 $this->adjustParserOptions( $revision, $parserOpts );
134 $status = $this->parserOutputAccess->getParserOutput(
135 $page, $parserOpts, $revision, $options
137 }
catch ( ClientError $e ) {
138 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
139 }
catch ( ResourceLimitExceededException $e ) {
140 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
157 bool $lenientRevHandling =
false
159 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
161 $this->adjustParserOptions( $revision, $parserOpts );
162 return $this->parserOutputAccess->getCachedParserOutput( $page, $parserOpts, $revision );
180 bool $lenientRevHandling =
false
185 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
189 $revId = $revision->getId();
190 if ( $revId !== 0 && $revId !==
null ) {
191 return Status::newFatal(
'parsoid-revision-access',
192 "parseUncacheable should not be called for a real revision" );
198 $parser = $this->parsoidParserFactory->create();
199 $parserOutput = $this->parsoidParserFactory->create()->parseFakeRevision(
200 $revision, $page, $parserOpts );
201 $parserOutput->updateCacheExpiry( 0 );
202 $status = Status::newGood( $parserOutput );
203 }
catch ( RevisionAccessException $e ) {
204 return Status::newFatal(
'parsoid-revision-access', $e->getMessage() );
205 }
catch ( ClientError $e ) {
206 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
207 }
catch ( ResourceLimitExceededException $e ) {
208 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
220 private function resolveRevision( PageIdentity $page, $revision,
bool $lenientRevHandling =
false ): array {
221 $uncacheable = false;
222 if ( !$page instanceof PageRecord ) {
224 $page = $this->pageLookup->getPageByReference( $page );
226 throw new RevisionAccessException(
227 'Page {name} not found',
233 if ( $revision ===
null ) {
234 $revision = $page->getLatest();
237 if ( is_int( $revision ) ) {
239 $revision = $this->revisionLookup->getRevisionById( $revId );
242 throw new RevisionAccessException(
243 'Revision {revId} not found',
244 [
'revId' => $revId ]
249 if ( $page->getId() !== $revision->getPageId() ) {
250 if ( $lenientRevHandling ) {
251 $page = $this->pageLookup->getPageById( $revision->getPageId() );
254 throw new \RuntimeException(
255 "Unexpected NULL page for pageid " . $revision->getPageId() .
256 " from revision " . $revision->getId()
262 throw new RevisionAccessException(
263 'Revision {revId} does not belong to page {name}',
264 [
'name' => $page->getDBkey(),
'revId' => $revision->getId() ]
269 return [ $page, $revision, $uncacheable ];
272 private function adjustParserOptions( RevisionRecord $revision,
ParserOptions $parserOpts ): void {
273 $mainSlot = $revision->getSlot( SlotRecord::MAIN );
274 $contentModel = $mainSlot->getModel();
275 if ( $this->supportsContentModel( $contentModel ) ) {
const CONTENT_MODEL_WIKITEXT
const CONTENT_FORMAT_WIKITEXT
Wikitext.
if(!defined('MW_SETUP_CALLBACK'))
Exception thrown when an unregistered content model is requested.
Service for getting rendered output of a given page.
Set options of the Parser.
setUseParsoid()
Request Parsoid-format HTML output.
Interface for objects (potentially) representing an editable wiki page.
Service for looking up information about wiki pages.