35use Wikimedia\Parsoid\Core\ClientError;
36use Wikimedia\Parsoid\Core\ResourceLimitExceededException;
76 $this->parsoidParserFactory = $parsoidParserFactory;
77 $this->parserOutputAccess = $parserOutputAccess;
78 $this->pageLookup = $pageLookup;
79 $this->revisionLookup = $revisionLookup;
80 $this->siteConfig = $siteConfig;
81 $this->contentHandlerFactory = $contentHandlerFactory;
99 bool $lenientRevHandling =
false
102 [ $page, $revision, $uncacheable ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
105 if ( $uncacheable ) {
106 $options |= ParserOutputAccess::OPT_NO_UPDATE_CACHE;
109 $this->adjustParserOptions( $revision, $parserOpts );
110 $status = $this->parserOutputAccess->getParserOutput(
111 $page, $parserOpts, $revision, $options
113 }
catch ( ClientError $e ) {
114 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
115 }
catch ( ResourceLimitExceededException $e ) {
116 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
134 bool $lenientRevHandling =
false
137 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
139 $this->adjustParserOptions( $revision, $parserOpts );
140 return $this->parserOutputAccess->getCachedParserOutput( $page, $parserOpts, $revision );
159 bool $lenientRevHandling =
false
165 [ $page, $revision, $ignored ] = $this->resolveRevision( $page, $revision, $lenientRevHandling );
169 $revId = $revision->getId();
170 if ( $revId !== 0 && $revId !==
null ) {
171 return Status::newFatal(
'parsoid-revision-access',
172 "parseUncacheable should not be called for a real revision" );
178 $parser = $this->parsoidParserFactory->create();
179 $parserOutput = $this->parsoidParserFactory->create()->parseFakeRevision(
180 $revision, $page, $parserOpts );
181 $parserOutput->updateCacheExpiry( 0 );
182 $status = Status::newGood( $parserOutput );
183 }
catch ( RevisionAccessException $e ) {
184 return Status::newFatal(
'parsoid-revision-access', $e->getMessage() );
185 }
catch ( ClientError $e ) {
186 $status = Status::newFatal(
'parsoid-client-error', $e->getMessage() );
187 }
catch ( ResourceLimitExceededException $e ) {
188 $status = Status::newFatal(
'parsoid-resource-limit-exceeded', $e->getMessage() );
200 private function resolveRevision( PageIdentity $page, $revision,
bool $lenientRevHandling =
false ): array {
201 $uncacheable = false;
202 if ( !$page instanceof PageRecord ) {
204 $page = $this->pageLookup->getPageByReference( $page );
206 throw new RevisionAccessException(
207 'Page {name} not found',
213 if ( $revision ===
null ) {
214 $revision = $page->getLatest();
217 if ( is_int( $revision ) ) {
219 $revision = $this->revisionLookup->getRevisionById( $revId );
222 throw new RevisionAccessException(
223 'Revision {revId} not found',
224 [
'revId' => $revId ]
229 if ( $page->getId() !== $revision->getPageId() ) {
230 if ( $lenientRevHandling ) {
231 $page = $this->pageLookup->getPageById( $revision->getPageId() );
234 throw new \RuntimeException(
235 "Unexpected NULL page for pageid " . $revision->getPageId() .
236 " from revision " . $revision->getId()
242 throw new RevisionAccessException(
243 'Revision {revId} does not belong to page {name}',
244 [
'name' => $page->getDBkey(),
'revId' => $revision->getId() ]
249 return [ $page, $revision, $uncacheable ];
252 private function adjustParserOptions( RevisionRecord $revision,
ParserOptions $parserOpts ): void {
253 $mainSlot = $revision->getSlot( SlotRecord::MAIN );
254 $contentModel = $mainSlot->getModel();
255 if ( $this->siteConfig->supportsContentModel( $contentModel ) ) {
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
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.