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