Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 39 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| ApiHelpParamValueMessage | |
0.00% |
0 / 38 |
|
0.00% |
0 / 7 |
272 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getParamValue | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isDeprecated | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deprecationMsg | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| isInternal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fetchMessage | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
72 | |||
| subMessage | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Copyright © 2014 Wikimedia Foundation and contributors |
| 4 | * |
| 5 | * @license GPL-2.0-or-later |
| 6 | * @file |
| 7 | */ |
| 8 | |
| 9 | namespace MediaWiki\Api; |
| 10 | |
| 11 | use MediaWiki\Message\Message; |
| 12 | use Wikimedia\Message\MessageSpecifier; |
| 13 | |
| 14 | /** |
| 15 | * Message subclass that prepends wikitext for API help. |
| 16 | * |
| 17 | * This exists so the apihelp-*-paramvalue-*-* messages don't all have to |
| 18 | * include markup wikitext while still keeping the |
| 19 | * 'APIGetParamDescriptionMessages' hook simple. |
| 20 | * |
| 21 | * @newable |
| 22 | * @since 1.25 |
| 23 | * @ingroup API |
| 24 | */ |
| 25 | class ApiHelpParamValueMessage extends Message { |
| 26 | |
| 27 | /** |
| 28 | * @see Message::__construct |
| 29 | * @stable to call |
| 30 | * |
| 31 | * @param string $paramValue Parameter value being documented |
| 32 | * @param string $text Message to use. |
| 33 | * @param array $params Parameters for the message. |
| 34 | * @param bool|MessageSpecifier $deprecated Whether the value is deprecated, |
| 35 | * and an optional message describing the deprecation or replacement. |
| 36 | * @param bool $internal Whether the value is internal |
| 37 | * @since 1.30 Added the `$deprecated` parameter |
| 38 | * @since 1.35 Added the `$internal` parameter |
| 39 | */ |
| 40 | public function __construct( |
| 41 | protected readonly string $paramValue, |
| 42 | $text, |
| 43 | $params = [], |
| 44 | protected readonly bool|MessageSpecifier $deprecated = false, |
| 45 | protected readonly bool $internal = false, |
| 46 | ) { |
| 47 | parent::__construct( $text, $params ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Fetch the parameter value |
| 52 | * @return string |
| 53 | */ |
| 54 | public function getParamValue() { |
| 55 | return $this->paramValue; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Fetch the 'deprecated' flag |
| 60 | * @since 1.30 |
| 61 | * @return bool |
| 62 | */ |
| 63 | public function isDeprecated() { |
| 64 | return $this->deprecated !== false; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Fetch the deprecation message. |
| 69 | * @since 1.46 |
| 70 | */ |
| 71 | public function deprecationMsg(): ?MessageSpecifier { |
| 72 | return $this->deprecated instanceof MessageSpecifier ? |
| 73 | $this->deprecated : null; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Fetch the 'internal' flag |
| 78 | * @since 1.35 |
| 79 | * @return bool |
| 80 | */ |
| 81 | public function isInternal() { |
| 82 | return $this->internal; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return string |
| 87 | */ |
| 88 | public function fetchMessage() { |
| 89 | if ( $this->message === null ) { |
| 90 | $prefix = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:"; |
| 91 | if ( $this->isDeprecated() ) { |
| 92 | $deprecationMsg = $this->deprecationMsg(); |
| 93 | $divspan = $deprecationMsg === null ? 'span' : 'div'; |
| 94 | $prefix .= "<$divspan class='apihelp-deprecated'>" . |
| 95 | $this->subMessage( 'api-help-param-deprecated' ); |
| 96 | if ( $deprecationMsg !== null ) { |
| 97 | $prefix .= $this->subMessage( 'word-separator' ) . |
| 98 | $this->subMessage( |
| 99 | Message::newFromSpecifier( $deprecationMsg ) |
| 100 | ); |
| 101 | } |
| 102 | $prefix .= "</$divspan>" . |
| 103 | $this->subMessage( 'word-separator' ); |
| 104 | } |
| 105 | if ( $this->isInternal() ) { |
| 106 | $prefix .= '<span class="apihelp-internal">' . |
| 107 | $this->subMessage( 'api-help-param-internal' ) . |
| 108 | '</span>' . |
| 109 | $this->subMessage( 'word-separator' ); |
| 110 | } |
| 111 | |
| 112 | if ( $this->getLanguage()->getCode() === 'qqx' ) { |
| 113 | # Insert a list of alternative message keys for &uselang=qqx. |
| 114 | $keylist = implode( ' / ', $this->keysToTry ); |
| 115 | if ( $this->overriddenKey !== null ) { |
| 116 | $keylist .= ' = ' . $this->overriddenKey; |
| 117 | } |
| 118 | $this->message = $prefix . "($keylist$*)"; |
| 119 | } else { |
| 120 | $this->message = $prefix . parent::fetchMessage(); |
| 121 | } |
| 122 | } |
| 123 | return $this->message; |
| 124 | } |
| 125 | |
| 126 | private function subMessage( string|Message $key ): string { |
| 127 | $msg = $key instanceof Message ? $key : new Message( $key ); |
| 128 | $msg->isInterface = $this->isInterface; |
| 129 | $msg->language = $this->language; |
| 130 | $msg->useDatabase = $this->useDatabase; |
| 131 | $msg->contextPage = $this->contextPage; |
| 132 | return $msg->plain(); |
| 133 | } |
| 134 | |
| 135 | } |
| 136 | |
| 137 | /** @deprecated class alias since 1.43 */ |
| 138 | class_alias( ApiHelpParamValueMessage::class, 'ApiHelpParamValueMessage' ); |