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

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

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

Public Member Functions

 __construct (ParsoidOutputStash $parsoidOutputStash, StatsdDataFactoryInterface $statsDataFactory, ParsoidOutputAccess $parsoidOutputAccess, HtmlTransformFactory $htmlTransformFactory, IContentHandlerFactory $contentHandlerFactory, LanguageFactory $languageFactory)
 
 getETag (string $suffix='')
 Returns an ETag uniquely identifying the HTML output.
See also
Handler::getETag()
Parameters
string$suffixA suffix to attach to the etag.
Returns
string|null We return null when there is no etag.
More...
 
 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
More...
 
 getHtmlOutputContentLanguage ()
 The content language of the HTML output after parsing. More...
 
 getLastModified ()
 Returns the time at which the HTML was rendered.
See also
Handler::getLastModified()
Returns
string|null
More...
 
 getPageBundle ()
 Returns the rendered HTML as a PageBundle object. More...
 
 getParamSettings ()
 Gets the request parameters of this request.
See also
Handler::getParamSettings()
Returns
array
More...
 
 getRevisionId ()
 Returns the ID of the revision that is being rendered. More...
 
 init (PageIdentity $page, array $parameters, User $user, $revision=null, ?Bcp47Code $pageLanguage=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. More...
 
 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
More...
 
 setContent (Content $content)
 Set the content to render. More...
 
 setContentSource (string $source, string $model)
 Set the content to render. More...
 
 setFlavor (string $flavor)
 Sets the given flavor to use for Wikitext -> HTML transformations. More...
 
 setOffsetType ( $offsetType)
 Set the desired offset type for data-parsoid attributes. More...
 
 setOutputProfileVersion ( $version)
 Set the desired Parsoid profile version for the output. More...
 
 setPageLanguage ( $pageLanguage)
 
 setRevision ( $revisionOrId)
 Set the revision to render. More...
 
 setStashingEnabled (bool $stash)
 Determine whether stashing should be applied. More...
 
 setUseParserCache (bool $read, bool $write)
 Controls how the parser cache is used. More...
 
 setVariantConversionLanguage ( $targetLanguage, $sourceLanguage=null)
 Set the language to be used for variant conversion.
Parameters
Bcp47Code | string$targetLanguage
Bcp47Code | string | null$sourceLanguage
More...
 

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 69 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 
)
Parameters
ParsoidOutputStash$parsoidOutputStash
StatsdDataFactoryInterface$statsDataFactory
ParsoidOutputAccess$parsoidOutputAccess
HtmlTransformFactory$htmlTransformFactory
IContentHandlerFactory$contentHandlerFactory
LanguageFactory$languageFactory

Definition at line 159 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.
Returns
string|null We return null when there is no etag.

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 474 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 406 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 574 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 495 of file HtmlOutputRendererHelper.php.

◆ getPageBundle()

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

Returns the rendered HTML as a PageBundle object.

Returns
PageBundle

Definition at line 626 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 502 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 656 of file HtmlOutputRendererHelper.php.

◆ init()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::init ( PageIdentity  $page,
array  $parameters,
User  $user,
  $revision = null,
?Bcp47Code  $pageLanguage = 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
User$user
RevisionRecord | int | null$revision
?Bcp47Code$pageLanguage

Definition at line 356 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 595 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 304 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 324 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().

Parameters
string$flavor
Returns
void

Definition at line 185 of file HtmlOutputRendererHelper.php.

◆ setOffsetType()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setOffsetType (   $offsetType)

Set the desired offset type for data-parsoid attributes.

Note
Will disable caching if the given offset type is different from the default.
Parameters
string$offsetTypeOne of the offset types accepted by Parsoid::wikitext2html.

Definition at line 226 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 204 of file HtmlOutputRendererHelper.php.

◆ setPageLanguage()

MediaWiki\Rest\Handler\Helper\HtmlOutputRendererHelper::setPageLanguage (   $pageLanguage)
Parameters
Bcp47Code | string$pageLanguagethe page language, as a Bcp47Code or a BCP-47 string.

Definition at line 338 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 275 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 254 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 241 of file HtmlOutputRendererHelper.php.

◆ setVariantConversionLanguage()

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

Set the language to be used for variant conversion.

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

Implements MediaWiki\Rest\Handler\Helper\HtmlOutputHelper.

Definition at line 385 of file HtmlOutputRendererHelper.php.

References LanguageCode\normalizeNonstandardCodeAndWarn().


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