Merge "SpecialBlock [Vue]: add NamespacesField and PagesField components"
[mediawiki.git] / includes / api / ApiHelpParamValueMessage.php
blob6949af8887a1024e6782655ab8cd3a1694516e0b
1 <?php
2 /**
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
20 * @file
23 namespace MediaWiki\Api;
25 use MediaWiki\Message\Message;
27 /**
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.
34 * @newable
35 * @since 1.25
36 * @ingroup API
38 class ApiHelpParamValueMessage extends Message {
40 /** @var string */
41 protected $paramValue;
42 /** @var bool */
43 protected $deprecated;
44 /** @var bool */
45 protected $internal;
47 /**
48 * @see Message::__construct
49 * @stable to call
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(
60 $paramValue,
61 $text,
62 $params = [],
63 $deprecated = false,
64 $internal = false
65 ) {
66 parent::__construct( $text, $params );
67 $this->paramValue = $paramValue;
68 $this->deprecated = (bool)$deprecated;
69 $this->internal = (bool)$internal;
72 /**
73 * Fetch the parameter value
74 * @return string
76 public function getParamValue() {
77 return $this->paramValue;
80 /**
81 * Fetch the 'deprecated' flag
82 * @since 1.30
83 * @return bool
85 public function isDeprecated() {
86 return $this->deprecated;
89 /**
90 * Fetch the 'internal' flag
91 * @since 1.35
92 * @return bool
94 public function isInternal() {
95 return $this->internal;
98 /**
99 * @return string
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' ) .
107 '</span>' .
108 $this->subMessage( 'word-separator' );
110 if ( $this->isInternal() ) {
111 $prefix .= '<span class="apihelp-internal">' .
112 $this->subMessage( 'api-help-param-internal' ) .
113 '</span>' .
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$*)";
124 } else {
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' );