MediaWiki  1.27.1
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  $this->outputFooter();
119  }
120 
126  public function getCSS() {
128 
129  $moduleNames = [
130  // See SkinTemplate::setupSkinUserCss
131  'mediawiki.legacy.shared',
132  // See Vector::setupSkinUserCss
133  'mediawiki.skinning.interface',
134  ];
135 
137 
138  if ( file_exists( "$wgStyleDirectory/Vector/skin.json" ) ) {
139  // Force loading Vector skin if available as a fallback skin
140  // for whatever ResourceLoader wants to have as the default.
141  $registry = new ExtensionRegistry();
142  $data = $registry->readFromQueue( [
143  "$wgStyleDirectory/Vector/skin.json" => 1,
144  ] );
145  if ( isset( $data['globals']['wgResourceModules'] ) ) {
146  $resourceLoader->register( $data['globals']['wgResourceModules'] );
147  }
148 
149  $moduleNames[] = 'skins.vector.styles';
150  }
151 
152  $moduleNames[] = 'mediawiki.legacy.config';
153 
154  $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [
155  'debug' => 'true',
156  'lang' => $this->getLanguageCode(),
157  'only' => 'styles',
158  ] ) );
159 
160  $styles = [];
161  foreach ( $moduleNames as $moduleName ) {
163  $module = $resourceLoader->getModule( $moduleName );
164  if ( !$module ) {
165  // T98043: Don't fatal, but it won't look as pretty.
166  continue;
167  }
168 
169  // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
170  $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
171  $module->readStyleFiles(
172  $module->getStyleFiles( $rlContext ),
173  $module->getFlip( $rlContext ),
174  $rlContext
175  ) ) );
176  }
177 
178  return implode( "\n", $styles );
179  }
180 
186  private function getCssUrl() {
187  return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=1' );
188  }
189 
190  public function useShortHeader( $use = true ) {
191  $this->useShortHeader = $use;
192  }
193 
194  public function allowFrames( $allow = true ) {
195  $this->allowFrames = $allow;
196  }
197 
198  public function flush() {
199  if ( !$this->headerDone ) {
200  $this->outputHeader();
201  }
202  if ( !$this->redirectTarget && strlen( $this->contents ) ) {
203  echo $this->contents;
204  flush();
205  $this->contents = '';
206  }
207  }
208 
212  public function getDir() {
213  global $wgLang;
214 
215  return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
216  }
217 
221  public function getLanguageCode() {
222  global $wgLang;
223 
224  return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
225  }
226 
230  public function getHeadAttribs() {
231  return [
232  'dir' => $this->getDir(),
233  'lang' => wfBCP47( $this->getLanguageCode() ),
234  ];
235  }
236 
242  public function headerDone() {
243  return $this->headerDone;
244  }
245 
246  public function outputHeader() {
247  $this->headerDone = true;
248  $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
249 
250  if ( !$this->allowFrames ) {
251  $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
252  }
253 
254  if ( $this->redirectTarget ) {
255  $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget );
256 
257  return;
258  }
259 
260  if ( $this->useShortHeader ) {
261  $this->outputShortHeader();
262 
263  return;
264  }
265 ?>
266 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
267 <head>
268  <meta name="robots" content="noindex, nofollow" />
269  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
270  <title><?php $this->outputTitle(); ?></title>
271  <?php echo $this->getCssUrl() . "\n"; ?>
272  <?php echo $this->getJQuery() . "\n"; ?>
273  <?php echo Html::linkedScript( 'config.js' ) . "\n"; ?>
274 </head>
275 
276 <?php echo Html::openElement( 'body', [ 'class' => $this->getDir() ] ) . "\n"; ?>
277 <div id="mw-page-base"></div>
278 <div id="mw-head-base"></div>
279 <div id="content" class="mw-body">
280 <div id="bodyContent" class="mw-body-content">
281 
282 <h1><?php $this->outputTitle(); ?></h1>
283 <?php
284  }
285 
286  public function outputFooter() {
287  if ( $this->useShortHeader ) {
288  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
289 
290  return;
291  }
292 ?>
293 
294 </div></div>
295 
296 <div id="mw-panel">
297  <div class="portal" id="p-logo">
298  <a style="background-image: url(images/installer-logo.png);"
299  href="https://www.mediawiki.org/"
300  title="Main Page"></a>
301  </div>
302 <?php
303  $message = wfMessage( 'config-sidebar' )->plain();
304  foreach ( explode( '----', $message ) as $section ) {
305  echo '<div class="portal"><div class="body">';
306  echo $this->parent->parse( $section, true );
307  echo '</div></div>';
308  }
309 ?>
310 </div>
311 
312 <?php
313  echo Html::closeElement( 'body' ) . Html::closeElement( 'html' );
314  }
315 
316  public function outputShortHeader() {
317 ?>
318 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
319 <head>
320  <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
321  <meta name="robots" content="noindex, nofollow" />
322  <title><?php $this->outputTitle(); ?></title>
323  <?php echo $this->getCssUrl() . "\n"; ?>
324  <?php echo $this->getJQuery(); ?>
325  <?php echo Html::linkedScript( 'config.js' ); ?>
326 </head>
327 
328 <body style="background-image: none">
329 <?php
330  }
331 
332  public function outputTitle() {
334  echo wfMessage( 'config-title', $wgVersion )->escaped();
335  }
336 
340  public function getJQuery() {
341  return Html::linkedScript( "../resources/lib/jquery/jquery.js" );
342  }
343 
344 }
static closeElement($element)
Returns "".
Definition: Html.php:306
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:1798
$wgVersion
MediaWiki version number.
getCSS()
Get the stylesheet of the MediaWiki skin.
per default it will return the text for text based content
error also a ContextSource you ll probably need to make sure the header is varied on such as when responding to a resource loader request or generating HTML output & $resourceLoader
Definition: hooks.txt:2418
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
Class for the core installer web interface.
static linkedScript($url)
Output a "".
Definition: Html.php:614
bool $headerDone
Has the header (or short header) been output?
bool $allowFrames
Does the current page need to allow being used as a frame? If not, X-Frame-Options will be output to ...
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static makeCombinedStyles(array $stylePairs)
Combines an associative array mapping media type to CSS into a single stylesheet with "@media" blocks...
Apache License January http
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
Output class modelled on OutputPage.
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
Bar style
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 after processing 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 unsetoffset-wrap String Wrap the message in html(usually something like"&lt
shown</td >< td > a href
title
wfBCP47($code)
Get the normalised IETF language tag See unit test for examples.
WebInstaller $parent
The WebInstaller object this WebInstallerOutput is used by.
static htmlHeader(array $attribs=[])
Constructs the opening html-tag with necessary doctypes depending on global variables.
Definition: Html.php:920
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
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:2715
ExtensionRegistry class.
bool $useShortHeader
Whether to use the limited header (used during CC license callbacks)
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
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
$wgStyleDirectory
Filesystem stylesheets directory.
headerDone()
Get whether the header has been output.
__construct(WebInstaller $parent)
Dynamic JavaScript and CSS resource loading system.
static linkedStyle($url, $media= 'all')
Output a "" linking to the given URL for the given media type (if any)...
Definition: Html.php:657
string $contents
Buffered contents that haven't been output yet.
getCssUrl()
"" to index.php?css=1 for the ""
Object passed around to modules which contains information about the state of a specific loader reque...