MediaWiki master
MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper Class Reference

Helper for getting output of a given wikitext page rendered by parsoid. More...

Inherits MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Collaboration diagram for MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper:

Public Member Functions

 __construct (ParsoidOutputStash $parsoidOutputStash, StatsdDataFactoryInterface $statsDataFactory, ParsoidOutputAccess $parsoidOutputAccess, HtmlTransformFactory $htmlTransformFactory, IContentHandlerFactory $contentHandlerFactory, LanguageFactory $languageFactory, bool $lenientRevHandling=false)
 
 getETag (string $suffix='')
 Returns an ETag uniquely identifying the HTML output.
See also
Handler::getETag()
Parameters
string$suffixA suffix to attach to the etag. Must consist of characters that are legal in ETags.
Returns
string|null We return null when there is no etag.

 
 getFlavor ()
 Returns the flavor of HTML that will be generated.
 
 getHtml ()
 Fetch the HTML for rendering of a given page.If the rendering is available in parsoid parser cache, return that. Otherwise, perform a parse and return the result while caching it in the parser cache.NOTE: Caching can be explicitly disabled or a force parse action can be issued. Stashing and rate limiting on stashing also applies here if specified.
Returns
ParserOutput a tuple with html and content-type
Exceptions
LocalizedHttpException
ClientError

 
 getHtmlOutputContentLanguage ()
 The content language of the HTML output after parsing.
 
 getLastModified ()
 Returns the time at which the HTML was rendered.
See also
Handler::getLastModified()
Returns
string|null

 
 getPageBundle ()
 Returns the rendered HTML as a PageBundle object.
 
 getParamSettings ()
 Gets the request parameters of this request.
See also
Handler::getParamSettings()
Returns
array

 
 getRevisionId ()
 Returns the ID of the revision that is being rendered.
 
 init (PageIdentity $page, array $parameters, Authority $authority, $revision=null)
 Initializes the helper with the given parameters like the page we're dealing with, parameters gotten from the request inputs, and the revision if any is available.
 
 putHeaders (ResponseInterface $response, bool $forHtml=true)
 Set the HTTP headers based on the response generated.
Parameters
ResponseInterface$response
bool$forHtmlWhether the response will be HTML (rather than JSON)
Returns
void

 
 setContent (Content $content)
 Set the content to render.
 
 setContentSource (string $source, string $model)
 Set the content to render.
 
 setFlavor (string $flavor)
 Sets the given flavor to use for Wikitext -> HTML transformations.
 
 setOutputProfileVersion ( $version)
 Set the desired Parsoid profile version for the output.
 
 setPageLanguage ( $pageLanguage)
 This is equivalent of 'pageLanguageOverride' in PageConfigFactory For example, when clients call the REST API with the 'content-language' header to effect language variant conversion.
 
 setRevision ( $revisionOrId)
 Set the revision to render.
 
 setStashingEnabled (bool $stash)
 Determine whether stashing should be applied.
 
 setUseParserCache (bool $read, bool $write)
 Controls how the parser cache is used.
 
 setVariantConversionLanguage ( $targetLanguage, $sourceLanguage=null)
 Set the language to be used for variant conversion.If $targetLanguage is a string, it may be a list of language ranges as specified by RFC 9110 for use in the Accept-Language header. Implementations must be able to process this format, and may use the information provided to choose a supported target language that is desirable to the client.
Parameters
Bcp47Code | string$targetLanguage
Bcp47Code | string | null$sourceLanguage

 

Detailed Description

Helper for getting output of a given wikitext page rendered by parsoid.

Since
1.36
Stability: unstable
Pending consolidation of the Parsoid extension with core code.

Definition at line 74 of file HtmlOutputRendererHelper.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::__construct ( ParsoidOutputStash $parsoidOutputStash,
StatsdDataFactoryInterface $statsDataFactory,
ParsoidOutputAccess $parsoidOutputAccess,
HtmlTransformFactory $htmlTransformFactory,
IContentHandlerFactory $contentHandlerFactory,
LanguageFactory $languageFactory,
bool $lenientRevHandling = false )
Parameters
ParsoidOutputStash$parsoidOutputStash
StatsdDataFactoryInterface$statsDataFactory
ParsoidOutputAccess$parsoidOutputAccess
HtmlTransformFactory$htmlTransformFactory
IContentHandlerFactory$contentHandlerFactory
LanguageFactory$languageFactory
bool$lenientRevHandlingShould we ignore mismatches $page and the page that $revision belongs to? Usually happens because of page moves. This should be set to true only for internal API calls.

Definition at line 174 of file HtmlOutputRendererHelper.php.

Member Function Documentation

◆ getETag()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getETag ( string $suffix = '')

Returns an ETag uniquely identifying the HTML output.

See also
Handler::getETag()
Parameters
string$suffixA suffix to attach to the etag. Must consist of characters that are legal in ETags.
Returns
string|null We return null when there is no etag.

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 511 of file HtmlOutputRendererHelper.php.

◆ getFlavor()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getFlavor ( )

Returns the flavor of HTML that will be generated.

See also
setFlavor()
Returns
string

Definition at line 224 of file HtmlOutputRendererHelper.php.

◆ getHtml()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getHtml ( )

Fetch the HTML for rendering of a given page.If the rendering is available in parsoid parser cache, return that. Otherwise, perform a parse and return the result while caching it in the parser cache.NOTE: Caching can be explicitly disabled or a force parse action can be issued. Stashing and rate limiting on stashing also applies here if specified.

Returns
ParserOutput a tuple with html and content-type
Exceptions
LocalizedHttpException
ClientError

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 446 of file HtmlOutputRendererHelper.php.

◆ getHtmlOutputContentLanguage()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getHtmlOutputContentLanguage ( )

The content language of the HTML output after parsing.

Returns
Bcp47Code The language, as a BCP-47 code

Definition at line 622 of file HtmlOutputRendererHelper.php.

◆ getLastModified()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getLastModified ( )

Returns the time at which the HTML was rendered.

See also
Handler::getLastModified()
Returns
string|null

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 532 of file HtmlOutputRendererHelper.php.

◆ getPageBundle()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getPageBundle ( )

Returns the rendered HTML as a PageBundle object.

Returns
PageBundle

Definition at line 680 of file HtmlOutputRendererHelper.php.

◆ getParamSettings()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getParamSettings ( )

Gets the request parameters of this request.

See also
Handler::getParamSettings()
Returns
array

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 539 of file HtmlOutputRendererHelper.php.

◆ getRevisionId()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::getRevisionId ( )

Returns the ID of the revision that is being rendered.

This will return 0 if no revision has been specified, so the current revision will be rendered.

This wil return null if RevisionRecord has been set but that RevisionRecord does not have a revision ID, e.g. when rendering a preview.

Returns
?int

Definition at line 710 of file HtmlOutputRendererHelper.php.

◆ init()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::init ( PageIdentity $page,
array $parameters,
Authority $authority,
$revision = null )

Initializes the helper with the given parameters like the page we're dealing with, parameters gotten from the request inputs, and the revision if any is available.

Parameters
PageIdentity$page
array$parameters
Authority$authority
RevisionRecord | int | null$revision

Definition at line 384 of file HtmlOutputRendererHelper.php.

◆ putHeaders()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::putHeaders ( ResponseInterface $response,
bool $forHtml = true )

Set the HTTP headers based on the response generated.

Parameters
ResponseInterface$response
bool$forHtmlWhether the response will be HTML (rather than JSON)
Returns
void

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 649 of file HtmlOutputRendererHelper.php.

References MediaWiki\Rest\ResponseInterface\setHeader().

◆ setContent()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setContent ( Content $content)

Set the content to render.

Useful when rendering for previews or when switching the editor from source mode to visual mode.

This will create a fake revision for rendering, the revision ID will be 0.

See also
setRevision
setContentSource
Parameters
Content$content

Definition at line 329 of file HtmlOutputRendererHelper.php.

◆ setContentSource()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setContentSource ( string $source,
string $model )

Set the content to render.

Useful when rendering for previews or when switching the editor from source mode to visual mode.

This will create a fake revision for rendering, the revision ID will be 0.

Parameters
string$sourceThe source data, e.g. wikitext
string$modelThe content model indicating how to interpret $source, e.g. CONTENT_MODEL_WIKITEXT
See also
setRevision
setContent

Definition at line 349 of file HtmlOutputRendererHelper.php.

◆ setFlavor()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setFlavor ( string $flavor)

Sets the given flavor to use for Wikitext -> HTML transformations.

Flavors may influence parser options, parsoid options, and DOM transformations. They will be reflected by the ETag returned by getETag().

Note
This method should not be called if stashing mode is enabled.
See also
setStashingEnabled
getFlavor()
Parameters
string$flavor
Returns
void

Definition at line 206 of file HtmlOutputRendererHelper.php.

◆ setOutputProfileVersion()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setOutputProfileVersion ( $version)

Set the desired Parsoid profile version for the output.

The actual output version is selected to be compatible with the one given here, per the rules of semantic versioning.

Note
Will disable caching if the effective output version is different from the default.
Parameters
string$version
Exceptions
HttpExceptionIf the given version is not supported (status 406)

Definition at line 239 of file HtmlOutputRendererHelper.php.

◆ setPageLanguage()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setPageLanguage ( $pageLanguage)

This is equivalent of 'pageLanguageOverride' in PageConfigFactory For example, when clients call the REST API with the 'content-language' header to effect language variant conversion.

Parameters
Bcp47Code | string$pageLanguagethe page language, as a Bcp47Code or a BCP-47 string.

Definition at line 367 of file HtmlOutputRendererHelper.php.

◆ setRevision()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setRevision ( $revisionOrId)

Set the revision to render.

This can take a fake RevisionRecord when rendering for previews or when switching the editor from source mode to visual mode.

In that case, $revisionOrId->getId() must return 0 to indicate that the ParserCache should be bypassed. Stashing may still apply.

Parameters
RevisionRecord | int$revisionOrId

Definition at line 300 of file HtmlOutputRendererHelper.php.

◆ setStashingEnabled()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setStashingEnabled ( bool $stash)

Determine whether stashing should be applied.

Parameters
bool$stash
Returns
void

Definition at line 279 of file HtmlOutputRendererHelper.php.

◆ setUseParserCache()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setUseParserCache ( bool $read,
bool $write )

Controls how the parser cache is used.

Parameters
bool$readWhether we should look for cached output before parsing
bool$writeWhether we should cache output after parsing

Definition at line 266 of file HtmlOutputRendererHelper.php.

◆ setVariantConversionLanguage()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setVariantConversionLanguage ( $targetLanguage,
$sourceLanguage = null )

Set the language to be used for variant conversion.If $targetLanguage is a string, it may be a list of language ranges as specified by RFC 9110 for use in the Accept-Language header. Implementations must be able to process this format, and may use the information provided to choose a supported target language that is desirable to the client.

Parameters
Bcp47Code | string$targetLanguage
Bcp47Code | string | null$sourceLanguage

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 408 of file HtmlOutputRendererHelper.php.


The documentation for this class was generated from the following file: