Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
ApiHelpParamValueMessage
0.00% covered (danger)
0.00%
0 / 28
0.00% covered (danger)
0.00%
0 / 6
90
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 getParamValue
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isDeprecated
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isInternal
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 fetchMessage
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
 subMessage
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Copyright © 2014 Wikimedia Foundation and contributors
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23/**
24 * Message subclass that prepends wikitext for API help.
25 *
26 * This exists so the apihelp-*-paramvalue-*-* messages don't all have to
27 * include markup wikitext while still keeping the
28 * 'APIGetParamDescriptionMessages' hook simple.
29 *
30 * @newable
31 * @since 1.25
32 * @ingroup API
33 */
34class ApiHelpParamValueMessage extends Message {
35
36    protected $paramValue;
37    protected $deprecated;
38    protected $internal;
39
40    /**
41     * @see Message::__construct
42     * @stable to call
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     * @param bool $internal Whether the value is internal
49     * @throws InvalidArgumentException
50     * @since 1.30 Added the `$deprecated` parameter
51     * @since 1.35 Added the `$internal` parameter
52     */
53    public function __construct(
54        $paramValue,
55        $text,
56        $params = [],
57        $deprecated = false,
58        $internal = false
59    ) {
60        parent::__construct( $text, $params );
61        $this->paramValue = $paramValue;
62        $this->deprecated = (bool)$deprecated;
63        $this->internal = (bool)$internal;
64    }
65
66    /**
67     * Fetch the parameter value
68     * @return string
69     */
70    public function getParamValue() {
71        return $this->paramValue;
72    }
73
74    /**
75     * Fetch the 'deprecated' flag
76     * @since 1.30
77     * @return bool
78     */
79    public function isDeprecated() {
80        return $this->deprecated;
81    }
82
83    /**
84     * Fetch the 'internal' flag
85     * @since 1.35
86     * @return bool
87     */
88    public function isInternal() {
89        return $this->internal;
90    }
91
92    /**
93     * @return string
94     */
95    public function fetchMessage() {
96        if ( $this->message === null ) {
97            $prefix = '';
98            if ( $this->isDeprecated() ) {
99                $prefix .= '<span class="apihelp-deprecated">' .
100                    $this->subMessage( 'api-help-param-deprecated' ) .
101                    '</span>' .
102                    $this->subMessage( 'word-separator' );
103            }
104            if ( $this->isInternal() ) {
105                $prefix .= '<span class="apihelp-internal">' .
106                    $this->subMessage( 'api-help-param-internal' ) .
107                    '</span>' .
108                    $this->subMessage( 'word-separator' );
109            }
110            $this->message = ";<span dir=\"ltr\" lang=\"en\">{$this->paramValue}</span>:"
111                . $prefix . parent::fetchMessage();
112        }
113        return $this->message;
114    }
115
116    private function subMessage( $key ) {
117        $msg = new Message( $key );
118        $msg->interface = $this->interface;
119        $msg->language = $this->language;
120        $msg->useDatabase = $this->useDatabase;
121        $msg->contextPage = $this->contextPage;
122        return $msg->fetchMessage();
123    }
124
125}