Debian Codegraph @

includes/skins/components/SkinComponentRegistryContext.php

raw symbols SCIP
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 MediaWiki\Config\Config;
22 use MediaWiki\Context\IContextSource;
23 use MediaWiki\Language\Language;
24 use MediaWiki\Output\OutputPage;
25 use MediaWiki\Title\Title;
26 use MediaWiki\User\User;
27 use MessageLocalizer;
28 use Skin;
29 use WikiPage;
30
31 /**
32 * @internal for use inside Skin and SkinTemplate classes only
33 * @unstable
34 */
35 class SkinComponentRegistryContext implements ComponentRegistryContext {
36
37 /** @var Skin */
38 private $skin;
39
40 /** @var MessageLocalizer|null */
41 private $localizer = null;
42
43 /**
44 * @param Skin $skin
45 */
46 public function __construct( Skin $skin ) {
47 $this->skin = $skin;
48 }
49
50 /**
51 * @return IContextSource
52 */
53 public function getContextSource(): IContextSource {
54 return $this->skin->getContext();
55 }
56
57 /**
58 * @inheritDoc
59 */
60 public function getConfig(): Config {
61 return $this->skin->getConfig();
62 }
63
64 /**
65 * @inheritDoc
66 */
67 public function getTitle(): Title {
68 return $this->skin->getTitle() ?? Title::makeTitle( NS_MAIN, 'Foo' );
69 }
70
71 /**
72 * @return Title|null the "relevant" title - see Skin::getRelevantTitle
73 */
74 public function getRelevantTitle() {
75 return $this->skin->getRelevantTitle() ?? $this->getTitle();
76 }
77
78 /**
79 * @return OutputPage
80 */
81 public function getOutput(): OutputPage {
82 return $this->skin->getOutput();
83 }
84
85 /**
86 * @return User
87 */
88 public function getUser() {
89 return $this->skin->getUser();
90 }
91
92 /**
93 * @return Language $language
94 */
95 public function getLanguage() {
96 return $this->skin->getLanguage();
97 }
98
99 /**
100 * @return MessageLocalizer
101 */
102 public function getMessageLocalizer(): MessageLocalizer {
103 if ( $this->localizer === null ) {
104 // Cannot call getContext in constructor,
105 // because Skin::class does not have a context yet.
106 // But it is valid to call it now
107 $this->localizer = $this->skin->getContext();
108 }
109
110 return $this->localizer;
111 }
112
113 /**
114 * @return WikiPage
115 */
116 public function getWikiPage() {
117 return $this->skin->getWikiPage();
118 }
119
120 /**
121 * Temporarily allows access to Skin method.
122 * It exists to support skins overriding the method in MediaWiki 1.40
123 * (overriding the method is now deprecated)
124 * It can be removed in 1.41
125 *
126 * @unstable
127 * @internal
128 * @return array
129 */
130 public function getFooterIcons() {
131 return $this->skin->getFooterIcons();
132 }
133
134 /**
135 * Renders a $wgFooterIcons icon according to the method's arguments
136 * It exists to support skins overriding the method in MediaWiki 1.40
137 * (overriding the method is now deprecated)
138 * It can be removed in 1.41
139 *
140 * @unstable
141 * @param array $icon The icon to build the html for, see $wgFooterIcons
142 * for the format of this array.
143 * @param bool|string $withImage Whether to use the icon's image or output
144 * a text-only footericon.
145 * @internal
146 * @return string HTML
147 */
148 public function makeFooterIcon( $icon, $withImage = 'withImage' ) {
149 return $this->skin->makeFooterIcon( $icon, $withImage );
150 }
151 }