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  $moduleNames = [
135  'mediawiki.skinning.interface',
136  'mediawiki.legacy.config'
137  ];
138 
139  $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
140 
141  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
142  'debug' => 'true',
143  'lang' => $this->getLanguage()->getCode(),
144  'only' => 'styles',
145  ] ) );
146 
147  $styles = [];
148  foreach ( $moduleNames as $moduleName ) {
150  $module = $resourceLoader->getModule( $moduleName );
151  '@phan-var ResourceLoaderFileModule $module';
152  if ( !$module ) {
153  // T98043: Don't fatal, but it won't look as pretty.
154  continue;
155  }
156 
157  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
158  $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
159  $module->readStyleFiles(
160  $module->getStyleFiles( $rlContext ),
161  $rlContext
162  ) ) );
163  }
164 
165  return implode( "\n", $styles );
166  }
167 
173  private function getCssUrl() {
174  return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
175  }
176 
177  public function useShortHeader( $use = true ) {
178  $this->useShortHeader = $use;
179  }
180 
181  public function allowFrames( $allow = true ) {
182  $this->allowFrames = $allow;
183  }
184 
185  public function flush() {
186  if ( !$this->headerDone ) {
187  $this->outputHeader();
188  }
189  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
190  echo $this->contents;
191  flush();
192  $this->contents = '';
193  }
194  }
195 
200  private function getLanguage() {
201  global $wgLang;
202 
203  return is_object( $wgLang ) ? $wgLang
204  : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' );
205  }
206 
210  public function getHeadAttribs() {
211  return [
212  'dir' => $this->getLanguage()->getDir(),
213  'lang' => $this->getLanguage()->getHtmlCode(),
214  ];
215  }
216 
222  public function headerDone() {
223  return $this->headerDone;
224  }
225 
226  public function outputHeader() {
227  $this->headerDone = true;
228  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
229 
230  if ( !$this->allowFrames ) {
231  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
232  }
233 
234  if ( $this->redirectTarget ) {
235  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
236 
237  return;
238  }
239 
240  if ( $this->useShortHeader ) {
241  $this->outputShortHeader();
242 
243  return;
244  }
245 
246 ?>
247 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
248 
249 <head>
250  <meta name="robots" content="noindex, nofollow" />
251  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
252  <title><?php $this->outputTitle(); ?></title>
253  <?php echo $this->getCssUrl() . "\n"; ?>
254  <?php echo $this->getJQuery() . "\n"; ?>
255  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
256 </head>
257 
258 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
259 <div id="mw-page-base"></div>
260 <div id="mw-head-base"></div>
261 <div id="content" class="mw-body" role="main">
262 <div id="bodyContent" class="mw-body-content">
263 
264 <h1><?php $this->outputTitle(); ?></h1>
265 <?php
266  }
267 
268  public function outputFooter() {
269  if ( $this->useShortHeader ) {
270  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
271 
272  return;
273  }
274 ?>
275 
276 </div></div>
277 
278 <div id="mw-panel">
279  <div class="portal" id="p-logo">
280  <a href="https://www.mediawiki.org/" title="Main Page"></a>
281  </div>
282 <?php
283  $message = wfMessage( 'config-sidebar' )->plain();
284  // Section 1: External links
285  // @todo FIXME: Migrate to plain link label messages (T227297).
286  foreach ( explode( '----', $message ) as $section ) {
287  echo '<div class="portal"><div class="body">';
288  echo $this->parent->parse( $section, true );
289  echo '</div></div>';
290  }
291  // Section 2: Installer pages
292  echo '<div class="portal"><div class="body"><ul>';
293  foreach ( [
294  'config-sidebar-readme' => 'Readme',
295  'config-sidebar-relnotes' => 'ReleaseNotes',
296  'config-sidebar-license' => 'Copying',
297  'config-sidebar-upgrade' => 'UpgradeDoc',
298  ] as $msgKey => $pageName ) {
299  echo $this->parent->makeLinkItem(
300  $this->parent->getDocUrl( $pageName ),
301  wfMessage( $msgKey )->text()
302  );
303  }
304  echo '</ul></div></div>';
305 ?>
306 </div>
307 
308 <?php
309  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
310  }
311 
312  public function outputShortHeader() {
313 ?>
314 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
315 
316 <head>
317  <meta name="robots" content="noindex, nofollow" />
318  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
319  <title><?php $this->outputTitle(); ?></title>
320  <?php echo $this->getCssUrl() . "\n"; ?>
321  <?php echo $this->getJQuery() . "\n"; ?>
322  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
323 </head>
324 
325 <body style="background-image: none">
326 <?php
327  }
328 
329  public function outputTitle() {
330  echo wfMessage( 'config-title', MW_VERSION )->escaped();
331  }
332 
336  public function getJQuery() {
337  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
338  }
339 
340 }
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:33
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
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:149
WebInstallerOutput\getCssUrl
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
Definition: WebInstallerOutput.php:173
$resourceLoader
$resourceLoader
Definition: load.php:42
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:39
WebInstallerOutput\outputHeader
outputHeader()
Definition: WebInstallerOutput.php:226
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:965
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1198
WebInstallerOutput\outputFooter
outputFooter()
Definition: WebInstallerOutput.php:268
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:336
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:315
WebInstallerOutput\headerDone
headerDone()
Get whether the header has been output.
Definition: WebInstallerOutput.php:222
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:596
WebInstallerOutput\$contents
string $contents
Buffered contents that haven't been output yet.
Definition: WebInstallerOutput.php:51
MWException
MediaWiki exception.
Definition: MWException.php:26
WebInstallerOutput\$redirectTarget
string $redirectTarget
Definition: WebInstallerOutput.php:62
WebInstallerOutput\$parent
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
Definition: WebInstallerOutput.php:45
$wgLang
$wgLang
Definition: Setup.php:781
WebInstallerOutput\allowFrames
allowFrames( $allow=true)
Definition: WebInstallerOutput.php:181
WebInstallerOutput\outputShortHeader
outputShortHeader()
Definition: WebInstallerOutput.php:312
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:1416
WebInstallerOutput\useShortHeader
useShortHeader( $use=true)
Definition: WebInstallerOutput.php:177
WebInstallerOutput\addWikiTextAsInterface
addWikiTextAsInterface( $text)
Definition: WebInstallerOutput.php:97
WebInstallerOutput\getHeadAttribs
getHeadAttribs()
Definition: WebInstallerOutput.php:210
WebInstallerOutput\outputTitle
outputTitle()
Definition: WebInstallerOutput.php:329
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:648
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:251
WebInstallerOutput\getLanguage
getLanguage()
Definition: WebInstallerOutput.php:200
WebInstallerOutput\output
output()
Definition: WebInstallerOutput.php:120
WebInstallerOutput\flush
flush()
Definition: WebInstallerOutput.php:185
WebInstallerOutput\addHTML
addHTML( $html)
Definition: WebInstallerOutput.php:88