MediaWiki  master
WebInstallerOutput.php
Go to the documentation of this file.
1 <?php
27 
41 
47  public $parent;
48 
53  private $contents = '';
54 
59  private $headerDone = false;
60 
65 
72  public $allowFrames = false;
73 
78  private $useShortHeader = false;
79 
83  public function __construct( WebInstaller $parent ) {
84  $this->parent = $parent;
85  }
86 
90  public function addHTML( $html ) {
91  $this->contents .= $html;
92  $this->flush();
93  }
94 
99  public function addWikiTextAsInterface( $text ) {
100  $this->addHTML( $this->parent->parse( $text ) );
101  }
102 
106  public function addHTMLNoFlush( $html ) {
107  $this->contents .= $html;
108  }
109 
115  public function redirect( $url ) {
116  if ( $this->headerDone ) {
117  throw new MWException( __METHOD__ . ' called after sending headers' );
118  }
119  $this->redirectTarget = $url;
120  }
121 
122  public function output() {
123  $this->flush();
124 
125  if ( !$this->redirectTarget ) {
126  $this->outputFooter();
127  }
128  }
129 
135  public function getCSS() {
136  $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
137 
138  $rlContext = new RL\Context( $resourceLoader, new FauxRequest( [
139  'debug' => 'true',
140  'lang' => $this->getLanguage()->getCode(),
141  'only' => 'styles',
142  ] ) );
143 
144  $module = new RL\SkinModule( [
145  'features' => [
146  'elements',
147  'interface-message-box'
148  ],
149  'styles' => [
150  'mw-config/config.css',
151  ],
152  ] );
153  $module->setConfig( $resourceLoader->getConfig() );
154 
155  // Based on MediaWiki\ResourceLoader\FileModule::getStyles, without the DB query
156  $styles = ResourceLoader::makeCombinedStyles(
157  $module->readStyleFiles(
158  $module->getStyleFiles( $rlContext ),
159  $rlContext
160  ) );
161 
162  return implode( "\n", $styles );
163  }
164 
170  private function getCssUrl() {
171  return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
172  }
173 
174  public function useShortHeader( $use = true ) {
175  $this->useShortHeader = $use;
176  }
177 
178  public function allowFrames( $allow = true ) {
179  $this->allowFrames = $allow;
180  }
181 
182  public function flush() {
183  if ( !$this->headerDone ) {
184  $this->outputHeader();
185  }
186  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
187  echo $this->contents;
188  flush();
189  $this->contents = '';
190  }
191  }
192 
197  private function getLanguage() {
198  global $wgLang;
199 
200  return is_object( $wgLang ) ? $wgLang
201  : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
202  }
203 
207  public function getHeadAttribs() {
208  return [
209  'dir' => $this->getLanguage()->getDir(),
210  'lang' => $this->getLanguage()->getHtmlCode(),
211  ];
212  }
213 
219  public function headerDone() {
220  return $this->headerDone;
221  }
222 
223  public function outputHeader() {
224  $this->headerDone = true;
225  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
226 
227  if ( !$this->allowFrames ) {
228  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
229  }
230 
231  if ( $this->redirectTarget ) {
232  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
233 
234  return;
235  }
236 
237  if ( $this->useShortHeader ) {
238  $this->outputShortHeader();
239 
240  return;
241  }
242 
243 ?>
244 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
245 
246 <head>
247  <meta name="robots" content="noindex, nofollow" />
248  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
249  <title><?php $this->outputTitle(); ?></title>
250  <?php echo $this->getCssUrl() . "\n"; ?>
251  <?php echo $this->getJQuery() . "\n"; ?>
252  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
253 </head>
254 
255 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
256 <div id="mw-page-base"></div>
257 <div id="mw-head-base"></div>
258 <div id="content" class="mw-body" role="main">
259 <div id="bodyContent" class="mw-body-content">
260 
261 <h1><?php $this->outputTitle(); ?></h1>
262 <?php
263  }
264 
265  public function outputFooter() {
266  if ( $this->useShortHeader ) {
267  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
268 
269  return;
270  }
271 ?>
272 
273 </div></div>
274 
275 <div id="mw-panel">
276  <div class="portal" id="p-logo">
277  <a href="https://www.mediawiki.org/" title="Main Page"></a>
278  </div>
279 <?php
280  $message = wfMessage( 'config-sidebar' )->plain();
281  // Section 1: External links
282  // @todo FIXME: Migrate to plain link label messages (T227297).
283  foreach ( explode( '----', $message ) as $section ) {
284  echo '<div class="portal"><div class="body">';
285  echo $this->parent->parse( $section, true );
286  echo '</div></div>';
287  }
288  // Section 2: Installer pages
289  echo '<div class="portal"><div class="body"><ul>';
290  foreach ( [
291  'config-sidebar-relnotes' => 'ReleaseNotes',
292  'config-sidebar-license' => 'Copying',
293  'config-sidebar-upgrade' => 'UpgradeDoc',
294  ] as $msgKey => $pageName ) {
295  echo $this->parent->makeLinkItem(
296  $this->parent->getDocUrl( $pageName ),
297  wfMessage( $msgKey )->text()
298  );
299  }
300  echo '</ul></div></div>';
301 ?>
302 </div>
303 
304 <?php
305  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
306  }
307 
308  public function outputShortHeader() {
309 ?>
310 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
311 
312 <head>
313  <meta name="robots" content="noindex, nofollow" />
314  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
315  <title><?php $this->outputTitle(); ?></title>
316  <?php echo $this->getCssUrl() . "\n"; ?>
317  <?php echo $this->getJQuery() . "\n"; ?>
318  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
319 </head>
320 
321 <body style="background-image: none">
322 <?php
323  }
324 
325  public function outputTitle() {
326  echo wfMessage( 'config-title', MW_VERSION )->escaped();
327  }
328 
332  public function getJQuery() {
333  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
334  }
335 
336 }
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:497
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:37
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:617
static linkedStyle( $url, $media='all')
Output a "<link rel=stylesheet>" linking to the given URL for the given media type (if any).
Definition: Html.php:669
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:1014
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:256
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:320
MediaWiki exception.
Definition: MWException.php:29
Service locator for MediaWiki core services.
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: Context.php:46
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.