MediaWiki  master
MediaWiki\Rest\Handler\ParsoidFormatHelper Class Reference

Format-related REST API helper. More...

Static Public Member Functions

static getContentType (string $format, ?string $contentVersion=null)
 Get the content type appropriate for a given response format. More...
 
static parseContentTypeHeader (string $contentTypeHeader, ?string &$format=null)
 Parse a Content-Type header and return the format type and version. More...
 
static setContentType (ResponseInterface $response, string $format, ?string $contentVersion=null)
 Set the Content-Type header appropriate for a given response format. More...
 

Public Attributes

const ERROR_ENCODING
 
const FORMAT_HTML = 'html'
 
const FORMAT_LINT = 'lint'
 
const FORMAT_PAGEBUNDLE = 'pagebundle'
 
const FORMAT_WIKITEXT = 'wikitext'
 
const VALID_PAGE
 
const VALID_TRANSFORM
 

Detailed Description

Format-related REST API helper.

Probably should be turned into an object encapsulating format and content version at some point.

Definition at line 29 of file ParsoidFormatHelper.php.

Member Function Documentation

◆ getContentType()

static MediaWiki\Rest\Handler\ParsoidFormatHelper::getContentType ( string  $format,
?string  $contentVersion = null 
)
static

Get the content type appropriate for a given response format.

Parameters
string$formatOne of the FORMAT_* constants
?string$contentVersion Output version, only for HTML and pagebundle formats. See Env::getcontentVersion().
Returns
string

Definition at line 60 of file ParsoidFormatHelper.php.

◆ parseContentTypeHeader()

static MediaWiki\Rest\Handler\ParsoidFormatHelper::parseContentTypeHeader ( string  $contentTypeHeader,
?string &  $format = null 
)
static

Parse a Content-Type header and return the format type and version.

Mostly the inverse of getContentType() but also accounts for legacy formats.

Parameters
string$contentTypeHeaderThe value of the Content-Type header.
?string&$format Format type will be set here (as a FORMAT_* constant).
Returns
?string Format version, or null if it couldn't be identified.
See also
Env::getInputContentVersion()

Definition at line 110 of file ParsoidFormatHelper.php.

◆ setContentType()

static MediaWiki\Rest\Handler\ParsoidFormatHelper::setContentType ( ResponseInterface  $response,
string  $format,
?string  $contentVersion = null 
)
static

Set the Content-Type header appropriate for a given response format.

Parameters
ResponseInterface$response
string$formatOne of the FORMAT_* constants
?string$contentVersion Output version, only for HTML and pagebundle formats. See Env::getcontentVersion().

Definition at line 95 of file ParsoidFormatHelper.php.

Member Data Documentation

◆ ERROR_ENCODING

const MediaWiki\Rest\Handler\ParsoidFormatHelper::ERROR_ENCODING
Initial value:
= [
self::FORMAT_WIKITEXT => 'plain',
self::FORMAT_HTML => 'html',
self::FORMAT_PAGEBUNDLE => 'json',
self::FORMAT_LINT => 'json',
]

Definition at line 36 of file ParsoidFormatHelper.php.

◆ FORMAT_HTML

const MediaWiki\Rest\Handler\ParsoidFormatHelper::FORMAT_HTML = 'html'

Definition at line 32 of file ParsoidFormatHelper.php.

◆ FORMAT_LINT

const MediaWiki\Rest\Handler\ParsoidFormatHelper::FORMAT_LINT = 'lint'

Definition at line 34 of file ParsoidFormatHelper.php.

◆ FORMAT_PAGEBUNDLE

const MediaWiki\Rest\Handler\ParsoidFormatHelper::FORMAT_PAGEBUNDLE = 'pagebundle'

Definition at line 33 of file ParsoidFormatHelper.php.

◆ FORMAT_WIKITEXT

const MediaWiki\Rest\Handler\ParsoidFormatHelper::FORMAT_WIKITEXT = 'wikitext'

Definition at line 31 of file ParsoidFormatHelper.php.

◆ VALID_PAGE

◆ VALID_TRANSFORM

const MediaWiki\Rest\Handler\ParsoidFormatHelper::VALID_TRANSFORM
Initial value:
= [
self::FORMAT_HTML => [ self::FORMAT_WIKITEXT ],
self::FORMAT_PAGEBUNDLE => [ self::FORMAT_WIKITEXT, self::FORMAT_PAGEBUNDLE ],
]

Definition at line 47 of file ParsoidFormatHelper.php.


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