ApiHelpParamValueMessage.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © 2014 Wikimedia Foundation and contributors
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. */
  22. /**
  23. * Message subclass that prepends wikitext for API help.
  24. *
  25. * This exists so the apihelp-*-paramvalue-*-* messages don't all have to
  26. * include markup wikitext while still keeping the
  27. * 'APIGetParamDescriptionMessages' hook simple.
  28. *
  29. * @since 1.25
  30. * @ingroup API
  31. */
  32. class ApiHelpParamValueMessage extends Message {
  33. protected $paramValue;
  34. protected $deprecated;
  35. /**
  36. * @see Message::__construct
  37. *
  38. * @param string $paramValue Parameter value being documented
  39. * @param string $text Message to use.
  40. * @param array $params Parameters for the message.
  41. * @param bool $deprecated Whether the value is deprecated
  42. * @throws InvalidArgumentException
  43. * @since 1.30 Added the `$deprecated` parameter
  44. */
  45. public function __construct( $paramValue, $text, $params = [], $deprecated = false ) {
  46. parent::__construct( $text, $params );
  47. $this->paramValue = $paramValue;
  48. $this->deprecated = (bool)$deprecated;
  49. }
  50. /**
  51. * Fetch the parameter value
  52. * @return string
  53. */
  54. public function getParamValue() {
  55. return $this->paramValue;
  56. }
  57. /**
  58. * Fetch the 'deprecated' flag
  59. * @since 1.30
  60. * @return bool
  61. */
  62. public function isDeprecated() {
  63. return $this->deprecated;
  64. }
  65. /**
  66. * Fetch the message.
  67. * @return string
  68. */
  69. public function fetchMessage() {
  70. if ( $this->message === null ) {
  71. $dep = '';
  72. if ( $this->isDeprecated() ) {
  73. $msg = new Message( 'api-help-param-deprecated' );
  74. $msg->interface = $this->interface;
  75. $msg->language = $this->language;
  76. $msg->useDatabase = $this->useDatabase;
  77. $msg->title = $this->title;
  78. $dep = '<span class="apihelp-deprecated">' . $msg->fetchMessage() . '</span> ';
  79. }
  80. $this->message = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:"
  81. . $dep . parent::fetchMessage();
  82. }
  83. return $this->message;
  84. }
  85. }