MediaWiki master
MediaWiki\Status\StatusFormatter Class Reference

Formatter for StatusValue objects. More...

Public Member Functions

 __construct (MessageLocalizer $messageLocalizer, MessageCache $messageCache, LoggerInterface $logger)
 
 getHTML (StatusValue $status, array $options=[])
 Get the error message as HTML.
 
 getMessage (StatusValue $status, array $options=[])
 Get a bullet list of the errors as a Message object.
 
 getPsr3MessageAndContext (StatusValue $status, array $context=[])
 Try to convert the status to a PSR-3 friendly format.
 
 getWikiText (StatusValue $status, array $options=[])
 Get the error list as a wikitext formatted list.
 

Detailed Description

Formatter for StatusValue objects.

Since
1.42
See also
StatusValue

Definition at line 45 of file StatusFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Status\StatusFormatter::__construct ( MessageLocalizer $messageLocalizer,
MessageCache $messageCache,
LoggerInterface $logger )

Definition at line 51 of file StatusFormatter.php.

Member Function Documentation

◆ getHTML()

MediaWiki\Status\StatusFormatter::getHTML ( StatusValue $status,
array $options = [] )

Get the error message as HTML.

This is done by parsing the wikitext error message

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).
Parameters
StatusValue$status
array$optionsAn array of options, supporting the following keys:
  • 'shortContext' (string|false|null) A short enclosing context message name, to be used when there is a single error
  • 'longContext' (string|false|null) A long enclosing context message name, for a list
  • 'lang' (string|Language|StubUserLang|null) Language to use for processing messages
  • 'cleanCallback' (callable|null) A callback for sanitizing parameter values
Returns
string

Definition at line 350 of file StatusFormatter.php.

References NS_SPECIAL.

◆ getMessage()

MediaWiki\Status\StatusFormatter::getMessage ( StatusValue $status,
array $options = [] )

Get a bullet list of the errors as a Message object.

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).

$shortContext and $longContext can be used to wrap the error list in some text. $shortContext will be preferred when there is a single error; $longContext will be preferred when there are multiple ones. In either case, $1 will be replaced with the list of errors.

$shortContext is assumed to use $1 as an inline parameter: if there is a single item, it will not be made into a list; if there are multiple items, newlines will be inserted around the list. $longContext is assumed to use $1 as a standalone parameter; it will always receive a list.

If both parameters are missing, and there is only one error, no bullet will be added.

Parameters
StatusValue$status
array$optionsAn array of options, supporting the following keys:
  • 'shortContext' (string|false|null) A short enclosing context message name, to be used when there is a single error
  • 'longContext' (string|false|null) A long enclosing context message name, for a list
  • 'lang' (string|Language|StubUserLang|null) Language to use for processing messages
  • 'cleanCallback' (callable|null) A callback for sanitizing parameter values
Returns
Message

Definition at line 177 of file StatusFormatter.php.

References StatusValue\fatal(), StatusValue\getErrors(), and StatusValue\isOK().

◆ getPsr3MessageAndContext()

MediaWiki\Status\StatusFormatter::getPsr3MessageAndContext ( StatusValue $status,
array $context = [] )

Try to convert the status to a PSR-3 friendly format.

The output will be similar to getWikiText( false, false, 'en' ), but message parameters will be extracted into the context array with parameter names 'parameter1' etc. when possible. A predefined context array may be passed for convenience.

Returns
array A pair of (message, context) suitable for passing to a PSR-3 logger.

Definition at line 236 of file StatusFormatter.php.

References $params, and MediaWiki\Status\StatusFormatter\getWikiText().

◆ getWikiText()

MediaWiki\Status\StatusFormatter::getWikiText ( StatusValue $status,
array $options = [] )

Get the error list as a wikitext formatted list.

All message parameters that were provided as strings will be escaped with wfEscapeWikiText. This is mostly a historical accident and often undesirable (T368821).

  • To avoid this behavior when producing the Status, pass MessageSpecifier objects to methods such as $status->fatal(), instead of separate key and params parameters.
  • To avoid this behavior when consuming the Status, use the $status->getMessages() method instead, and display each message separately (or combine then with Message::listParams()).
Parameters
StatusValue$status
array$optionsAn array of options, supporting the following keys:
  • 'shortContext' (string|false|null) A short enclosing context message name, to be used when there is a single error
  • 'longContext' (string|false|null) A long enclosing context message name, for a list
  • 'lang' (string|Language|StubUserLang|null) Language to use for processing messages
  • 'cleanCallback' (callable|null) A callback for sanitizing parameter values
Returns
string

Definition at line 100 of file StatusFormatter.php.

References StatusValue\fatal(), StatusValue\getErrors(), and StatusValue\isOK().

Referenced by MediaWiki\Status\StatusFormatter\getPsr3MessageAndContext().


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