MediaWiki
REL1_23
|
00001 <?php 00035 class WebInstallerOutput { 00036 00042 public $parent; 00043 00048 private $contents = ''; 00049 00054 private $headerDone = false; 00055 00059 public $redirectTarget; 00060 00067 public $allowFrames = false; 00068 00073 private $useShortHeader = false; 00074 00078 public function __construct( WebInstaller $parent ) { 00079 $this->parent = $parent; 00080 } 00081 00085 public function addHTML( $html ) { 00086 $this->contents .= $html; 00087 $this->flush(); 00088 } 00089 00093 public function addWikiText( $text ) { 00094 $this->addHTML( $this->parent->parse( $text ) ); 00095 } 00096 00100 public function addHTMLNoFlush( $html ) { 00101 $this->contents .= $html; 00102 } 00103 00109 public function redirect( $url ) { 00110 if ( $this->headerDone ) { 00111 throw new MWException( __METHOD__ . ' called after sending headers' ); 00112 } 00113 $this->redirectTarget = $url; 00114 } 00115 00116 public function output() { 00117 $this->flush(); 00118 $this->outputFooter(); 00119 } 00120 00132 public function getCSS( $dir ) { 00133 // All CSS files these modules reference will be concatenated in sequence 00134 // and loaded as one file. 00135 $moduleNames = array( 00136 'mediawiki.legacy.shared', 00137 'mediawiki.skinning.interface', 00138 'skins.vector.styles', 00139 'mediawiki.legacy.config', 00140 ); 00141 00142 $prepend = ''; 00143 $css = ''; 00144 00145 $resourceLoader = new ResourceLoader(); 00146 foreach ( $moduleNames as $moduleName ) { 00148 $module = $resourceLoader->getModule( $moduleName ); 00149 $cssFileNames = $module->getAllStyleFiles(); 00150 00151 wfSuppressWarnings(); 00152 foreach ( $cssFileNames as $cssFileName ) { 00153 if ( !file_exists( $cssFileName ) ) { 00154 $prepend .= ResourceLoader::makeComment( "Unable to find $cssFileName." ); 00155 continue; 00156 } 00157 00158 if ( !is_readable( $cssFileName ) ) { 00159 $prepend .= ResourceLoader::makeComment( "Unable to read $cssFileName. " . 00160 "Please check file permissions." ); 00161 continue; 00162 } 00163 00164 try { 00165 00166 if ( preg_match( '/\.less$/', $cssFileName ) ) { 00167 // Run the LESS compiler for *.less files (bug 55589) 00168 $compiler = ResourceLoader::getLessCompiler(); 00169 $cssFileContents = $compiler->compileFile( $cssFileName ); 00170 } else { 00171 // Regular CSS file 00172 $cssFileContents = file_get_contents( $cssFileName ); 00173 } 00174 00175 if ( $cssFileContents ) { 00176 // Rewrite URLs, though don't bother embedding images. While static image 00177 // files may be cached, CSS returned by this function is definitely not. 00178 $cssDirName = dirname( $cssFileName ); 00179 $css .= CSSMin::remap( 00180 /* source */ $cssFileContents, 00181 /* local */ $cssDirName, 00182 /* remote */ '..' . str_replace( 00183 array( $GLOBALS['IP'], DIRECTORY_SEPARATOR ), 00184 array( '', '/' ), 00185 $cssDirName 00186 ), 00187 /* embedData */ false 00188 ); 00189 } else { 00190 $prepend .= ResourceLoader::makeComment( "Unable to read $cssFileName." ); 00191 } 00192 } catch ( Exception $e ) { 00193 $prepend .= ResourceLoader::formatException( $e ); 00194 } 00195 00196 $css .= "\n"; 00197 } 00198 wfRestoreWarnings(); 00199 } 00200 00201 $css = $prepend . $css; 00202 00203 if ( $dir == 'rtl' ) { 00204 $css = CSSJanus::transform( $css, true ); 00205 } 00206 00207 return $css; 00208 } 00209 00215 private function getCssUrl() { 00216 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() ); 00217 } 00218 00219 public function useShortHeader( $use = true ) { 00220 $this->useShortHeader = $use; 00221 } 00222 00223 public function allowFrames( $allow = true ) { 00224 $this->allowFrames = $allow; 00225 } 00226 00227 public function flush() { 00228 if ( !$this->headerDone ) { 00229 $this->outputHeader(); 00230 } 00231 if ( !$this->redirectTarget && strlen( $this->contents ) ) { 00232 echo $this->contents; 00233 flush(); 00234 $this->contents = ''; 00235 } 00236 } 00237 00241 public function getDir() { 00242 global $wgLang; 00243 00244 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr'; 00245 } 00246 00250 public function getLanguageCode() { 00251 global $wgLang; 00252 00253 return is_object( $wgLang ) ? $wgLang->getCode() : 'en'; 00254 } 00255 00259 public function getHeadAttribs() { 00260 return array( 00261 'dir' => $this->getDir(), 00262 'lang' => $this->getLanguageCode(), 00263 ); 00264 } 00265 00271 public function headerDone() { 00272 return $this->headerDone; 00273 } 00274 00275 public function outputHeader() { 00276 $this->headerDone = true; 00277 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' ); 00278 00279 if ( !$this->allowFrames ) { 00280 $this->parent->request->response()->header( 'X-Frame-Options: DENY' ); 00281 } 00282 00283 if ( $this->redirectTarget ) { 00284 $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget ); 00285 00286 return; 00287 } 00288 00289 if ( $this->useShortHeader ) { 00290 $this->outputShortHeader(); 00291 00292 return; 00293 } 00294 ?> 00295 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> 00296 <head> 00297 <meta name="robots" content="noindex, nofollow" /> 00298 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 00299 <title><?php $this->outputTitle(); ?></title> 00300 <?php echo $this->getCssUrl() . "\n"; ?> 00301 <?php echo $this->getJQuery() . "\n"; ?> 00302 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?> 00303 </head> 00304 00305 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?> 00306 <div id="mw-page-base"></div> 00307 <div id="mw-head-base"></div> 00308 <div id="content"> 00309 <div id="bodyContent"> 00310 00311 <h1><?php $this->outputTitle(); ?></h1> 00312 <?php 00313 } 00314 00315 public function outputFooter() { 00316 if ( $this->useShortHeader ) { 00317 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' ); 00318 00319 return; 00320 } 00321 ?> 00322 00323 </div></div> 00324 00325 <div id="mw-panel"> 00326 <div class="portal" id="p-logo"> 00327 <a style="background-image: url(../skins/common/images/mediawiki.png);" 00328 href="https://www.mediawiki.org/" 00329 title="Main Page"></a> 00330 </div> 00331 <div class="portal"><div class="body"> 00332 <?php 00333 echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true ); 00334 ?> 00335 </div></div> 00336 </div> 00337 00338 <?php 00339 echo Html::closeElement( 'body' ) . Html::closeElement( 'html' ); 00340 } 00341 00342 public function outputShortHeader() { 00343 ?> 00344 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> 00345 <head> 00346 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 00347 <meta name="robots" content="noindex, nofollow" /> 00348 <title><?php $this->outputTitle(); ?></title> 00349 <?php echo $this->getCssUrl() . "\n"; ?> 00350 <?php echo $this->getJQuery(); ?> 00351 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?> 00352 </head> 00353 00354 <body style="background-image: none"> 00355 <?php 00356 } 00357 00358 public function outputTitle() { 00359 global $wgVersion; 00360 echo wfMessage( 'config-title', $wgVersion )->escaped(); 00361 } 00362 00366 public function getJQuery() { 00367 return Html::linkedScript( "../resources/lib/jquery/jquery.js" ); 00368 } 00369 00370 }