Merge "Rewrite pref cleanup script"
[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 */
32 class ApiHelpParamValueMessage extends Message {
33
34 protected $paramValue;
35 protected $deprecated;
36
37 /**
38 * @see Message::__construct
39 *
40 * @param string $paramValue Parameter value being documented
41 * @param string $text Message to use.
42 * @param array $params Parameters for the message.
43 * @param bool $deprecated Whether the value is deprecated
44 * @throws InvalidArgumentException
45 * @since 1.30 Added the `$deprecated` parameter
46 */
47 public function __construct( $paramValue, $text, $params = [], $deprecated = false ) {
48 parent::__construct( $text, $params );
49 $this->paramValue = $paramValue;
50 $this->deprecated = (bool)$deprecated;
51 }
52
53 /**
54 * Fetch the parameter value
55 * @return string
56 */
57 public function getParamValue() {
58 return $this->paramValue;
59 }
60
61 /**
62 * Fetch the 'deprecated' flag
63 * @since 1.30
64 * @return bool
65 */
66 public function isDeprecated() {
67 return $this->deprecated;
68 }
69
70 /**
71 * Fetch the message.
72 * @return string
73 */
74 public function fetchMessage() {
75 if ( $this->message === null ) {
76 $dep = '';
77 if ( $this->isDeprecated() ) {
78 $msg = new Message( 'api-help-param-deprecated' );
79 $msg->interface = $this->interface;
80 $msg->language = $this->language;
81 $msg->useDatabase = $this->useDatabase;
82 $msg->title = $this->title;
83 $dep = '<span class="apihelp-deprecated">' . $msg->fetchMessage() . '</span> ';
84 }
85 $this->message = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:"
86 . $dep . parent::fetchMessage();
87 }
88 return $this->message;
89 }
90
91 }