3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
21 namespace MediaWiki\Api
;
23 use Wikimedia\Message\MessageSpecifier
;
26 * Interface for messages with machine-readable data for use by the API
28 * The idea is that it's a Message that has some extra data for the API to use when interpreting it
29 * as an error (or, in the future, as a warning). Internals of MediaWiki often use messages (or
30 * message keys, or Status objects containing messages) to pass information about errors to the user
31 * (see e.g. PermissionManager::getPermissionErrors()) and the API has to make do with that.
34 * @note This interface exists to work around PHP's inheritance, so ApiMessage
35 * can extend Message and ApiRawMessage can extend RawMessage while still
36 * allowing an instanceof check for a Message object including this
37 * functionality. If for some reason you feel the need to implement this
38 * interface on some other class, that class must also implement all the
39 * public methods the Message class provides (not just those from
40 * MessageSpecifier, which as written is fairly useless).
43 interface IApiMessage
extends MessageSpecifier
{
45 * Returns a machine-readable code for use by the API
47 * If no code was specifically set, the message key is used as the code
48 * after removing "apiwarn-" or "apierror-" prefixes and applying
49 * backwards-compatibility mappings.
53 public function getApiCode();
56 * Returns additional machine-readable data about the error condition
59 public function getApiData();
62 * Sets the machine-readable code for use by the API
63 * @param string|null $code If null, uses the default (see self::getApiCode())
64 * @param array|null $data If non-null, passed to self::setApiData()
66 public function setApiCode( $code, ?
array $data = null );
69 * Sets additional machine-readable data about the error condition
72 public function setApiData( array $data );
75 /** @deprecated class alias since 1.43 */
76 class_alias( IApiMessage
::class, 'IApiMessage' );