MediaWiki  REL1_19
WebInstallerOutput.php
Go to the documentation of this file.
00001 <?php
00020 class WebInstallerOutput {
00026         public $parent;
00027 
00032         private $contents = '';
00033 
00038         private $headerDone = false;
00039 
00040         public $redirectTarget;
00041 
00048         public $allowFrames = false;
00049 
00054         private $useShortHeader = false;
00055 
00061         public function __construct( WebInstaller $parent ) {
00062                 $this->parent = $parent;
00063         }
00064 
00065         public function addHTML( $html ) {
00066                 $this->contents .= $html;
00067                 $this->flush();
00068         }
00069 
00070         public function addWikiText( $text ) {
00071                 $this->addHTML( $this->parent->parse( $text ) );
00072         }
00073 
00074         public function addHTMLNoFlush( $html ) {
00075                 $this->contents .= $html;
00076         }
00077 
00078         public function redirect( $url ) {
00079                 if ( $this->headerDone ) {
00080                         throw new MWException( __METHOD__ . ' called after sending headers' );
00081                 }
00082                 $this->redirectTarget = $url;
00083         }
00084 
00085         public function output() {
00086                 $this->flush();
00087                 $this->outputFooter();
00088         }
00089 
00095         public function getCSS( $dir ) {
00096                 $skinDir = dirname( dirname( dirname( __FILE__ ) ) ) . '/skins';
00097 
00098                 // All these files will be concatenated in sequence and loaded
00099                 // as one file.
00100                 // The string 'images/' in the files' contents will be replaced
00101                 // by '../skins/$skinName/images/', where $skinName is what appears
00102                 // before the last '/' in each of the strings.
00103                 $cssFileNames = array(
00104 
00105                         // Basically the "skins.vector" ResourceLoader module styles
00106                         'common/commonElements.css',
00107                         'common/commonContent.css',
00108                         'common/commonInterface.css',
00109                         'vector/screen.css',
00110 
00111                         // mw-config specific
00112                         'common/config.css',
00113                 );
00114 
00115                 $css = '';
00116 
00117                 wfSuppressWarnings();
00118                 foreach ( $cssFileNames as $cssFileName ) {
00119                         $fullCssFileName = "$skinDir/$cssFileName";
00120                         $cssFileContents = file_get_contents( $fullCssFileName );
00121                         if ( $cssFileContents ) {
00122                                 preg_match( "/^(\w+)\//", $cssFileName, $match );
00123                                 $skinName = $match[1];
00124                                 $css .= str_replace( 'images/', "../skins/$skinName/images/", $cssFileContents );
00125                         } else {
00126                                 $css .= "/** Your webserver cannot read $fullCssFileName. Please check file permissions. */";
00127                         }
00128 
00129                         $css .= "\n";
00130                 }
00131                 wfRestoreWarnings();
00132 
00133                 if( $dir == 'rtl' ) {
00134                         $css = CSSJanus::transform( $css, true );
00135                 }
00136                 return $css;
00137         }
00138 
00143         private function getCssUrl( ) {
00144                 return Html::linkedStyle( $_SERVER['PHP_SELF'] . '?css=' . $this->getDir() );
00145         }
00146 
00147         public function useShortHeader( $use = true ) {
00148                 $this->useShortHeader = $use;
00149         }
00150 
00151         public function allowFrames( $allow = true ) {
00152                 $this->allowFrames = $allow;
00153         }
00154 
00155         public function flush() {
00156                 if ( !$this->headerDone ) {
00157                         $this->outputHeader();
00158                 }
00159                 if ( !$this->redirectTarget && strlen( $this->contents ) ) {
00160                         echo $this->contents;
00161                         flush();
00162                         $this->contents = '';
00163                 }
00164         }
00165 
00169         public function getDir() {
00170                 global $wgLang;
00171                 return is_object( $wgLang ) ? $wgLang->getDir() : 'ltr';
00172         }
00173 
00177         public function getLanguageCode() {
00178                 global $wgLang;
00179                 return is_object( $wgLang ) ? $wgLang->getCode() : 'en';
00180         }
00181 
00185         public function getHeadAttribs() {
00186                 return array(
00187                         'dir' => $this->getDir(),
00188                         'lang' => $this->getLanguageCode(),
00189                 );
00190         }
00191 
00196         public function headerDone() {
00197                 return $this->headerDone;
00198         }
00199 
00200         public function outputHeader() {
00201                 $this->headerDone = true;
00202                 $dbTypes = $this->parent->getDBTypes();
00203 
00204                 $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' );
00205                 if (!$this->allowFrames) {
00206                         $this->parent->request->response()->header( 'X-Frame-Options: DENY' );
00207                 }
00208                 if ( $this->redirectTarget ) {
00209                         $this->parent->request->response()->header( 'Location: '.$this->redirectTarget );
00210                         return;
00211                 }
00212 
00213                 if ( $this->useShortHeader ) {
00214                         $this->outputShortHeader();
00215                         return;
00216                 }
00217 
00218 ?>
00219 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
00220 <head>
00221         <meta name="robots" content="noindex, nofollow" />
00222         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
00223         <title><?php $this->outputTitle(); ?></title>
00224         <?php echo Html::linkedStyle( '../skins/common/shared.css' ) . "\n"; ?>
00225         <?php echo $this->getCssUrl() . "\n"; ?>
00226         <?php echo Html::inlineScript(  "var dbTypes = " . Xml::encodeJsVar( $dbTypes ) ) . "\n"; ?>
00227         <?php echo $this->getJQuery() . "\n"; ?>
00228         <?php echo Html::linkedScript( '../skins/common/config.js' ) . "\n"; ?>
00229 </head>
00230 
00231 <?php echo Html::openElement( 'body', array( 'class' => $this->getDir() ) ) . "\n"; ?>
00232 <div id="mw-page-base"></div>
00233 <div id="mw-head-base"></div>
00234 <div id="content">
00235 <div id="bodyContent">
00236 
00237 <h1><?php $this->outputTitle(); ?></h1>
00238 <?php
00239         }
00240 
00241         public function outputFooter() {
00242                 if ( $this->useShortHeader ) {
00243 ?>
00244 </body></html>
00245 <?php
00246                         return;
00247                 }
00248 ?>
00249 
00250 </div></div>
00251 
00252 
00253 <div id="mw-panel">
00254         <div class="portal" id="p-logo">
00255           <a style="background-image: url(../skins/common/images/mediawiki.png);"
00256                 href="http://www.mediawiki.org/"
00257                 title="Main Page"></a>
00258         </div>
00259         <div class="portal"><div class="body">
00260 <?php
00261         echo $this->parent->parse( wfMsgNoTrans( 'config-sidebar' ), true );
00262 ?>
00263         </div></div>
00264 </div>
00265 
00266 </body>
00267 </html>
00268 <?php
00269         }
00270 
00271         public function outputShortHeader() {
00272 ?>
00273 <?php echo Html::htmlHeader( $this->getHeadAttribs() ); ?>
00274 <head>
00275         <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
00276         <meta name="robots" content="noindex, nofollow" />
00277         <title><?php $this->outputTitle(); ?></title>
00278         <?php echo $this->getCssUrl() . "\n"; ?>
00279         <?php echo $this->getJQuery(); ?>
00280         <?php echo Html::linkedScript( '../skins/common/config.js' ); ?>
00281 </head>
00282 
00283 <body style="background-image: none">
00284 <?php
00285         }
00286 
00287         public function outputTitle() {
00288                 global $wgVersion;
00289                 echo htmlspecialchars( wfMsg( 'config-title', $wgVersion ) );
00290         }
00291 
00292         public function getJQuery() {
00293                 return Html::linkedScript( "../resources/jquery/jquery.js" );
00294         }
00295 }