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