Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
24.18% |
22 / 91 |
|
5.88% |
1 / 17 |
CRAP | |
0.00% |
0 / 1 |
WebInstallerOutput | |
24.18% |
22 / 91 |
|
5.88% |
1 / 17 |
320.69 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addHTML | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
addWikiTextAsInterface | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
addHTMLNoFlush | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
redirect | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
output | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
getCSS | |
100.00% |
22 / 22 |
|
100.00% |
1 / 1 |
1 | |||
getCssUrl | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
flush | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
20 | |||
getLanguage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
getHeadAttribs | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
headerDone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
outputHeader | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
6 | |||
outputFooter | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
12 | |||
outputTitle | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getJQuery | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
getCodex | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | /** |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License as published by |
6 | * the Free Software Foundation; either version 2 of the License, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details. |
13 | * |
14 | * You should have received a copy of the GNU General Public License along |
15 | * with this program; if not, write to the Free Software Foundation, Inc., |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | * http://www.gnu.org/copyleft/gpl.html |
18 | * |
19 | * @file |
20 | * @ingroup Installer |
21 | */ |
22 | |
23 | namespace MediaWiki\Installer; |
24 | |
25 | use LogicException; |
26 | use MediaWiki\Html\Html; |
27 | use MediaWiki\Language\Language; |
28 | use MediaWiki\MediaWikiServices; |
29 | use MediaWiki\Request\FauxRequest; |
30 | use MediaWiki\ResourceLoader as RL; |
31 | use MediaWiki\ResourceLoader\ResourceLoader; |
32 | |
33 | /** |
34 | * Output class modelled on OutputPage. |
35 | * |
36 | * I've opted to use a distinct class rather than derive from OutputPage here in |
37 | * the interests of separation of concerns: if we used a subclass, there would be |
38 | * quite a lot of things you could do in OutputPage that would break the installer, |
39 | * that wouldn't be immediately obvious. |
40 | * |
41 | * @ingroup Installer |
42 | * @since 1.17 |
43 | * @internal |
44 | */ |
45 | class WebInstallerOutput { |
46 | |
47 | /** |
48 | * The WebInstaller object this WebInstallerOutput is used by. |
49 | * |
50 | * @var WebInstaller |
51 | */ |
52 | public $parent; |
53 | |
54 | /** |
55 | * Buffered contents that haven't been output yet |
56 | * @var string |
57 | */ |
58 | private $contents = ''; |
59 | |
60 | /** |
61 | * Has the header been output? |
62 | * @var bool |
63 | */ |
64 | private $headerDone = false; |
65 | |
66 | /** |
67 | * @var string |
68 | */ |
69 | public $redirectTarget; |
70 | |
71 | public function __construct( WebInstaller $parent ) { |
72 | $this->parent = $parent; |
73 | } |
74 | |
75 | /** |
76 | * @param string $html |
77 | */ |
78 | public function addHTML( $html ) { |
79 | $this->contents .= $html; |
80 | $this->flush(); |
81 | } |
82 | |
83 | /** |
84 | * @param string $text |
85 | * @since 1.32 |
86 | */ |
87 | public function addWikiTextAsInterface( $text ) { |
88 | $this->addHTML( $this->parent->parse( $text ) ); |
89 | } |
90 | |
91 | /** |
92 | * @param string $html |
93 | */ |
94 | public function addHTMLNoFlush( $html ) { |
95 | $this->contents .= $html; |
96 | } |
97 | |
98 | /** |
99 | * @param string $url |
100 | */ |
101 | public function redirect( $url ) { |
102 | if ( $this->headerDone ) { |
103 | throw new LogicException( __METHOD__ . ' called after sending headers' ); |
104 | } |
105 | $this->redirectTarget = $url; |
106 | } |
107 | |
108 | public function output() { |
109 | $this->flush(); |
110 | |
111 | if ( !$this->redirectTarget ) { |
112 | $this->outputFooter(); |
113 | } |
114 | } |
115 | |
116 | /** |
117 | * Get the stylesheet of the MediaWiki skin. |
118 | * |
119 | * @return string |
120 | */ |
121 | public function getCSS() { |
122 | $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader(); |
123 | |
124 | $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [ |
125 | 'debug' => 'true', |
126 | 'lang' => $this->getLanguage()->getCode(), |
127 | 'only' => 'styles', |
128 | ] ) ); |
129 | |
130 | $module = new RL\SkinModule( [ |
131 | 'features' => [ |
132 | 'elements', |
133 | 'interface-message-box' |
134 | ], |
135 | 'styles' => [ |
136 | 'mw-config/config.css', |
137 | ], |
138 | ] ); |
139 | $module->setConfig( $resourceLoader->getConfig() ); |
140 | |
141 | // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query |
142 | $styles = ResourceLoader::makeCombinedStyles( |
143 | $module->readStyleFiles( |
144 | $module->getStyleFiles( $rlContext ), |
145 | $rlContext |
146 | ) ); |
147 | |
148 | return implode( "\n", $styles ); |
149 | } |
150 | |
151 | /** |
152 | * "<link>" to index.php?css=1 for the "<head>" |
153 | * |
154 | * @return string |
155 | */ |
156 | private function getCssUrl() { |
157 | return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) ); |
158 | } |
159 | |
160 | public function flush() { |
161 | if ( !$this->headerDone ) { |
162 | $this->outputHeader(); |
163 | } |
164 | if ( !$this->redirectTarget && strlen( $this->contents ) ) { |
165 | echo $this->contents; |
166 | flush(); |
167 | $this->contents = ''; |
168 | } |
169 | } |
170 | |
171 | /** |
172 | * @since 1.33 |
173 | * @return Language |
174 | */ |
175 | private function getLanguage() { |
176 | global $wgLang; |
177 | |
178 | return is_object( $wgLang ) ? $wgLang |
179 | : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ); |
180 | } |
181 | |
182 | /** |
183 | * @return string[] |
184 | */ |
185 | public function getHeadAttribs() { |
186 | return [ |
187 | 'dir' => $this->getLanguage()->getDir(), |
188 | 'lang' => $this->getLanguage()->getHtmlCode(), |
189 | ]; |
190 | } |
191 | |
192 | /** |
193 | * Get whether the header has been output |
194 | * |
195 | * @return bool |
196 | */ |
197 | public function headerDone() { |
198 | return $this->headerDone; |
199 | } |
200 | |
201 | public function outputHeader() { |
202 | $this->headerDone = true; |
203 | $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' ); |
204 | $this->parent->request->response()->header( 'X-Frame-Options: DENY' ); |
205 | |
206 | if ( $this->redirectTarget ) { |
207 | $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget ); |
208 | |
209 | return; |
210 | } |
211 | ?> |
212 | <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> |
213 | |
214 | <head> |
215 | <meta name="robots" content="noindex, nofollow" /> |
216 | <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
217 | <title><?php $this->outputTitle(); ?></title> |
218 | <?php echo $this->getCodex() . "\n"; ?> |
219 | <?php echo $this->getCssUrl() . "\n"; ?> |
220 | <?php echo $this->getJQuery() . "\n"; ?> |
221 | <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?> |
222 | </head> |
223 | |
224 | <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?> |
225 | <div id="mw-page-base"></div> |
226 | <div id="mw-head-base"></div> |
227 | <div id="content" class="mw-body" role="main"> |
228 | <div id="bodyContent" class="mw-body-content"> |
229 | |
230 | <h1><?php $this->outputTitle(); ?></h1> |
231 | <?php |
232 | } |
233 | |
234 | public function outputFooter() { |
235 | ?> |
236 | |
237 | </div></div> |
238 | |
239 | <aside id="mw-panel"> |
240 | <div class="portal" id="p-logo"> |
241 | <a href="https://www.mediawiki.org/" title="Main Page"></a> |
242 | </div> |
243 | <?php |
244 | // @phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact |
245 | $message = wfMessage( 'config-sidebar' )->plain(); |
246 | // Section 1: External links |
247 | // @todo FIXME: Migrate to plain link label messages (T227297). |
248 | foreach ( explode( '----', $message ) as $section ) { |
249 | echo '<div class="portal"><div class="body">'; |
250 | echo $this->parent->parse( $section, true ); |
251 | echo '</div></div>'; |
252 | } |
253 | // Section 2: Installer pages |
254 | echo '<div class="portal"><div class="body"><ul>'; |
255 | foreach ( [ |
256 | 'config-sidebar-relnotes' => 'ReleaseNotes', |
257 | 'config-sidebar-license' => 'Copying', |
258 | 'config-sidebar-upgrade' => 'UpgradeDoc', |
259 | ] as $msgKey => $pageName ) { |
260 | echo $this->parent->makeLinkItem( |
261 | $this->parent->getDocUrl( $pageName ), |
262 | wfMessage( $msgKey )->text() |
263 | ); |
264 | } |
265 | echo '</ul></div></div>'; |
266 | // @phpcs:enable |
267 | ?> |
268 | </aside> |
269 | |
270 | <?php |
271 | echo Html::closeElement( 'body' ) . Html::closeElement( 'html' ); |
272 | } |
273 | |
274 | public function outputTitle() { |
275 | echo wfMessage( 'config-title', MW_VERSION )->escaped(); |
276 | } |
277 | |
278 | /** |
279 | * @return string |
280 | */ |
281 | public function getJQuery() { |
282 | return Html::linkedScript( "../resources/lib/jquery/jquery.js" ); |
283 | } |
284 | |
285 | /** |
286 | * @return string |
287 | */ |
288 | public function getCodex() { |
289 | return Html::linkedStyle( "../resources/lib/codex/codex.style.css" ); |
290 | } |
291 | |
292 | } |