Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
50.00% |
8 / 16 |
|
30.00% |
3 / 10 |
CRAP | |
0.00% |
0 / 1 |
MessageContent | |
50.00% |
8 / 16 |
|
30.00% |
3 / 10 |
30.00 | |
0.00% |
0 / 1 |
__construct | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
3.21 | |||
getWikitext | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getNativeData | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMessage | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTextForSearchIndex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getWikitextForTransclusion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTextForSummary | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getSize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
copy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
isCountable | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * Wrapper content object allowing to handle a system message as a Content object. |
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 | * @since 1.21 |
21 | * @deprecated since 1.38. |
22 | * |
23 | * @file |
24 | * @ingroup Content |
25 | * |
26 | * @author Daniel Kinzler |
27 | */ |
28 | |
29 | /** |
30 | * Wrapper allowing us to handle a system message as a Content object. |
31 | * Note that this is generally *not* used to represent content from the |
32 | * MediaWiki namespace. |
33 | * MessageContent is just intended as glue for wrapping a message programmatically. |
34 | * |
35 | * @ingroup Content |
36 | */ |
37 | class MessageContent extends AbstractContent { |
38 | |
39 | /** |
40 | * @var Message |
41 | */ |
42 | protected $mMessage; |
43 | |
44 | /** |
45 | * @param Message|string $msg A Message object, or a message key. |
46 | * @param string[]|null $params An optional array of message parameters. |
47 | */ |
48 | public function __construct( $msg, $params = null ) { |
49 | wfDeprecated( __CLASS__, '1.38' ); |
50 | # XXX: messages may be wikitext, html or plain text! and maybe even something else entirely. |
51 | parent::__construct( CONTENT_MODEL_WIKITEXT ); |
52 | |
53 | if ( is_string( $msg ) ) { |
54 | $this->mMessage = wfMessage( $msg ); |
55 | } else { |
56 | $this->mMessage = clone $msg; |
57 | } |
58 | |
59 | if ( $params ) { |
60 | $this->mMessage = $this->mMessage->params( $params ); |
61 | } |
62 | } |
63 | |
64 | /** |
65 | * Returns the message text. {{-transformation is done. |
66 | * |
67 | * @return string Unescaped message text. |
68 | */ |
69 | public function getWikitext() { |
70 | return $this->mMessage->text(); |
71 | } |
72 | |
73 | /** |
74 | * Returns the message object, with any parameters already substituted. |
75 | * |
76 | * @deprecated since 1.33 use getMessage() instead. |
77 | * |
78 | * @return Message |
79 | */ |
80 | public function getNativeData() { |
81 | return $this->getMessage(); |
82 | } |
83 | |
84 | /** |
85 | * Returns the message object, with any parameters already substituted. |
86 | * |
87 | * @since 1.33 |
88 | * |
89 | * @return Message |
90 | */ |
91 | public function getMessage() { |
92 | // NOTE: Message objects are mutable. Cloning here makes MessageContent immutable. |
93 | return clone $this->mMessage; |
94 | } |
95 | |
96 | /** |
97 | * @return string |
98 | * |
99 | * @see Content::getTextForSearchIndex |
100 | */ |
101 | public function getTextForSearchIndex() { |
102 | return $this->mMessage->plain(); |
103 | } |
104 | |
105 | /** |
106 | * @return string |
107 | * |
108 | * @see Content::getWikitextForTransclusion |
109 | */ |
110 | public function getWikitextForTransclusion() { |
111 | return $this->getWikitext(); |
112 | } |
113 | |
114 | /** |
115 | * @param int $maxlength Maximum length of the summary text, defaults to 250. |
116 | * |
117 | * @return string The summary text. |
118 | * |
119 | * @see Content::getTextForSummary |
120 | */ |
121 | public function getTextForSummary( $maxlength = 250 ) { |
122 | return mb_strcut( $this->mMessage->plain(), 0, $maxlength ); |
123 | } |
124 | |
125 | /** |
126 | * @return int |
127 | * |
128 | * @see Content::getSize |
129 | */ |
130 | public function getSize() { |
131 | return strlen( $this->mMessage->plain() ); |
132 | } |
133 | |
134 | /** |
135 | * @return Content A copy of this object |
136 | * |
137 | * @see Content::copy |
138 | */ |
139 | public function copy() { |
140 | // MessageContent is immutable (because getNativeData() and getMessage() |
141 | // returns a clone of the Message object) |
142 | return $this; |
143 | } |
144 | |
145 | /** |
146 | * @param bool|null $hasLinks |
147 | * |
148 | * @return bool Always false. |
149 | * |
150 | * @see Content::isCountable |
151 | */ |
152 | public function isCountable( $hasLinks = null ) { |
153 | return false; |
154 | } |
155 | } |