parent = $parent; } /** * @param string $html */ public function addHTML( $html ) { $this->contents .= $html; $this->flush(); } /** * @param string $text * @since 1.32 */ public function addWikiTextAsInterface( $text ) { $this->addHTML( $this->parent->parse( $text ) ); } /** * @param string $html */ public function addHTMLNoFlush( $html ) { $this->contents .= $html; } /** * @param string $url * * @throws MWException */ public function redirect( $url ) { if ( $this->headerDone ) { throw new MWException( __METHOD__ . ' called after sending headers' ); } $this->redirectTarget = $url; } public function output() { $this->flush(); if ( !$this->redirectTarget ) { $this->outputFooter(); } } /** * Get the stylesheet of the MediaWiki skin. * * @return string */ public function getCSS() { $moduleNames = [ 'mediawiki.skinning.interface', 'mediawiki.legacy.config' ]; $resourceLoader = MediaWikiServices::getInstance()->getResourceLoader(); $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( [ 'debug' => 'true', 'lang' => $this->getLanguage()->getCode(), 'only' => 'styles', ] ) ); $styles = []; foreach ( $moduleNames as $moduleName ) { /** @var ResourceLoaderFileModule $module */ $module = $resourceLoader->getModule( $moduleName ); '@phan-var ResourceLoaderFileModule $module'; if ( !$module ) { // T98043: Don't fatal, but it won't look as pretty. continue; } // Based on: ResourceLoaderFileModule::getStyles (without the DB query) $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles( $module->readStyleFiles( $module->getStyleFiles( $rlContext ), $rlContext ) ) ); } return implode( "\n", $styles ); } /** * "" to index.php?css=1 for the "
" * * @return string */ private function getCssUrl() { return Html::linkedStyle( $this->parent->getUrl( [ 'css' => 1 ] ) ); } public function useShortHeader( $use = true ) { $this->useShortHeader = $use; } public function allowFrames( $allow = true ) { $this->allowFrames = $allow; } public function flush() { if ( !$this->headerDone ) { $this->outputHeader(); } if ( !$this->redirectTarget && strlen( $this->contents ) ) { echo $this->contents; flush(); $this->contents = ''; } } /** * @since 1.33 * @return Language */ private function getLanguage() { global $wgLang; return is_object( $wgLang ) ? $wgLang : MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage( 'en' ); } /** * @return string[] */ public function getHeadAttribs() { return [ 'dir' => $this->getLanguage()->getDir(), 'lang' => $this->getLanguage()->getHtmlCode(), ]; } /** * Get whether the header has been output * * @return bool */ public function headerDone() { return $this->headerDone; } public function outputHeader() { $this->headerDone = true; $this->parent->request->response()->header( 'Content-Type: text/html; charset=utf-8' ); if ( !$this->allowFrames ) { $this->parent->request->response()->header( 'X-Frame-Options: DENY' ); } if ( $this->redirectTarget ) { $this->parent->request->response()->header( 'Location: ' . $this->redirectTarget ); return; } if ( $this->useShortHeader ) { $this->outputShortHeader(); return; } ?> getHeadAttribs() ); ?>