MediaWiki  REL1_31
WebInstallerOutput.php
Go to the documentation of this file.
1 <?php
36 
42  public $parent;
43 
48  private $contents = '';
49 
54  private $headerDone = false;
55 
60 
67  public $allowFrames = false;
68 
73  private $useShortHeader = false;
74 
78  public function __construct( WebInstaller $parent ) {
79  $this->parent = $parent;
80  }
81 
85  public function addHTML( $html ) {
86  $this->contents .= $html;
87  $this->flush();
88  }
89 
93  public function addWikiText( $text ) {
94  $this->addHTML( $this->parent->parse( $text ) );
95  }
96 
100  public function addHTMLNoFlush( $html ) {
101  $this->contents .= $html;
102  }
103 
109  public function redirect( $url ) {
110  if ( $this->headerDone ) {
111  throw new MWException( __METHOD__ . ' called after sending headers' );
112  }
113  $this->redirectTarget = $url;
114  }
115 
116  public function output() {
117  $this->flush();
118 
119  if ( !$this->redirectTarget ) {
120  $this->outputFooter();
121  }
122  }
123 
129  public function getCSS() {
131 
132  $moduleNames = [
133  // See SkinTemplate::setupSkinUserCss
134  'mediawiki.legacy.shared',
135  // See Vector::setupSkinUserCss
136  'mediawiki.skinning.interface',
137  ];
138 
140 
141  if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
142  // Force loading Vector skin if available as a fallback skin
143  // for whatever ResourceLoader wants to have as the default.
144  $registry = new ExtensionRegistry();
145  $data = $registry->readFromQueue( [
146  "$wgStyleDirectory/Vector/skin.json" => 1,
147  ] );
148  if ( isset( $data['globals']['wgResourceModules'] ) ) {
149  $resourceLoader->register( $data['globals']['wgResourceModules'] );
150  }
151 
152  $moduleNames[] = 'skins.vector.styles';
153  }
154 
155  $moduleNames[] = 'mediawiki.legacy.config';
156 
157  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
158  'debug' => 'true',
159  'lang' => $this->getLanguageCode(),
160  'only' => 'styles',
161  ] ) );
162 
163  $styles = [];
164  foreach ( $moduleNames as $moduleName ) {
166  $module = $resourceLoader->getModule( $moduleName );
167  if ( !$module ) {
168  // T98043: Don't fatal, but it won't look as pretty.
169  continue;
170  }
171 
172  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
173  $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
174  $module->readStyleFiles(
175  $module->getStyleFiles( $rlContext ),
176  $module->getFlip( $rlContext ),
177  $rlContext
178  ) ) );
179  }
180 
181  return implode( "\n", $styles );
182  }
183 
189  private function getCssUrl() {
190  return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
191  }
192 
193  public function useShortHeader( $use = true ) {
194  $this->useShortHeader = $use;
195  }
196 
197  public function allowFrames( $allow = true ) {
198  $this->allowFrames = $allow;
199  }
200 
201  public function flush() {
202  if ( !$this->headerDone ) {
203  $this->outputHeader();
204  }
205  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
206  echo $this->contents;
207  flush();
208  $this->contents = '';
209  }
210  }
211 
215  public function getDir() {
216  global $wgLang;
217 
218  return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
219  }
220 
224  public function getLanguageCode() {
225  global $wgLang;
226 
227  return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
228  }
229 
233  public function getHeadAttribs() {
234  return [
235  'dir' => $this->getDir(),
236  'lang' => LanguageCode::bcp47( $this->getLanguageCode() ),
237  ];
238  }
239 
245  public function headerDone() {
246  return $this->headerDone;
247  }
248 
249  public function outputHeader() {
250  $this->headerDone = true;
251  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
252 
253  if ( !$this->allowFrames ) {
254  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
255  }
256 
257  if ( $this->redirectTarget ) {
258  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
259 
260  return;
261  }
262 
263  if ( $this->useShortHeader ) {
264  $this->outputShortHeader();
265 
266  return;
267  }
268 ?>
269 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
270 
271 <head>
272  <meta name="robots" content="noindex, nofollow" />
273  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
274  <title><?php $this->outputTitle(); ?></title>
275  <?php echo $this->getCssUrl() . "\n"; ?>
276  <?php echo $this->getJQuery() . "\n"; ?>
277  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
278 </head>
279 
280 <?php echo Html::openElement( 'body', [ 'class' => $this->getDir() ] ) . "\n"; ?>
281 <div id="mw-page-base"></div>
282 <div id="mw-head-base"></div>
283 <div id="content" class="mw-body">
284 <div id="bodyContent" class="mw-body-content">
285 
286 <h1><?php $this->outputTitle(); ?></h1>
287 <?php
288  }
289 
290  public function outputFooter() {
291  if ( $this->useShortHeader ) {
292  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
293 
294  return;
295  }
296 ?>
297 
298 </div></div>
299 
300 <div id="mw-panel">
301  <div class="portal" id="p-logo">
302  <a style="background-image: url(images/installer-logo.png);"
303  href="https://www.mediawiki.org/"
304  title="Main Page"></a>
305  </div>
306 <?php
307  $message = wfMessage( 'config-sidebar' )->plain();
308  foreach ( explode( '----', $message ) as $section ) {
309  echo '<div class="portal"><div class="body">';
310  echo $this->parent->parse( $section, true );
311  echo '</div></div>';
312  }
313 ?>
314 </div>
315 
316 <?php
317  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
318  }
319 
320  public function outputShortHeader() {
321 ?>
322 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
323 <head>
324  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
325  <meta name="robots" content="noindex, nofollow" />
326  <title><?php $this->outputTitle(); ?></title>
327  <?php echo $this->getCssUrl() . "\n"; ?>
328  <?php echo $this->getJQuery(); ?>
329  <?php echo Html::linkedScript( 'config.js' ); ?>
330 </head>
331 
332 <body style="background-image: none">
333 <?php
334  }
335 
336  public function outputTitle() {
338  echo wfMessage( 'config-title', $wgVersion )->escaped();
339  }
340 
344  public function getJQuery() {
345  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
346  }
347 
348 }
WebInstallerOutput\addHTMLNoFlush
addHTMLNoFlush( $html)
Definition: WebInstallerOutput.php:100
ResourceLoaderContext
Object passed around to modules which contains information about the state of a specific loader reque...
Definition: ResourceLoaderContext.php:32
FauxRequest
WebRequest clone which takes values from a provided array.
Definition: FauxRequest.php:33
WebInstallerOutput\addWikiText
addWikiText( $text)
Definition: WebInstallerOutput.php:93
WebInstallerOutput\redirect
redirect( $url)
Definition: WebInstallerOutput.php:109
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
$html
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:2013
WebInstallerOutput\$useShortHeader
bool $useShortHeader
Whether to use the limited header (used during CC license callbacks)
Definition: WebInstallerOutput.php:73
WebInstallerOutput\$headerDone
bool $headerDone
Has the header (or short header) been output?
Definition: WebInstallerOutput.php:54
wfMessage
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "&lt
WebInstallerOutput\getCssUrl
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
Definition: WebInstallerOutput.php:189
ExtensionRegistry
ExtensionRegistry class.
Definition: ExtensionRegistry.php:14
$wgVersion
$wgVersion
MediaWiki version number.
Definition: DefaultSettings.php:75
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:30
WebInstallerOutput\outputHeader
outputHeader()
Definition: WebInstallerOutput.php:249
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:935
WebInstallerOutput\outputFooter
outputFooter()
Definition: WebInstallerOutput.php:290
http
Apache License January http
Definition: APACHE-LICENSE-2.0.txt:6
$resourceLoader
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction you ll probably need to make sure the header is varied on and they can depend only on the ResourceLoaderContext such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition: hooks.txt:2818
WebInstallerOutput\getCSS
getCSS()
Get the stylesheet of the MediaWiki skin.
Definition: WebInstallerOutput.php:129
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:37
WebInstallerOutput\__construct
__construct(WebInstaller $parent)
Definition: WebInstallerOutput.php:78
WebInstallerOutput
Output class modelled on OutputPage.
Definition: WebInstallerOutput.php:35
WebInstallerOutput\getJQuery
getJQuery()
Definition: WebInstallerOutput.php:344
WebInstallerOutput\getDir
getDir()
Definition: WebInstallerOutput.php:215
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:309
WebInstallerOutput\headerDone
headerDone()
Get whether the header has been output.
Definition: WebInstallerOutput.php:245
WebInstallerOutput\$contents
string $contents
Buffered contents that haven't been output yet.
Definition: WebInstallerOutput.php:48
MWException
MediaWiki exception.
Definition: MWException.php:26
WebInstallerOutput\$redirectTarget
string $redirectTarget
Definition: WebInstallerOutput.php:59
WebInstallerOutput\$parent
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
Definition: WebInstallerOutput.php:42
Html\linkedScript
static linkedScript( $url)
Output a "<script>" tag linking to the given URL, e.g., "<script src=foo.js></script>".
Definition: Html.php:579
title
title
Definition: parserTests.txt:219
contents
Some information about database access in MediaWiki By Tim January Database layout For information about the MediaWiki database such as a description of the tables and their contents
Definition: database.txt:9
$wgLang
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as $wgLang
Definition: design.txt:56
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:95
div
div
Definition: parserTests.txt:6593
style
Bar style
Definition: parserTests.txt:192
WebInstallerOutput\allowFrames
allowFrames( $allow=true)
Definition: WebInstallerOutput.php:197
WebInstallerOutput\outputShortHeader
outputShortHeader()
Definition: WebInstallerOutput.php:320
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:1273
WebInstallerOutput\useShortHeader
useShortHeader( $use=true)
Definition: WebInstallerOutput.php:193
WebInstallerOutput\getHeadAttribs
getHeadAttribs()
Definition: WebInstallerOutput.php:233
WebInstallerOutput\outputTitle
outputTitle()
Definition: WebInstallerOutput.php:336
ResourceLoader
Dynamic JavaScript and CSS resource loading system.
Definition: ResourceLoader.php:38
$section
usually copyright or history_copyright This message must be in HTML not wikitext if the section is included from a template $section
Definition: hooks.txt:3022
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:626
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:67
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:22
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:94
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\output
output()
Definition: WebInstallerOutput.php:116
WebInstallerOutput\flush
flush()
Definition: WebInstallerOutput.php:201
WebInstallerOutput\getLanguageCode
getLanguageCode()
Definition: WebInstallerOutput.php:224
name
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Definition: design.txt:12
WebInstallerOutput\addHTML
addHTML( $html)
Definition: WebInstallerOutput.php:85
href
shown</td >< td > a href
Definition: All_system_messages.txt:2667
$wgStyleDirectory
$wgStyleDirectory
Filesystem stylesheets directory.
Definition: DefaultSettings.php:250