MediaWiki  master
WebInstallerOutput.php
Go to the documentation of this file.
1 <?php
29 
43 
49  public $parent;
50 
55  private $contents = '';
56 
61  private $headerDone = false;
62 
67 
74  public $allowFrames = false;
75 
80  private $useShortHeader = false;
81 
85  public function __construct( WebInstaller $parent ) {
86  $this->parent = $parent;
87  }
88 
92  public function addHTML( $html ) {
93  $this->contents .= $html;
94  $this->flush();
95  }
96 
101  public function addWikiTextAsInterface( $text ) {
102  $this->addHTML( $this->parent->parse( $text ) );
103  }
104 
108  public function addHTMLNoFlush( $html ) {
109  $this->contents .= $html;
110  }
111 
117  public function redirect( $url ) {
118  if ( $this->headerDone ) {
119  throw new MWException( __METHOD__ . ' called after sending headers' );
120  }
121  $this->redirectTarget = $url;
122  }
123 
124  public function output() {
125  $this->flush();
126 
127  if ( !$this->redirectTarget ) {
128  $this->outputFooter();
129  }
130  }
131 
137  public function getCSS() {
138  $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
139 
140  $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [
141  'debug' => 'true',
142  'lang' => $this->getLanguage()->getCode(),
143  'only' => 'styles',
144  ] ) );
145 
146  $module = new RL\SkinModule( [
147  'features' => [
148  'elements',
149  'interface-message-box'
150  ],
151  'styles' => [
152  'mw-config/config.css',
153  ],
154  ] );
155  $module->setConfig( $resourceLoader->getConfig() );
156 
157  // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query
158  $styles = ResourceLoader::makeCombinedStyles(
159  $module->readStyleFiles(
160  $module->getStyleFiles( $rlContext ),
161  $rlContext
162  ) );
163 
164  return implode( "\n", $styles );
165  }
166 
172  private function getCssUrl() {
173  return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
174  }
175 
176  public function useShortHeader( $use = true ) {
177  $this->useShortHeader = $use;
178  }
179 
180  public function allowFrames( $allow = true ) {
181  $this->allowFrames = $allow;
182  }
183 
184  public function flush() {
185  if ( !$this->headerDone ) {
186  $this->outputHeader();
187  }
188  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
189  echo $this->contents;
190  flush();
191  $this->contents = '';
192  }
193  }
194 
199  private function getLanguage() {
200  global $wgLang;
201 
202  return is_object( $wgLang ) ? $wgLang
203  : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
204  }
205 
209  public function getHeadAttribs() {
210  return [
211  'dir' => $this->getLanguage()->getDir(),
212  'lang' => $this->getLanguage()->getHtmlCode(),
213  ];
214  }
215 
221  public function headerDone() {
222  return $this->headerDone;
223  }
224 
225  public function outputHeader() {
226  $this->headerDone = true;
227  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
228 
229  if ( !$this->allowFrames ) {
230  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
231  }
232 
233  if ( $this->redirectTarget ) {
234  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
235 
236  return;
237  }
238 
239  if ( $this->useShortHeader ) {
240  $this->outputShortHeader();
241 
242  return;
243  }
244 
245 ?>
246 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
247 
248 <head>
249  <meta name="robots" content="noindex, nofollow" />
250  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
251  <title><?php $this->outputTitle(); ?></title>
252  <?php echo $this->getCssUrl() . "\n"; ?>
253  <?php echo $this->getJQuery() . "\n"; ?>
254  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
255 </head>
256 
257 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
258 <div id="mw-page-base"></div>
259 <div id="mw-head-base"></div>
260 <div id="content" class="mw-body" role="main">
261 <div id="bodyContent" class="mw-body-content">
262 
263 <h1><?php $this->outputTitle(); ?></h1>
264 <?php
265  }
266 
267  public function outputFooter() {
268  if ( $this->useShortHeader ) {
269  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
270 
271  return;
272  }
273 ?>
274 
275 </div></div>
276 
277 <div id="mw-panel">
278  <div class="portal" id="p-logo">
279  <a href="https://www.mediawiki.org/" title="Main Page"></a>
280  </div>
281 <?php
282  $message = wfMessage( 'config-sidebar' )->plain();
283  // Section 1: External links
284  // @todo FIXME: Migrate to plain link label messages (T227297).
285  foreach ( explode( '----', $message ) as $section ) {
286  echo '<div class="portal"><div class="body">';
287  echo $this->parent->parse( $section, true );
288  echo '</div></div>';
289  }
290  // Section 2: Installer pages
291  echo '<div class="portal"><div class="body"><ul>';
292  foreach ( [
293  'config-sidebar-relnotes' => 'ReleaseNotes',
294  'config-sidebar-license' => 'Copying',
295  'config-sidebar-upgrade' => 'UpgradeDoc',
296  ] as $msgKey => $pageName ) {
297  echo $this->parent->makeLinkItem(
298  $this->parent->getDocUrl( $pageName ),
299  wfMessage( $msgKey )->text()
300  );
301  }
302  echo '</ul></div></div>';
303 ?>
304 </div>
305 
306 <?php
307  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
308  }
309 
310  public function outputShortHeader() {
311 ?>
312 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
313 
314 <head>
315  <meta name="robots" content="noindex, nofollow" />
316  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
317  <title><?php $this->outputTitle(); ?></title>
318  <?php echo $this->getCssUrl() . "\n"; ?>
319  <?php echo $this->getJQuery() . "\n"; ?>
320  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
321 </head>
322 
323 <body style="background-image: none">
324 <?php
325  }
326 
327  public function outputTitle() {
328  echo wfMessage( 'config-title', MW_VERSION )->escaped();
329  }
330 
334  public function getJQuery() {
335  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
336  }
337 
338 }
const MW_VERSION
The running version of MediaWiki.
Definition: Defines.php:36
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
Definition: Setup.php:535
MediaWiki exception.
Definition: MWException.php:33
This class is a collection of static functions that serve two purposes:
Definition: Html.php:57
Service locator for MediaWiki core services.
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:42
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: Context.php:45
ResourceLoader is a loading system for JavaScript and CSS resources.
Module for skin stylesheets.
Definition: SkinModule.php:35
Output class modelled on OutputPage.
__construct(WebInstaller $parent)
getCSS()
Get the stylesheet of the MediaWiki skin.
bool $allowFrames
Does the current page need to allow being used as a frame? If not, X-Frame-Options will be output to ...
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
headerDone()
Get whether the header has been output.
Class for the core installer web interface.