MediaWiki
REL1_20
|
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 00110 public function getCSS( $dir ) { 00111 $skinDir = dirname( dirname( __DIR__ ) ) . '/skins'; 00112 00113 // All these files will be concatenated in sequence and loaded 00114 // as one file. 00115 // The string 'images/' in the files' contents will be replaced 00116 // by '../skins/$skinName/images/', where $skinName is what appears 00117 // before the last '/' in each of the strings. 00118 $cssFileNames = array( 00119 00120 // Basically the "skins.vector" ResourceLoader module styles 00121 'common/shared.css', 00122 'common/commonElements.css', 00123 'common/commonContent.css', 00124 'common/commonInterface.css', 00125 'vector/screen.css', 00126 00127 // mw-config specific 00128 'common/config.css', 00129 ); 00130 00131 $css = ''; 00132 00133 wfSuppressWarnings(); 00134 foreach ( $cssFileNames as $cssFileName ) { 00135 $fullCssFileName = "$skinDir/$cssFileName"; 00136 $cssFileContents = file_get_contents( $fullCssFileName ); 00137 if ( $cssFileContents ) { 00138 preg_match( "/^(\w+)\//", $cssFileName, $match ); 00139 $skinName = $match[1]; 00140 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents ); 00141 } else { 00142 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */"; 00143 } 00144 00145 $css .= "\n"; 00146 } 00147 wfRestoreWarnings(); 00148 00149 if( $dir == 'rtl' ) { 00150 $css = CSSJanus::transform( $css, true ); 00151 } 00152 00153 return $css; 00154 } 00155 00160 private function getCssUrl( ) { 00161 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() ); 00162 } 00163 00164 public function useShortHeader( $use = true ) { 00165 $this->useShortHeader = $use; 00166 } 00167 00168 public function allowFrames( $allow = true ) { 00169 $this->allowFrames = $allow; 00170 } 00171 00172 public function flush() { 00173 if ( !$this->headerDone ) { 00174 $this->outputHeader(); 00175 } 00176 if ( !$this->redirectTarget && strlen( $this->contents ) ) { 00177 echo $this->contents; 00178 flush(); 00179 $this->contents = ''; 00180 } 00181 } 00182 00186 public function getDir() { 00187 global $wgLang; 00188 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr'; 00189 } 00190 00194 public function getLanguageCode() { 00195 global $wgLang; 00196 return is_object( $wgLang ) ? $wgLang->getCode() : 'en'; 00197 } 00198 00202 public function getHeadAttribs() { 00203 return array( 00204 'dir' => $this->getDir(), 00205 'lang' => $this->getLanguageCode(), 00206 ); 00207 } 00208 00213 public function headerDone() { 00214 return $this->headerDone; 00215 } 00216 00217 public function outputHeader() { 00218 $this->headerDone = true; 00219 $dbTypes = $this->parent->getDBTypes(); 00220 00221 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' ); 00222 if (!$this->allowFrames) { 00223 $this->parent->request->response()->header( 'X-Frame-Options: DENY' ); 00224 } 00225 if ( $this->redirectTarget ) { 00226 $this->parent->request->response()->header( 'Location: '.$this->redirectTarget ); 00227 return; 00228 } 00229 00230 if ( $this->useShortHeader ) { 00231 $this->outputShortHeader(); 00232 return; 00233 } 00234 00235 ?> 00236 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> 00237 <head> 00238 <meta name="robots" content="noindex, nofollow" /> 00239 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 00240 <title><?php $this->outputTitle(); ?></title> 00241 <?php echo $this->getCssUrl() . "\n"; ?> 00242 <?php echo Html::inlineScript( "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?> 00243 <?php echo $this->getJQuery() . "\n"; ?> 00244 <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?> 00245 </head> 00246 00247 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?> 00248 <div id="mw-page-base"></div> 00249 <div id="mw-head-base"></div> 00250 <div id="content"> 00251 <div id="bodyContent"> 00252 00253 <h1><?php $this->outputTitle(); ?></h1> 00254 <?php 00255 } 00256 00257 public function outputFooter() { 00258 if ( $this->useShortHeader ) { 00259 ?> 00260 </body></html> 00261 <?php 00262 return; 00263 } 00264 ?> 00265 00266 </div></div> 00267 00268 00269 <div id="mw-panel"> 00270 <div class="portal" id="p-logo"> 00271 <a style="background-image: url(../skins/common/images/mediawiki.png);" 00272 href="http://www.mediawiki.org/" 00273 title="Main Page"></a> 00274 </div> 00275 <div class="portal"><div class="body"> 00276 <?php 00277 echo $this->parent->parse( wfMessage( 'config-sidebar' )->plain(), true ); 00278 ?> 00279 </div></div> 00280 </div> 00281 00282 </body> 00283 </html> 00284 <?php 00285 } 00286 00287 public function outputShortHeader() { 00288 ?> 00289 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?> 00290 <head> 00291 <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> 00292 <meta name="robots" content="noindex, nofollow" /> 00293 <title><?php $this->outputTitle(); ?></title> 00294 <?php echo $this->getCssUrl() . "\n"; ?> 00295 <?php echo $this->getJQuery(); ?> 00296 <?php echo Html::linkedScript( '../skins/common/config.js' ); ?> 00297 </head> 00298 00299 <body style="background-image: none"> 00300 <?php 00301 } 00302 00303 public function outputTitle() { 00304 global $wgVersion; 00305 echo wfMessage( 'config-title', $wgVersion )->escaped(); 00306 } 00307 00308 public function getJQuery() { 00309 return Html::linkedScript( "../resources/jquery/jquery.js" ); 00310 } 00311 }