MediaWiki  1.32.5
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 
94  public function addWikiText( $text ) {
95  wfDeprecated( __METHOD__, '1.32' );
96  $this->addWikiTextAsInterface( $text );
97  }
98 
103  public function addWikiTextAsInterface( $text ) {
104  $this->addHTML( $this->parent->parse( $text ) );
105  }
106 
110  public function addHTMLNoFlush( $html ) {
111  $this->contents .= $html;
112  }
113 
119  public function redirect( $url ) {
120  if ( $this->headerDone ) {
121  throw new MWException( __METHOD__ . ' called after sending headers' );
122  }
123  $this->redirectTarget = $url;
124  }
125 
126  public function output() {
127  $this->flush();
128 
129  if ( !$this->redirectTarget ) {
130  $this->outputFooter();
131  }
132  }
133 
139  public function getCSS() {
140  global $wgStyleDirectory;
141 
142  $moduleNames = [
143  // Based on Skin::getDefaultModules
144  'mediawiki.legacy.shared',
145  // Based on Vector::setupSkinUserCss
146  'mediawiki.skinning.interface',
147  ];
148 
149  $resourceLoader = new ResourceLoader();
150 
151  if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
152  // Force loading Vector skin if available as a fallback skin
153  // for whatever ResourceLoader wants to have as the default.
154  $registry = new ExtensionRegistry();
155  $data = $registry->readFromQueue( [
156  "$wgStyleDirectory/Vector/skin.json" => 1,
157  ] );
158  if ( isset( $data['globals']['wgResourceModules'] ) ) {
159  $resourceLoader->register( $data['globals']['wgResourceModules'] );
160  }
161 
162  $moduleNames[] = 'skins.vector.styles';
163  }
164 
165  $moduleNames[] = 'mediawiki.legacy.config';
166 
167  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
168  'debug' => 'true',
169  'lang' => $this->getLanguageCode(),
170  'only' => 'styles',
171  ] ) );
172 
173  $styles = [];
174  foreach ( $moduleNames as $moduleName ) {
176  $module = $resourceLoader->getModule( $moduleName );
177  if ( !$module ) {
178  // T98043: Don't fatal, but it won't look as pretty.
179  continue;
180  }
181 
182  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
183  $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
184  $module->readStyleFiles(
185  $module->getStyleFiles( $rlContext ),
186  $module->getFlip( $rlContext ),
187  $rlContext
188  ) ) );
189  }
190 
191  return implode( "\n", $styles );
192  }
193 
199  private function getCssUrl() {
200  return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
201  }
202 
203  public function useShortHeader( $use = true ) {
204  $this->useShortHeader = $use;
205  }
206 
207  public function allowFrames( $allow = true ) {
208  $this->allowFrames = $allow;
209  }
210 
211  public function flush() {
212  if ( !$this->headerDone ) {
213  $this->outputHeader();
214  }
215  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
216  echo $this->contents;
217  flush();
218  $this->contents = '';
219  }
220  }
221 
225  public function getDir() {
226  global $wgLang;
227 
228  return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
229  }
230 
234  public function getLanguageCode() {
235  global $wgLang;
236 
237  return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
238  }
239 
243  public function getHeadAttribs() {
244  return [
245  'dir' => $this->getDir(),
246  'lang' => LanguageCode::bcp47( $this->getLanguageCode() ),
247  ];
248  }
249 
255  public function headerDone() {
256  return $this->headerDone;
257  }
258 
259  public function outputHeader() {
260  $this->headerDone = true;
261  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
262 
263  if ( !$this->allowFrames ) {
264  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
265  }
266 
267  if ( $this->redirectTarget ) {
268  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
269 
270  return;
271  }
272 
273  if ( $this->useShortHeader ) {
274  $this->outputShortHeader();
275 
276  return;
277  }
278 ?>
279 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
280 
281 <head>
282  <meta name="robots" content="noindex, nofollow" />
283  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
284  <title><?php $this->outputTitle(); ?></title>
285  <?php echo $this->getCssUrl() . "\n"; ?>
286  <?php echo $this->getJQuery() . "\n"; ?>
287  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
288 </head>
289 
290 <?php echo Html::openElement( 'body', [ 'class' => $this->getDir() ] ) . "\n"; ?>
291 <div id="mw-page-base"></div>
292 <div id="mw-head-base"></div>
293 <div id="content" class="mw-body">
294 <div id="bodyContent" class="mw-body-content">
295 
296 <h1><?php $this->outputTitle(); ?></h1>
297 <?php
298  }
299 
300  public function outputFooter() {
301  if ( $this->useShortHeader ) {
302  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
303 
304  return;
305  }
306 ?>
307 
308 </div></div>
309 
310 <div id="mw-panel">
311  <div class="portal" id="p-logo">
312  <a style="background-image: url(images/installer-logo.png);"
313  href="https://www.mediawiki.org/"
314  title="Main Page"></a>
315  </div>
316 <?php
317  $message = wfMessage( 'config-sidebar' )->plain();
318  foreach ( explode( '----', $message ) as $section ) {
319  echo '<div class="portal"><div class="body">';
320  echo $this->parent->parse( $section, true );
321  echo '</div></div>';
322  }
323 ?>
324 </div>
325 
326 <?php
327  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
328  }
329 
330  public function outputShortHeader() {
331 ?>
332 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
333 <head>
334  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
335  <meta name="robots" content="noindex, nofollow" />
336  <title><?php $this->outputTitle(); ?></title>
337  <?php echo $this->getCssUrl() . "\n"; ?>
338  <?php echo $this->getJQuery(); ?>
339  <?php echo Html::linkedScript( 'config.js' ); ?>
340 </head>
341 
342 <body style="background-image: none">
343 <?php
344  }
345 
346  public function outputTitle() {
347  global $wgVersion;
348  echo wfMessage( 'config-title', $wgVersion )->escaped();
349  }
350 
354  public function getJQuery() {
355  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
356  }
357 
358 }
WebInstallerOutput\addHTMLNoFlush
addHTMLNoFlush( $html)
Definition: WebInstallerOutput.php:110
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:94
WebInstallerOutput\redirect
redirect( $url)
Definition: WebInstallerOutput.php:119
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:73
WebInstallerOutput\$headerDone
bool $headerDone
Has the header (or short header) been output?
Definition: WebInstallerOutput.php:54
WebInstallerOutput\getCssUrl
getCssUrl()
"<link>" to index.php?css=1 for the "<head>"
Definition: WebInstallerOutput.php:199
ExtensionRegistry
ExtensionRegistry class.
Definition: ExtensionRegistry.php:14
$wgVersion
$wgVersion
MediaWiki version number.
Definition: DefaultSettings.php:74
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:32
WebInstallerOutput\outputHeader
outputHeader()
Definition: WebInstallerOutput.php:259
Html\htmlHeader
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:956
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:89
WebInstallerOutput\outputFooter
outputFooter()
Definition: WebInstallerOutput.php:300
$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:2683
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:139
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:78
WebInstallerOutput
Output class modelled on OutputPage.
Definition: WebInstallerOutput.php:35
WebInstallerOutput\getJQuery
getJQuery()
Definition: WebInstallerOutput.php:354
WebInstallerOutput\getDir
getDir()
Definition: WebInstallerOutput.php:225
Html\closeElement
static closeElement( $element)
Returns "</$element>".
Definition: Html.php:310
WebInstallerOutput\headerDone
headerDone()
Get whether the header has been output.
Definition: WebInstallerOutput.php:255
name
and how to run hooks for an and one after Each event has a name
Definition: hooks.txt:6
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:593
WebInstallerOutput\$contents
string $contents
Buffered contents that haven't been output yet.
Definition: WebInstallerOutput.php:48
$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:2044
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:1118
WebInstallerOutput\$redirectTarget
string $redirectTarget
Definition: WebInstallerOutput.php:59
WebInstallerOutput\$parent
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
Definition: WebInstallerOutput.php:42
$wgLang
$wgLang
Definition: Setup.php:910
div
div
Definition: parserTests.txt:6868
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:207
WebInstallerOutput\outputShortHeader
outputShortHeader()
Definition: WebInstallerOutput.php:330
title
title
Definition: parserTests.txt:239
WebInstallerOutput\useShortHeader
useShortHeader( $use=true)
Definition: WebInstallerOutput.php:203
WebInstallerOutput\addWikiTextAsInterface
addWikiTextAsInterface( $text)
Definition: WebInstallerOutput.php:103
WebInstallerOutput\getHeadAttribs
getHeadAttribs()
Definition: WebInstallerOutput.php:243
WebInstallerOutput\outputTitle
outputTitle()
Definition: WebInstallerOutput.php:346
style
Bar style
Definition: parserTests.txt:212
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:647
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
$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:3098
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
LanguageCode\bcp47
static bcp47( $code)
Get the normalised IETF language tag See unit test for examples.
Definition: LanguageCode.php:182
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\output
output()
Definition: WebInstallerOutput.php:126
WebInstallerOutput\flush
flush()
Definition: WebInstallerOutput.php:211
WebInstallerOutput\getLanguageCode
getLanguageCode()
Definition: WebInstallerOutput.php:234
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:85
href
shown</td >< td > a href
Definition: All_system_messages.txt:2667
$wgStyleDirectory
$wgStyleDirectory
Filesystem stylesheets directory.
Definition: DefaultSettings.php:229