| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 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 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
class WebInstallerOutput { |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public $parent; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
private $contents = ''; |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
private $headerDone = false; |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
public $redirectTarget; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
public function __construct( WebInstaller $parent ) { |
| 75 |
$this->parent = $parent; |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
public function addHTML( $html ) { |
| 82 |
$this->contents .= $html; |
| 83 |
$this->flush(); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public function addWikiTextAsInterface( $text ) { |
| 91 |
$this->addHTML( $this->parent->parse( $text ) ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
public function addHTMLNoFlush( $html ) { |
| 98 |
$this->contents .= $html; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
public function redirect( $url ) { |
| 105 |
if ( $this->headerDone ) { |
| 106 |
throw new LogicException( __METHOD__ . ' called after sending headers' ); |
| 107 |
} |
| 108 |
$this->redirectTarget = $url; |
| 109 |
} |
| 110 |
|
| 111 |
public function output() { |
| 112 |
$this->flush(); |
| 113 |
|
| 114 |
if ( !$this->redirectTarget ) { |
| 115 |
$this->outputFooter(); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
public function getCSS() { |
| 125 |
$resourceLoader = MediaWikiServices::getInstance()->getResourceLoader(); |
| 126 |
|
| 127 |
$rlContext = new RL\Context( $resourceLoader, new FauxRequest( [ |
| 128 |
'debug' => 'true', |
| 129 |
'lang' => $this->getLanguage()->getCode(), |
| 130 |
'only' => 'styles', |
| 131 |
] ) ); |
| 132 |
|
| 133 |
$module = new RL\SkinModule( [ |
| 134 |
'features' => [ |
| 135 |
'elements', |
| 136 |
'interface-message-box' |
| 137 |
], |
| 138 |
'styles' => [ |
| 139 |
'mw-config/config.css', |
| 140 |
], |
| 141 |
] ); |
| 142 |
$module->setConfig( $resourceLoader->getConfig() ); |
| 143 |
|
| 144 |
|
| 145 |
$styles = ResourceLoader::makeCombinedStyles( |
| 146 |
$module->readStyleFiles( |
| 147 |
$module->getStyleFiles( $rlContext ), |
| 148 |
$rlContext |
| 149 |
) ); |
| 150 |
|
| 151 |
return implode( "\n", $styles ); |
| 152 |
} |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
private function getCssUrl() { |
| 160 |
return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) ); |
| 161 |
} |
| 162 |
|
| 163 |
public function flush() { |
| 164 |
if ( !$this->headerDone ) { |
| 165 |
$this->outputHeader(); |
| 166 |
} |
| 167 |
if ( !$this->redirectTarget && strlen( $this->contents ) ) { |
| 168 |
echo $this->contents; |
| 169 |
flush(); |
| 170 |
$this->contents = ''; |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
private function getLanguage() { |
| 179 |
global $wgLang; |
| 180 |
|
| 181 |
return is_object( $wgLang ) ? $wgLang |
| 182 |
: MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ); |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
public function getHeadAttribs() { |
| 189 |
return [ |
| 190 |
'dir' => $this->getLanguage()->getDir(), |
| 191 |
'lang' => $this->getLanguage()->getHtmlCode(), |
| 192 |
]; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
public function headerDone() { |
| 201 |
return $this->headerDone; |
| 202 |
} |
| 203 |
|
| 204 |
public function outputHeader() { |
| 205 |
$this->headerDone = true; |
| 206 |
$this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' ); |
| 207 |
$this->parent->request->response()->header( 'X-Frame-Options: DENY' ); |
| 208 |
|
| 209 |
if ( $this->redirectTarget ) { |
| 210 |
$this->parent->request->response()->header( 'Location: ' . $this->redirectTarget ); |
| 211 |
|
| 212 |
return; |
| 213 |
} |
| 214 |
?> |
| 215 |
<?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> |
| 216 |
|
| 217 |
<head> |
| 218 |
<meta name="robots" content="noindex, nofollow" /> |
| 219 |
<meta http-equiv="Content-type" content="text/html; charset=utf-8" /> |
| 220 |
<title><?php $this->outputTitle(); ?></title> |
| 221 |
<?php echo $this->getCodex() . "\n"; ?> |
| 222 |
<?php echo $this->getCssUrl() . "\n"; ?> |
| 223 |
<?php echo $this->getJQuery() . "\n"; ?> |
| 224 |
<?php echo Html::linkedScript( 'config.js' ) . "\n"; ?> |
| 225 |
</head> |
| 226 |
|
| 227 |
<?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?> |
| 228 |
<div id="mw-page-base"></div> |
| 229 |
<div id="mw-head-base"></div> |
| 230 |
<div id="content" class="mw-body" role="main"> |
| 231 |
<div id="bodyContent" class="mw-body-content"> |
| 232 |
|
| 233 |
<h1><?php $this->outputTitle(); ?></h1> |
| 234 |
<?php |
| 235 |
} |
| 236 |
|
| 237 |
public function outputFooter() { |
| 238 |
?> |
| 239 |
|
| 240 |
</div></div> |
| 241 |
|
| 242 |
<aside id="mw-panel"> |
| 243 |
<div class="portal" id="p-logo"> |
| 244 |
<a href="https://www.mediawiki.org/" title="Main Page"></a> |
| 245 |
</div> |
| 246 |
<?php |
| 247 |
|
| 248 |
$message = wfMessage( 'config-sidebar' )->plain(); |
| 249 |
|
| 250 |
|
| 251 |
foreach ( explode( '----', $message ) as $section ) { |
| 252 |
echo '<div class="portal"><div class="body">'; |
| 253 |
echo $this->parent->parse( $section, true ); |
| 254 |
echo '</div></div>'; |
| 255 |
} |
| 256 |
|
| 257 |
echo '<div class="portal"><div class="body"><ul>'; |
| 258 |
foreach ( [ |
| 259 |
'config-sidebar-relnotes' => 'ReleaseNotes', |
| 260 |
'config-sidebar-license' => 'Copying', |
| 261 |
'config-sidebar-upgrade' => 'UpgradeDoc', |
| 262 |
] as $msgKey => $pageName ) { |
| 263 |
echo $this->parent->makeLinkItem( |
| 264 |
$this->parent->getDocUrl( $pageName ), |
| 265 |
wfMessage( $msgKey )->text() |
| 266 |
); |
| 267 |
} |
| 268 |
echo '</ul></div></div>'; |
| 269 |
|
| 270 |
?> |
| 271 |
</aside> |
| 272 |
|
| 273 |
<?php |
| 274 |
echo Html::closeElement( 'body' ) . Html::closeElement( 'html' ); |
| 275 |
} |
| 276 |
|
| 277 |
public function outputTitle() { |
| 278 |
echo wfMessage( 'config-title', MW_VERSION )->escaped(); |
| 279 |
} |
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
public function getJQuery() { |
| 285 |
return Html::linkedScript( "../resources/lib/jquery/jquery.js" ); |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
public function getCodex() { |
| 292 |
return Html::linkedStyle( "../resources/lib/codex/codex.style.css" ); |
| 293 |
} |
| 294 |
|
| 295 |
} |