MediaWiki master
MediaWiki\Api\IApiMessage Interface Reference

Interface for messages with machine-readable data for use by the API. More...

Inherits Wikimedia\Message\MessageSpecifier.

Inherited by MediaWiki\Api\ApiMessage, and MediaWiki\Api\ApiRawMessage.

Collaboration diagram for MediaWiki\Api\IApiMessage:

Public Member Functions

 getApiCode ()
 Returns a machine-readable code for use by the API.
 
 getApiData ()
 Returns additional machine-readable data about the error condition.
 
 setApiCode ( $code, ?array $data=null)
 Sets the machine-readable code for use by the API.
 
 setApiData (array $data)
 Sets additional machine-readable data about the error condition.
 
- Public Member Functions inherited from Wikimedia\Message\MessageSpecifier
 getKey ()
 Returns the message key.
 
 getParams ()
 Returns the message parameters.
 

Detailed Description

Interface for messages with machine-readable data for use by the API.

The idea is that it's a Message that has some extra data for the API to use when interpreting it as an error (or, in the future, as a warning). Internals of MediaWiki often use messages (or message keys, or Status objects containing messages) to pass information about errors to the user (see e.g. PermissionManager::getPermissionErrors()) and the API has to make do with that.

Since
1.25
Note
This interface exists to work around PHP's inheritance, so ApiMessage can extend Message and ApiRawMessage can extend RawMessage while still allowing an instanceof check for a Message object including this functionality. If for some reason you feel the need to implement this interface on some other class, that class must also implement all the public methods the Message class provides (not just those from MessageSpecifier, which as written is fairly useless).

Definition at line 43 of file IApiMessage.php.

Member Function Documentation

◆ getApiCode()

MediaWiki\Api\IApiMessage::getApiCode ( )

Returns a machine-readable code for use by the API.

If no code was specifically set, the message key is used as the code after removing "apiwarn-" or "apierror-" prefixes and applying backwards-compatibility mappings.

Returns
string

Implemented in MediaWiki\Api\ApiRawMessage.

Referenced by MediaWiki\Rest\Handler\ActionModuleBasedHandler\throwHttpExceptionForActionModuleError(), MediaWiki\Rest\Handler\EditHandler\throwHttpExceptionForActionModuleError(), and MediaWiki\Rest\Handler\UpdateHandler\throwHttpExceptionForActionModuleError().

◆ getApiData()

MediaWiki\Api\IApiMessage::getApiData ( )

Returns additional machine-readable data about the error condition.

Returns
array

◆ setApiCode()

MediaWiki\Api\IApiMessage::setApiCode ( $code,
?array $data = null )

Sets the machine-readable code for use by the API.

Parameters
string | null$codeIf null, uses the default (see self::getApiCode())
array | null$dataIf non-null, passed to self::setApiData()

Referenced by MediaWiki\Api\ApiMessage\__construct(), and MediaWiki\Api\ApiRawMessage\__construct().

◆ setApiData()

MediaWiki\Api\IApiMessage::setApiData ( array $data)

Sets additional machine-readable data about the error condition.

Parameters
array$data

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