MediaWiki  master
WebInstallerOutput.php
Go to the documentation of this file.
1 <?php
25 
39 
45  public $parent;
46 
51  private $contents = '';
52 
57  private $headerDone = false;
58 
63 
70  public $allowFrames = false;
71 
76  private $useShortHeader = false;
77 
81  public function __construct( WebInstaller $parent ) {
82  $this->parent = $parent;
83  }
84 
88  public function addHTML( $html ) {
89  $this->contents .= $html;
90  $this->flush();
91  }
92 
97  public function addWikiTextAsInterface( $text ) {
98  $this->addHTML( $this->parent->parse( $text ) );
99  }
100 
104  public function addHTMLNoFlush( $html ) {
105  $this->contents .= $html;
106  }
107 
113  public function redirect( $url ) {
114  if ( $this->headerDone ) {
115  throw new MWException( __METHOD__ . ' called after sending headers' );
116  }
117  $this->redirectTarget = $url;
118  }
119 
120  public function output() {
121  $this->flush();
122 
123  if ( !$this->redirectTarget ) {
124  $this->outputFooter();
125  }
126  }
127 
133  public function getCSS() {
134  $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
135 
136  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
137  'debug' => 'true',
138  'lang' => $this->getLanguage()->getCode(),
139  'only' => 'styles',
140  ] ) );
141 
142  $module = new ResourceLoaderSkinModule( [
143  'features' => [
144  'elements',
145  'interface-message-box'
146  ],
147  'styles' => [
148  'mw-config/config.css',
149  ],
150  ] );
151  $module->setConfig( $resourceLoader->getConfig() );
152 
153  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
155  $module->readStyleFiles(
156  $module->getStyleFiles( $rlContext ),
157  $rlContext
158  ) );
159 
160  return implode( "\n", $styles );
161  }
162 
168  private function getCssUrl() {
169  return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
170  }
171 
172  public function useShortHeader( $use = true ) {
173  $this->useShortHeader = $use;
174  }
175 
176  public function allowFrames( $allow = true ) {
177  $this->allowFrames = $allow;
178  }
179 
180  public function flush() {
181  if ( !$this->headerDone ) {
182  $this->outputHeader();
183  }
184  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
185  echo $this->contents;
186  flush();
187  $this->contents = '';
188  }
189  }
190 
195  private function getLanguage() {
196  global $wgLang;
197 
198  return is_object( $wgLang ) ? $wgLang
199  : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
200  }
201 
205  public function getHeadAttribs() {
206  return [
207  'dir' => $this->getLanguage()->getDir(),
208  'lang' => $this->getLanguage()->getHtmlCode(),
209  ];
210  }
211 
217  public function headerDone() {
218  return $this->headerDone;
219  }
220 
221  public function outputHeader() {
222  $this->headerDone = true;
223  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
224 
225  if ( !$this->allowFrames ) {
226  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
227  }
228 
229  if ( $this->redirectTarget ) {
230  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
231 
232  return;
233  }
234 
235  if ( $this->useShortHeader ) {
236  $this->outputShortHeader();
237 
238  return;
239  }
240 
241 ?>
242 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
243 
244 <head>
245  <meta name="robots" content="noindex, nofollow" />
246  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
247  <title><?php $this->outputTitle(); ?></title>
248  <?php echo $this->getCssUrl() . "\n"; ?>
249  <?php echo $this->getJQuery() . "\n"; ?>
250  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
251 </head>
252 
253 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
254 <div id="mw-page-base"></div>
255 <div id="mw-head-base"></div>
256 <div id="content" class="mw-body" role="main">
257 <div id="bodyContent" class="mw-body-content">
258 
259 <h1><?php $this->outputTitle(); ?></h1>
260 <?php
261  }
262 
263  public function outputFooter() {
264  if ( $this->useShortHeader ) {
265  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
266 
267  return;
268  }
269 ?>
270 
271 </div></div>
272 
273 <div id="mw-panel">
274  <div class="portal" id="p-logo">
275  <a href="https://www.mediawiki.org/" title="Main Page"></a>
276  </div>
277 <?php
278  $message = wfMessage( 'config-sidebar' )->plain();
279  // Section 1: External links
280  // @todo FIXME: Migrate to plain link label messages (T227297).
281  foreach ( explode( '----', $message ) as $section ) {
282  echo '<div class="portal"><div class="body">';
283  echo $this->parent->parse( $section, true );
284  echo '</div></div>';
285  }
286  // Section 2: Installer pages
287  echo '<div class="portal"><div class="body"><ul>';
288  foreach ( [
289  'config-sidebar-relnotes' => 'ReleaseNotes',
290  'config-sidebar-license' => 'Copying',
291  'config-sidebar-upgrade' => 'UpgradeDoc',
292  ] as $msgKey => $pageName ) {
293  echo $this->parent->makeLinkItem(
294  $this->parent->getDocUrl( $pageName ),
295  wfMessage( $msgKey )->text()
296  );
297  }
298  echo '</ul></div></div>';
299 ?>
300 </div>
301 
302 <?php
303  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
304  }
305 
306  public function outputShortHeader() {
307 ?>
308 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
309 
310 <head>
311  <meta name="robots" content="noindex, nofollow" />
312  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
313  <title><?php $this->outputTitle(); ?></title>
314  <?php echo $this->getCssUrl() . "\n"; ?>
315  <?php echo $this->getJQuery() . "\n"; ?>
316  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
317 </head>
318 
319 <body style="background-image: none">
320 <?php
321  }
322 
323  public function outputTitle() {
324  echo wfMessage( 'config-title', MW_VERSION )->escaped();
325  }
326 
330  public function getJQuery() {
331  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
332  }
333 
334 }
WebInstallerOutput\addHTMLNoFlush
addHTMLNoFlush( $html)
Definition: WebInstallerOutput.php:104
ResourceLoaderContext
Context object that contains information about the state of a specific ResourceLoader web request.
Definition: ResourceLoaderContext.php:34
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:35
WebInstallerOutput\redirect
redirect( $url)
Definition: WebInstallerOutput.php:113
WebInstallerOutput\$useShortHeader
bool $useShortHeader
Whether to use the limited header (used during CC license callbacks)
Definition: WebInstallerOutput.php:76
WebInstallerOutput\$headerDone
bool $headerDone
Has the header (or short header) been output?
Definition: WebInstallerOutput.php:57
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:200
WebInstallerOutput\getCssUrl
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
Definition: WebInstallerOutput.php:168
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:32
MW_VERSION
const MW_VERSION
The running version of MediaWiki.
Definition: Defines.php:36
WebInstallerOutput\outputHeader
outputHeader()
Definition: WebInstallerOutput.php:221
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:994
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1175
WebInstallerOutput\outputFooter
outputFooter()
Definition: WebInstallerOutput.php:263
$wgLang
$wgLang
Definition: Setup.php:834
WebInstallerOutput\getCSS
getCSS()
Get the stylesheet of the MediaWiki skin.
Definition: WebInstallerOutput.php:133
WebInstallerOutput\__construct
__construct(WebInstaller $parent)
Definition: WebInstallerOutput.php:81
WebInstallerOutput
Output class modelled on OutputPage.
Definition: WebInstallerOutput.php:38
WebInstallerOutput\getJQuery
getJQuery()
Definition: WebInstallerOutput.php:330
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:316
WebInstallerOutput\headerDone
headerDone()
Get whether the header has been output.
Definition: WebInstallerOutput.php:217
Html\linkedScript
static linkedScript( $url, $nonce=null)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:613
WebInstallerOutput\$contents
string $contents
Buffered contents that haven't been output yet.
Definition: WebInstallerOutput.php:51
MWException
MediaWiki exception.
Definition: MWException.php:29
WebInstallerOutput\$redirectTarget
string $redirectTarget
Definition: WebInstallerOutput.php:62
WebInstallerOutput\$parent
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
Definition: WebInstallerOutput.php:45
WebInstallerOutput\allowFrames
allowFrames( $allow=true)
Definition: WebInstallerOutput.php:176
WebInstallerOutput\outputShortHeader
outputShortHeader()
Definition: WebInstallerOutput.php:306
ResourceLoader\makeCombinedStyles
static makeCombinedStyles(array $stylePairs)
Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks...
Definition: ResourceLoader.php:1368
WebInstallerOutput\useShortHeader
useShortHeader( $use=true)
Definition: WebInstallerOutput.php:172
WebInstallerOutput\addWikiTextAsInterface
addWikiTextAsInterface( $text)
Definition: WebInstallerOutput.php:97
WebInstallerOutput\getHeadAttribs
getHeadAttribs()
Definition: WebInstallerOutput.php:205
WebInstallerOutput\outputTitle
outputTitle()
Definition: WebInstallerOutput.php:323
Html\linkedStyle
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:665
WebInstallerOutput\$allowFrames
bool $allowFrames
Does the current page need to allow being used as a frame? If not, X-Frame-Options will be output to ...
Definition: WebInstallerOutput.php:70
Html\openElement
static openElement( $element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:252
WebInstallerOutput\getLanguage
getLanguage()
Definition: WebInstallerOutput.php:195
WebInstallerOutput\output
output()
Definition: WebInstallerOutput.php:120
WebInstallerOutput\flush
flush()
Definition: WebInstallerOutput.php:180
WebInstallerOutput\addHTML
addHTML( $html)
Definition: WebInstallerOutput.php:88
ResourceLoaderSkinModule
Module for skin stylesheets.
Definition: ResourceLoaderSkinModule.php:28