Merge "FauxRequest: don’t override getValues()"
[lhc/web/wiklou.git] / includes / api / ApiHelpParamValueMessage.php
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 /**
24 * Message subclass that prepends wikitext for API help.
25 *
26 * This exists so the apihelp-*-paramvalue-*-* messages don't all have to
27 * include markup wikitext while still keeping the
28 * 'APIGetParamDescriptionMessages' hook simple.
29 *
30 * @since 1.25
31 * @ingroup API
32 */
33 class ApiHelpParamValueMessage extends Message {
34
35 protected $paramValue;
36 protected $deprecated;
37
38 /**
39 * @see Message::__construct
40 *
41 * @param string $paramValue Parameter value being documented
42 * @param string $text Message to use.
43 * @param array $params Parameters for the message.
44 * @param bool $deprecated Whether the value is deprecated
45 * @throws InvalidArgumentException
46 * @since 1.30 Added the `$deprecated` parameter
47 */
48 public function __construct( $paramValue, $text, $params = [], $deprecated = false ) {
49 parent::__construct( $text, $params );
50 $this->paramValue = $paramValue;
51 $this->deprecated = (bool)$deprecated;
52 }
53
54 /**
55 * Fetch the parameter value
56 * @return string
57 */
58 public function getParamValue() {
59 return $this->paramValue;
60 }
61
62 /**
63 * Fetch the 'deprecated' flag
64 * @since 1.30
65 * @return bool
66 */
67 public function isDeprecated() {
68 return $this->deprecated;
69 }
70
71 /**
72 * Fetch the message.
73 * @return string
74 */
75 public function fetchMessage() {
76 if ( $this->message === null ) {
77 $dep = '';
78 if ( $this->isDeprecated() ) {
79 $msg = new Message( 'api-help-param-deprecated' );
80 $msg->interface = $this->interface;
81 $msg->language = $this->language;
82 $msg->useDatabase = $this->useDatabase;
83 $msg->title = $this->title;
84 $dep = '<span class="apihelp-deprecated">' . $msg->fetchMessage() . '</span> ';
85 }
86 $this->message = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:"
87 . $dep . parent::fetchMessage();
88 }
89 return $this->message;
90 }
91
92 }