* introduced SkinTemplate::$useHeadElement as switch for backward compatibility for extension skins using the old way of generating the <head> element:
** false (default): no change from previous version
** true: <head> specific items set in SkinTemplate::outputPage() are no longer generated (avoid double execution of some functions) and the result of OutputPage::headElement() is stored in the 'headelement' item
* updated all core skin to use this new method, some extensions using MonoBookTemplate but not extending SkinMonoBook (or for other core skins) will need to set $useHeadElement to true to work properly though
* Made Skin::userCanPreview() public since it's needed in OutputPage::getHeadScripts()
* Pass the Skin object from OutputPage::headElement() to OutputPage::getHeadScripts() rather than getting it from $wgUser
*
* @param $sk Skin The given Skin
*/
- public function headElement( Skin $sk , $includeStyle = true ) {
+ public function headElement( Skin $sk, $includeStyle = true ) {
global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType;
global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgEnableScriptLoader, $wgHtml5;
$ret .= implode( "\n", array(
$this->getHeadLinks(),
$this->buildCssLinks(),
- $this->getHeadScripts(),
+ $this->getHeadScripts( $sk ),
$this->getHeadItems(),
));
if( $sk->usercss ){
*
* also adds userjs to the end if enabled:
*/
- function getHeadScripts() {
- global $wgUser, $wgJsMimeType;
- $sk = $wgUser->getSkin();
+ function getHeadScripts( Skin $sk ) {
+ global $wgUser, $wgRequest, $wgJsMimeType;
$vars = Skin::makeGlobalVariablesScript( $sk->getSkinName() );
//add user js if enabled:
if( $this->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
- $userpage = $wgUser->getUserPage();
- $userjs = Skin::makeUrl(
- $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
- 'action=raw&ctype=' . $wgJsMimeType );
- $this->addScriptFile( $userjs );
+ $action = $wgRequest->getVal( 'action', 'view' );
+ if( $this->mTitle->isJsSubpage() and $sk->userCanPreview( $action ) ) {
+ # XXX: additional security check/prompt?
+ $this->addInlineScript( $wgRequest->getText( 'wpTextbox1' ) );
+ } else {
+ $userpage = $wgUser->getUserPage();
+ $userjs = Skin::makeUrl(
+ $userpage->getPrefixedText() . '/' . $sk->getSkinName() . '.js',
+ 'action=raw&ctype=' . $wgJsMimeType );
+ $this->addScriptFile( $userjs );
+ }
}
return $vars . "\n" . $this->mScripts;
*
* @param string $action
* @return bool
- * @private
*/
- function userCanPreview( $action ) {
+ public function userCanPreview( $action ) {
global $wgRequest, $wgUser;
if( $action != 'submit' )
$action = $wgRequest->getVal( 'action' );
# If we're previewing the CSS page, use it
if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
- $previewCss = $wgRequest->getText( 'wpTextbox1' );
// @FIXME: properly escape the cdata!
- $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
+ $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
} else {
$out->addStyle( self::makeUrl( $this->userpage . '/' . $this->getSkinName() .'.css',
'action=raw&ctype=text/css' ) );
*/
var $template = 'QuickTemplate';
+ /**
+ * Whether this skin use OutputPage::headElement() to generate the <head>
+ * tag
+ */
+ var $useHeadElement = false;
+
/**#@-*/
/**
$this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
}
- $this->userjs = $this->userjsprev = false;
- $this->setupUserCss( $out );
- $this->setupUserJs( $out->isUserJsAllowed() );
$this->titletxt = $this->mTitle->getPrefixedText();
wfProfileOut( __METHOD__ . '-stuff' );
+ wfProfileIn( __METHOD__ . '-stuff-head' );
+ if ( $this->useHeadElement ) {
+ $pagecss = $this->setupPageCss();
+ if( $pagecss )
+ $out->addInlineStyle( $pagecss );
+ } else {
+ $this->setupUserCss( $out );
+
+ $tpl->set( 'pagecss', $this->setupPageCss() );
+ $tpl->setRef( 'usercss', $this->usercss );
+
+ $this->userjs = $this->userjsprev = false;
+ $this->setupUserJs( $out->isUserJsAllowed() );
+ $tpl->setRef( 'userjs', $this->userjs );
+ $tpl->setRef( 'userjsprev', $this->userjsprev );
+
+ if( $wgUseSiteJs ) {
+ $jsCache = $this->loggedin ? '&smaxage=0' : '';
+ $tpl->set( 'jsvarurl',
+ self::makeUrl( '-',
+ "action=raw$jsCache&gen=js&useskin=" .
+ urlencode( $this->getSkinName() ) ) );
+ } else {
+ $tpl->set( 'jsvarurl', false );
+ }
+
+ $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
+ $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
+ $tpl->set( 'headlinks', $out->getHeadLinks() );
+ $tpl->set( 'csslinks', $out->buildCssLinks() );
+
+ if( $wgUseTrackbacks && $out->isArticleRelated() ) {
+ $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
+ } else {
+ $tpl->set( 'trackbackhtml', null );
+ }
+ }
+ wfProfileOut( __METHOD__ . '-stuff-head' );
+
wfProfileIn( __METHOD__ . '-stuff2' );
$tpl->set( 'title', $out->getPageTitle() );
$tpl->set( 'pagetitle', $out->getHTMLTitle() );
} else {
$tpl->set( 'feeds', false );
}
- if( $wgUseTrackbacks && $out->isArticleRelated() ) {
- $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
- } else {
- $tpl->set( 'trackbackhtml', null );
- }
- $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
- $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
$tpl->setRef( 'mimetype', $wgMimeType );
$tpl->setRef( 'jsmimetype', $wgJsMimeType );
$tpl->setRef( 'charset', $wgOutputEncoding );
- $tpl->set( 'headlinks', $out->getHeadLinks() );
- $tpl->set( 'csslinks', $out->buildCssLinks() );
$tpl->setRef( 'wgScript', $wgScript );
$tpl->setRef( 'skinname', $this->skinname );
$tpl->set( 'skinclass', get_class( $this ) );
$tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
$tpl->set( 'userlang', $wgLang->getCode() );
$tpl->set( 'userlangattributes', 'lang="' . $wgLang->getCode() . '" xml:lang="' . $wgLang->getCode() . '"' );
- $tpl->set( 'pagecss', $this->setupPageCss() );
- $tpl->setRef( 'usercss', $this->usercss );
- $tpl->setRef( 'userjs', $this->userjs );
- $tpl->setRef( 'userjsprev', $this->userjsprev );
- if( $wgUseSiteJs ) {
- $jsCache = $this->loggedin ? '&smaxage=0' : '';
- $tpl->set( 'jsvarurl',
- self::makeUrl( '-',
- "action=raw$jsCache&gen=js&useskin=" .
- urlencode( $this->getSkinName() ) ) );
- } else {
- $tpl->set( 'jsvarurl', false );
- }
$newtalks = $wgUser->getNewMessageLinks();
$tpl->set( 'nav_urls', $this->buildNavUrls() );
// Set the head scripts near the end, in case the above actions resulted in added scripts
- $tpl->set( 'headscripts', $out->getScript() );
+ if ( $this->useHeadElement ) {
+ $tpl->set( 'headelement', $out->headElement( $this ) );
+ } else {
+ $tpl->set( 'headscripts', $out->getScript() );
+ }
// original version by hansm
if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
* @ingroup Skins
*/
class SkinChick extends SkinTemplate {
- function initPage( OutputPage $out ) {
- parent::initPage( $out );
- $this->skinname = 'chick';
- $this->stylename = 'chick';
- $this->template = 'MonoBookTemplate';
- }
+ var $skinname = 'chick', $stylename = 'chick',
+ $template = 'MonoBookTemplate', $useHeadElement = true;
function setupSkinUserCss( OutputPage $out ){
parent::setupSkinUserCss( $out );
*/
class SkinModern extends SkinTemplate {
var $skinname = 'modern', $stylename = 'modern',
- $template = 'ModernTemplate';
+ $template = 'ModernTemplate', $useHeadElement = true;
/*
* We don't like the default getPoweredBy, the icon clashes with the
}
function setupSkinUserCss( OutputPage $out ){
+ global $wgStyleVersion, $wgJsMimeType, $wgStylePath;
+
// Do not call parent::setupSkinUserCss(), we have our own print style
$out->addStyle( 'common/shared.css', 'screen' );
$out->addStyle( 'modern/main.css', 'screen' );
$out->addStyle( 'modern/print.css', 'print' );
$out->addStyle( 'modern/rtl.css', 'screen', '', 'rtl' );
+
+ $path = htmlspecialchars( $wgStylePath );
+ $out->addScript( <<<HTML
+<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
+ <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
+HTML
+ );
}
}
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
- $wgOut->addScript( <<<HTML
-<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
- <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
-HTML
- );
-
- echo $wgOut->headElement( $this->skin );
+ $this->html( 'headelement' );
?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
<?php if($this->data['body_onload' ]) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
class SkinMonoBook extends SkinTemplate {
/** Using monobook. */
var $skinname = 'monobook', $stylename = 'monobook',
- $template = 'MonoBookTemplate';
+ $template = 'MonoBookTemplate', $useHeadElement = true;
function setupSkinUserCss( OutputPage $out ) {
- global $wgHandheldStyle;
+ global $wgHandheldStyle, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
parent::setupSkinUserCss( $out );
$out->addStyle( 'monobook/rtl.css', 'screen', '', 'rtl' );
-
- // @todo We can move this to the parent once we update all the skins
- if( isset( $this->pagecss ) && $this->pagecss )
- $out->addInlineStyle( $this->pagecss );
-
- if( isset( $this->usercss ) && $this->usercss )
- $out->addInlineStyle( $this->usercss );
-
+ # FIXME: What is this? Should it apply to all skins?
+ $path = htmlspecialchars( $wgStylePath );
+ $out->addScript( <<<HTML
+<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
+ <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
+HTML
+ );
}
}
* @access private
*/
function execute() {
- global $wgRequest, $wgOut, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
+ global $wgRequest;
+
$this->skin = $skin = $this->data['skin'];
$action = $wgRequest->getText( 'action' );
// Suppress warnings to prevent notices about missing indexes in $this->data
wfSuppressWarnings();
- # FIXME: What is this? Should it apply to all skins?
- $path = htmlspecialchars( $wgStylePath );
- $wgOut->addScript( <<<HTML
-<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
- <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
-HTML
- );
-
- echo $wgOut->headElement( $this->skin );
-
+ $this->html( 'headelement' );
?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
<?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
class="mediawiki <?php $this->text('dir'); $this->text('capitalizeallnouns') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
*/
class SkinMySkin extends SkinTemplate {
var $skinname = 'myskin', $stylename = 'myskin',
- $template = 'MonoBookTemplate';
+ $template = 'MonoBookTemplate', $useHeadElement = true;
}
*/
class SkinSimple extends SkinTemplate {
var $skinname = 'simple', $stylename = 'simple',
- $template = 'MonoBookTemplate';
+ $template = 'MonoBookTemplate', $useHeadElement = true;
function setupSkinUserCss( OutputPage $out ){
$out->addStyle( 'simple/main.css', 'screen' );
/* Functions */
var $skinname = 'vector', $stylename = 'vector',
- $template = 'VectorTemplate';
+ $template = 'VectorTemplate', $useHeadElement = true;
/**
* Initializes output page and sets up skin-specific parameters
array_reverse( $this->data['personal_urls'] );
}
// Output HTML Page
- echo $wgOut->headElement( $this->skin );
+ $this->html( 'headelement' );
?>
<body<?php if ( $this->data['body_ondblclick'] ): ?> ondblclick="<?php $this->text( 'body_ondblclick' ) ?>"<?php endif; ?> <?php if ( $this->data['body_onload'] ): ?> onload="<?php $this->text( 'body_onload' ) ?>"<?php endif; ?> class="mediawiki <?php $this->text( 'dir' ) ?> <?php $this->text( 'pageclass' ) ?> <?php $this->text( 'skinnameclass' ) ?>" dir="<?php $this->text( 'dir' ) ?>">
<div id="page-base" class="noprint"></div>