IApiMessage.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * Interface for messages with machine-readable data for use by the API
  22. *
  23. * The idea is that it's a Message that has some extra data for the API to use when interpreting it
  24. * as an error (or, in the future, as a warning). Internals of MediaWiki often use messages (or
  25. * message keys, or Status objects containing messages) to pass information about errors to the user
  26. * (see e.g. Title::getUserPermissionsErrors()) and the API has to make do with that.
  27. *
  28. * @since 1.25
  29. * @note This interface exists to work around PHP's inheritance, so ApiMessage
  30. * can extend Message and ApiRawMessage can extend RawMessage while still
  31. * allowing an instanceof check for a Message object including this
  32. * functionality. If for some reason you feel the need to implement this
  33. * interface on some other class, that class must also implement all the
  34. * public methods the Message class provides (not just those from
  35. * MessageSpecifier, which as written is fairly useless).
  36. * @ingroup API
  37. */
  38. interface IApiMessage extends MessageSpecifier {
  39. /**
  40. * Returns a machine-readable code for use by the API
  41. *
  42. * If no code was specifically set, the message key is used as the code
  43. * after removing "apiwarn-" or "apierror-" prefixes and applying
  44. * backwards-compatibility mappings.
  45. *
  46. * @return string
  47. */
  48. public function getApiCode();
  49. /**
  50. * Returns additional machine-readable data about the error condition
  51. * @return array
  52. */
  53. public function getApiData();
  54. /**
  55. * Sets the machine-readable code for use by the API
  56. * @param string|null $code If null, uses the default (see self::getApiCode())
  57. * @param array|null $data If non-null, passed to self::setApiData()
  58. */
  59. public function setApiCode( $code, array $data = null );
  60. /**
  61. * Sets additional machine-readable data about the error condition
  62. * @param array $data
  63. */
  64. public function setApiData( array $data );
  65. }