| 1 | <?php |
| 2 | /** |
| 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. |
| 7 | * |
| 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. |
| 12 | * |
| 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 |
| 17 | * |
| 18 | * @file |
| 19 | */ |
| 20 | |
| 21 | namespace MediaWiki\Api; |
| 22 | |
| 23 | use Wikimedia\Message\MessageSpecifier; |
| 24 | |
| 25 | /** |
| 26 | * Interface for messages with machine-readable data for use by the API |
| 27 | * |
| 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. |
| 32 | * |
| 33 | * @since 1.25 |
| 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). |
| 41 | * @ingroup API |
| 42 | */ |
| 43 | interface IApiMessage extends MessageSpecifier { |
| 44 | /** |
| 45 | * Returns a machine-readable code for use by the API |
| 46 | * |
| 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. |
| 50 | * |
| 51 | * @return string |
| 52 | */ |
| 53 | public function getApiCode(); |
| 54 | |
| 55 | /** |
| 56 | * Returns additional machine-readable data about the error condition |
| 57 | * @return array |
| 58 | */ |
| 59 | public function getApiData(); |
| 60 | |
| 61 | /** |
| 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() |
| 65 | */ |
| 66 | public function setApiCode( $code, ?array $data = null ); |
| 67 | |
| 68 | /** |
| 69 | * Sets additional machine-readable data about the error condition |
| 70 | * @param array $data |
| 71 | */ |
| 72 | public function setApiData( array $data ); |
| 73 | } |
| 74 | |
| 75 | /** @deprecated class alias since 1.43 */ |
| 76 | class_alias( IApiMessage::class, 'IApiMessage' ); |