MediaWiki  1.33.0
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 addWikiText( $text ) {
98  wfDeprecated( __METHOD__, '1.32' );
99  $this->addWikiTextAsInterface( $text );
100  }
101 
106  public function addWikiTextAsInterface( $text ) {
107  $this->addHTML( $this->parent->parse( $text ) );
108  }
109 
113  public function addHTMLNoFlush( $html ) {
114  $this->contents .= $html;
115  }
116 
122  public function redirect( $url ) {
123  if ( $this->headerDone ) {
124  throw new MWException( __METHOD__ . ' called after sending headers' );
125  }
126  $this->redirectTarget = $url;
127  }
128 
129  public function output() {
130  $this->flush();
131 
132  if ( !$this->redirectTarget ) {
133  $this->outputFooter();
134  }
135  }
136 
142  public function getCSS() {
143  global $wgStyleDirectory;
144 
145  $moduleNames = [
146  // Based on Skin::getDefaultModules
147  'mediawiki.legacy.shared',
148  // Based on Vector::setupSkinUserCss
149  'mediawiki.skinning.interface',
150  ];
151 
152  $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader();
153 
154  if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
155  // Force loading Vector skin if available as a fallback skin
156  // for whatever ResourceLoader wants to have as the default.
157  $registry = new ExtensionRegistry();
158  $data = $registry->readFromQueue( [
159  "$wgStyleDirectory/Vector/skin.json" => 1,
160  ] );
161  if ( isset( $data['globals']['wgResourceModules'] ) ) {
162  $resourceLoader->register( $data['globals']['wgResourceModules'] );
163  }
164 
165  $moduleNames[] = 'skins.vector.styles';
166  }
167 
168  $moduleNames[] = 'mediawiki.legacy.config';
169 
170  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
171  'debug' => 'true',
172  'lang' => $this->getLanguage()->getCode(),
173  'only' => 'styles',
174  ] ) );
175 
176  $styles = [];
177  foreach ( $moduleNames as $moduleName ) {
179  $module = $resourceLoader->getModule( $moduleName );
180  if ( !$module ) {
181  // T98043: Don't fatal, but it won't look as pretty.
182  continue;
183  }
184 
185  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
186  $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
187  $module->readStyleFiles(
188  $module->getStyleFiles( $rlContext ),
189  $module->getFlip( $rlContext ),
190  $rlContext
191  ) ) );
192  }
193 
194  return implode( "\n", $styles );
195  }
196 
202  private function getCssUrl() {
203  return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) );
204  }
205 
206  public function useShortHeader( $use = true ) {
207  $this->useShortHeader = $use;
208  }
209 
210  public function allowFrames( $allow = true ) {
211  $this->allowFrames = $allow;
212  }
213 
214  public function flush() {
215  if ( !$this->headerDone ) {
216  $this->outputHeader();
217  }
218  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
219  echo $this->contents;
220  flush();
221  $this->contents = '';
222  }
223  }
224 
229  private function getLanguage() {
230  global $wgLang;
231 
232  return is_object( $wgLang ) ? $wgLang : Language::factory( 'en' );
233  }
234 
238  public function getHeadAttribs() {
239  return [
240  'dir' => $this->getLanguage()->getDir(),
241  'lang' => $this->getLanguage()->getHtmlCode(),
242  ];
243  }
244 
250  public function headerDone() {
251  return $this->headerDone;
252  }
253 
254  public function outputHeader() {
255  $this->headerDone = true;
256  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
257 
258  if ( !$this->allowFrames ) {
259  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
260  }
261 
262  if ( $this->redirectTarget ) {
263  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
264 
265  return;
266  }
267 
268  if ( $this->useShortHeader ) {
269  $this->outputShortHeader();
270 
271  return;
272  }
273 ?>
274 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
275 
276 <head>
277  <meta name="robots" content="noindex, nofollow" />
278  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
279  <title><?php $this->outputTitle(); ?></title>
280  <?php echo $this->getCssUrl() . "\n"; ?>
281  <?php echo $this->getJQuery() . "\n"; ?>
282  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
283 </head>
284 
285 <?php echo Html::openElement( 'body', [ 'class' => $this->getLanguage()->getDir() ] ) . "\n"; ?>
286 <div id="mw-page-base"></div>
287 <div id="mw-head-base"></div>
288 <div id="content" class="mw-body">
289 <div id="bodyContent" class="mw-body-content">
290 
291 <h1><?php $this->outputTitle(); ?></h1>
292 <?php
293  }
294 
295  public function outputFooter() {
296  if ( $this->useShortHeader ) {
297  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
298 
299  return;
300  }
301 ?>
302 
303 </div></div>
304 
305 <div id="mw-panel">
306  <div class="portal" id="p-logo">
307  <a style="background-image: url(images/installer-logo.png);"
308  href="https://www.mediawiki.org/"
309  title="Main Page"></a>
310  </div>
311 <?php
312  $message = wfMessage( 'config-sidebar' )->plain();
313  foreach ( explode( '----', $message ) as $section ) {
314  echo '<div class="portal"><div class="body">';
315  echo $this->parent->parse( $section, true );
316  echo '</div></div>';
317  }
318 ?>
319 </div>
320 
321 <?php
322  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
323  }
324 
325  public function outputShortHeader() {
326 ?>
327 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
328 <head>
329  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
330  <meta name="robots" content="noindex, nofollow" />
331  <title><?php $this->outputTitle(); ?></title>
332  <?php echo $this->getCssUrl() . "\n"; ?>
333  <?php echo $this->getJQuery(); ?>
334  <?php echo Html::linkedScript( 'config.js' ); ?>
335 </head>
336 
337 <body style="background-image: none">
338 <?php
339  }
340 
341  public function outputTitle() {
342  global $wgVersion;
343  echo wfMessage( 'config-title', $wgVersion )->escaped();
344  }
345 
349  public function getJQuery() {
350  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
351  }
352 
353 }
WebInstallerOutput\addHTMLNoFlush
addHTMLNoFlush( $html)
Definition: WebInstallerOutput.php:113
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:97
WebInstallerOutput\redirect
redirect( $url)
Definition: WebInstallerOutput.php:122
content
per default it will return the text for text based content
Definition: contenthandler.txt:104
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
WebInstallerOutput\getCssUrl
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
Definition: WebInstallerOutput.php:202
ExtensionRegistry
ExtensionRegistry class.
Definition: ExtensionRegistry.php:17
$wgVersion
$wgVersion
MediaWiki version number.
Definition: DefaultSettings.php:75
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:32
WebInstallerOutput\outputHeader
outputHeader()
Definition: WebInstallerOutput.php:254
a
</source > ! result< div class="mw-highlight mw-content-ltr" dir="ltr">< pre >< span ></span >< span class="kd"> var</span >< span class="nx"> a</span >< span class="p"></span ></pre ></div > ! end ! test Multiline< source/> in lists !input *< source > a b</source > *foo< source > a b</source > ! html< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! html tidy< ul >< li >< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul >< ul >< li > foo< div class="mw-highlight mw-content-ltr" dir="ltr">< pre > a b</pre ></div ></li ></ul > ! end ! test Custom attributes !input< source lang="javascript" id="foo" class="bar" dir="rtl" style="font-size: larger;"> var a
Definition: parserTests.txt:85
WebInstallerOutput\outputFooter
outputFooter()
Definition: WebInstallerOutput.php:295
$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:2636
http
Apache License January http
Definition: APACHE-LICENSE-2.0.txt:3
WebInstallerOutput\getCSS
getCSS()
Get the stylesheet of the MediaWiki skin.
Definition: WebInstallerOutput.php:142
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:35
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:349
WebInstallerOutput\headerDone
headerDone()
Get whether the header has been output.
Definition: WebInstallerOutput.php:250
name
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
$data
$data
Utility to generate mapping file used in mw.Title (phpCharToUpper.json)
Definition: generatePhpCharToUpperMappings.php:13
WebInstallerOutput\$contents
string $contents
Buffered contents that haven't been output yet.
Definition: WebInstallerOutput.php:51
$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:1985
MWException
MediaWiki exception.
Definition: MWException.php:26
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1078
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:875
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
div
div
Definition: parserTests.txt:6850
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:2
WebInstallerOutput\allowFrames
allowFrames( $allow=true)
Definition: WebInstallerOutput.php:210
WebInstallerOutput\outputShortHeader
outputShortHeader()
Definition: WebInstallerOutput.php:325
title
title
Definition: parserTests.txt:245
WebInstallerOutput\useShortHeader
useShortHeader( $use=true)
Definition: WebInstallerOutput.php:206
WebInstallerOutput\addWikiTextAsInterface
addWikiTextAsInterface( $text)
Definition: WebInstallerOutput.php:106
WebInstallerOutput\getHeadAttribs
getHeadAttribs()
Definition: WebInstallerOutput.php:238
WebInstallerOutput\outputTitle
outputTitle()
Definition: WebInstallerOutput.php:341
style
Bar style
Definition: parserTests.txt:218
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
$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:3053
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:9
WebInstallerOutput\getLanguage
getLanguage()
Definition: WebInstallerOutput.php:229
WebInstallerOutput\output
output()
Definition: WebInstallerOutput.php:129
WebInstallerOutput\flush
flush()
Definition: WebInstallerOutput.php:214
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:215
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
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 use $formDescriptor instead 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\addHTML
addHTML( $html)
Definition: WebInstallerOutput.php:88
href
shown</td >< td > a href
Definition: All_system_messages.txt:2667
$wgStyleDirectory
$wgStyleDirectory
Filesystem stylesheets directory.
Definition: DefaultSettings.php:230