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