Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 13 |
CRAP | |
0.00% |
0 / 1 |
SkinComponentRegistryContext | |
0.00% |
0 / 24 |
|
0.00% |
0 / 13 |
272 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getContextSource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getConfig | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getRelevantTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getOutput | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getUser | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getLanguage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getMessageLocalizer | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getWikiPage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
runHook | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
getFooterIcons | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
makeFooterIcon | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | */ |
18 | |
19 | namespace MediaWiki\Skin; |
20 | |
21 | use Language; |
22 | use MediaWiki\Config\Config; |
23 | use MediaWiki\Context\IContextSource; |
24 | use MediaWiki\HookContainer\ProtectedHookAccessorTrait; |
25 | use MediaWiki\Output\OutputPage; |
26 | use MediaWiki\Title\Title; |
27 | use MediaWiki\User\User; |
28 | use MessageLocalizer; |
29 | use Skin; |
30 | use WikiPage; |
31 | |
32 | /** |
33 | * @internal for use inside Skin and SkinTemplate classes only |
34 | * @unstable |
35 | */ |
36 | class SkinComponentRegistryContext implements ComponentRegistryContext { |
37 | use ProtectedHookAccessorTrait; |
38 | |
39 | /** @var Skin */ |
40 | private $skin; |
41 | |
42 | /** @var MessageLocalizer|null */ |
43 | private $localizer = null; |
44 | |
45 | /** |
46 | * @param Skin $skin |
47 | */ |
48 | public function __construct( Skin $skin ) { |
49 | $this->skin = $skin; |
50 | } |
51 | |
52 | /** |
53 | * @return IContextSource |
54 | */ |
55 | public function getContextSource(): IContextSource { |
56 | return $this->skin->getContext(); |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | */ |
62 | public function getConfig(): Config { |
63 | return $this->skin->getConfig(); |
64 | } |
65 | |
66 | /** |
67 | * @inheritDoc |
68 | */ |
69 | public function getTitle(): Title { |
70 | return $this->skin->getTitle() ?? Title::makeTitle( NS_MAIN, 'Foo' ); |
71 | } |
72 | |
73 | /** |
74 | * @return Title|null the "relevant" title - see Skin::getRelevantTitle |
75 | */ |
76 | public function getRelevantTitle() { |
77 | return $this->skin->getRelevantTitle() ?? $this->getTitle(); |
78 | } |
79 | |
80 | /** |
81 | * @return OutputPage |
82 | */ |
83 | public function getOutput(): OutputPage { |
84 | return $this->skin->getOutput(); |
85 | } |
86 | |
87 | /** |
88 | * @return User |
89 | */ |
90 | public function getUser() { |
91 | return $this->skin->getUser(); |
92 | } |
93 | |
94 | /** |
95 | * @return Language $language |
96 | */ |
97 | public function getLanguage() { |
98 | return $this->skin->getLanguage(); |
99 | } |
100 | |
101 | /** |
102 | * @return MessageLocalizer |
103 | */ |
104 | public function getMessageLocalizer(): MessageLocalizer { |
105 | if ( $this->localizer === null ) { |
106 | // Cannot call getContext in constructor, |
107 | // because Skin::class does not have a context yet. |
108 | // But it is valid to call it now |
109 | $this->localizer = $this->skin->getContext(); |
110 | } |
111 | |
112 | return $this->localizer; |
113 | } |
114 | |
115 | /** |
116 | * @return WikiPage |
117 | */ |
118 | public function getWikiPage() { |
119 | return $this->skin->getWikiPage(); |
120 | } |
121 | |
122 | /** |
123 | * Run a hook |
124 | * |
125 | * @param string $methodName |
126 | * @param array $args |
127 | */ |
128 | public function runHook( string $methodName, array $args ) { |
129 | $hookRunner = $this->getHookRunner(); |
130 | $hook = [ $hookRunner, $methodName ]; |
131 | switch ( $methodName ) { |
132 | case 'onSkinAddFooterLinks': |
133 | call_user_func_array( |
134 | $hook, |
135 | array_merge( [ $this->skin ], $args ) |
136 | ); |
137 | break; |
138 | default: |
139 | call_user_func_array( $hook, $args ); |
140 | break; |
141 | } |
142 | } |
143 | |
144 | /** |
145 | * Temporarily allows access to Skin method. |
146 | * It exists to support skins overriding the method in MediaWiki 1.40 |
147 | * (overriding the method is now deprecated) |
148 | * It can be removed in 1.41 |
149 | * |
150 | * @unstable |
151 | * @internal |
152 | * @return array |
153 | */ |
154 | public function getFooterIcons() { |
155 | return $this->skin->getFooterIcons(); |
156 | } |
157 | |
158 | /** |
159 | * Renders a $wgFooterIcons icon according to the method's arguments |
160 | * It exists to support skins overriding the method in MediaWiki 1.40 |
161 | * (overriding the method is now deprecated) |
162 | * It can be removed in 1.41 |
163 | * |
164 | * @unstable |
165 | * @param array $icon The icon to build the html for, see $wgFooterIcons |
166 | * for the format of this array. |
167 | * @param bool|string $withImage Whether to use the icon's image or output |
168 | * a text-only footericon. |
169 | * @internal |
170 | * @return string HTML |
171 | */ |
172 | public function makeFooterIcon( $icon, $withImage = 'withImage' ) { |
173 | return $this->skin->makeFooterIcon( $icon, $withImage ); |
174 | } |
175 | } |