3 * Copyright © 2014 Wikimedia Foundation and contributors
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.
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.
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
23 namespace MediaWiki\Api
;
25 use MediaWiki\Message\Message
;
28 * Message subclass that prepends wikitext for API help.
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.
38 class ApiHelpParamValueMessage
extends Message
{
41 protected $paramValue;
43 protected $deprecated;
48 * @see Message::__construct
51 * @param string $paramValue Parameter value being documented
52 * @param string $text Message to use.
53 * @param array $params Parameters for the message.
54 * @param bool $deprecated Whether the value is deprecated
55 * @param bool $internal Whether the value is internal
56 * @since 1.30 Added the `$deprecated` parameter
57 * @since 1.35 Added the `$internal` parameter
59 public function __construct(
66 parent
::__construct( $text, $params );
67 $this->paramValue
= $paramValue;
68 $this->deprecated
= (bool)$deprecated;
69 $this->internal
= (bool)$internal;
73 * Fetch the parameter value
76 public function getParamValue() {
77 return $this->paramValue
;
81 * Fetch the 'deprecated' flag
85 public function isDeprecated() {
86 return $this->deprecated
;
90 * Fetch the 'internal' flag
94 public function isInternal() {
95 return $this->internal
;
101 public function fetchMessage() {
102 if ( $this->message
=== null ) {
103 $prefix = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:";
104 if ( $this->isDeprecated() ) {
105 $prefix .= '<span class="apihelp-deprecated">' .
106 $this->subMessage( 'api-help-param-deprecated' ) .
108 $this->subMessage( 'word-separator' );
110 if ( $this->isInternal() ) {
111 $prefix .= '<span class="apihelp-internal">' .
112 $this->subMessage( 'api-help-param-internal' ) .
114 $this->subMessage( 'word-separator' );
117 if ( $this->getLanguage()->getCode() === 'qqx' ) {
118 # Insert a list of alternative message keys for &uselang=qqx.
119 $keylist = implode( ' / ', $this->keysToTry
);
120 if ( $this->overriddenKey
!== null ) {
121 $keylist .= ' = ' . $this->overriddenKey
;
123 $this->message
= $prefix . "($keylist$*)";
125 $this->message
= $prefix . parent
::fetchMessage();
128 return $this->message
;
131 private function subMessage( $key ) {
132 $msg = new Message( $key );
133 $msg->isInterface
= $this->isInterface
;
134 $msg->language
= $this->language
;
135 $msg->useDatabase
= $this->useDatabase
;
136 $msg->contextPage
= $this->contextPage
;
137 return $msg->plain();
142 /** @deprecated class alias since 1.43 */
143 class_alias( ApiHelpParamValueMessage
::class, 'ApiHelpParamValueMessage' );