Unify MonoBook <head> generation with legacy skins
This was less work than I thought it would be. The only possible practical difference in MonoBook should be that some IE fixes are moved down; at a glance, I don't see how this would hurt anything, but if it does then some more hacks can be added to move them back up. A bunch of whitespace was changed in both MonoBook and legacy skins. Legacy skins had some stuff moved around in the <head>, but mainly to better match MonoBook, so they should work better if anything, not worse. dir= was added to the <body> in legacy skins, matching MonoBook. There should be no other practical differences. I would strongly encourage people to port the Modern and Vector skins to at least share the <head>-generation code like this. I'd even more strongly encourage people to totally rewrite the skin system, but that's a bigger job. :)
This commit is contained in:
parent
fee18093bd
commit
c4012b03bc
4 changed files with 69 additions and 51 deletions
|
|
@ -93,7 +93,7 @@ class OutputPage {
|
|||
array_push( $this->mKeywords, $text );
|
||||
}
|
||||
}
|
||||
function addScript( $script ) { $this->mScripts .= "\t\t" . $script . "\n"; }
|
||||
function addScript( $script ) { $this->mScripts .= "\t" . $script . "\n"; }
|
||||
|
||||
function addExtensionStyle( $url ) {
|
||||
$linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
|
||||
|
|
@ -1548,8 +1548,10 @@ class OutputPage {
|
|||
global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
|
||||
global $wgContLang, $wgUseTrackbacks, $wgStyleVersion;
|
||||
|
||||
$this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
|
||||
$this->addStyle( 'common/wikiprintable.css', 'print' );
|
||||
$this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
|
||||
if ( $sk->commonPrintStylesheet() ) {
|
||||
$this->addStyle( 'common/wikiprintable.css', 'print' );
|
||||
}
|
||||
$sk->setupUserCss( $this );
|
||||
|
||||
$ret = '';
|
||||
|
|
@ -1558,24 +1560,23 @@ class OutputPage {
|
|||
$ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
|
||||
}
|
||||
|
||||
$ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
|
||||
$ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
|
||||
|
||||
if ( '' == $this->getHTMLTitle() ) {
|
||||
$this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
|
||||
}
|
||||
|
||||
$rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
|
||||
$dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
|
||||
$ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
|
||||
foreach($wgXhtmlNamespaces as $tag => $ns) {
|
||||
$ret .= "xmlns:{$tag}=\"{$ns}\" ";
|
||||
}
|
||||
$ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
|
||||
$ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t\t";
|
||||
$ret .= implode( "\t\t", array(
|
||||
$ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
|
||||
$ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
|
||||
$ret .= implode( "\n", array(
|
||||
$this->getHeadLinks(),
|
||||
$this->buildCssLinks(),
|
||||
$sk->getHeadScripts( $this->mAllowUserJs ),
|
||||
$this->mScripts,
|
||||
$sk->getHeadScripts( $this->mAllowUserJs, $this->mScripts ),
|
||||
$this->getHeadItems(),
|
||||
));
|
||||
if( $sk->usercss ){
|
||||
|
|
@ -1591,6 +1592,14 @@ class OutputPage {
|
|||
|
||||
protected function addDefaultMeta() {
|
||||
global $wgVersion;
|
||||
|
||||
static $called = false;
|
||||
if ( $called ) {
|
||||
# Don't run this twice
|
||||
return;
|
||||
}
|
||||
$called = true;
|
||||
|
||||
$this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
|
||||
$this->addMeta( 'generator', "MediaWiki $wgVersion" );
|
||||
|
||||
|
|
@ -1679,7 +1688,7 @@ class OutputPage {
|
|||
}
|
||||
}
|
||||
|
||||
return implode( "\n\t\t", $tags ) . "\n";
|
||||
return implode( "\n\t", $tags ) . "\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1746,7 +1755,7 @@ class OutputPage {
|
|||
$links[] = $link;
|
||||
}
|
||||
|
||||
return implode( "\n\t\t", $links );
|
||||
return "\t" . implode( "\n\t", $links );
|
||||
}
|
||||
|
||||
protected function styleLink( $style, $options ) {
|
||||
|
|
|
|||
|
|
@ -447,12 +447,31 @@ class Skin extends Linker {
|
|||
return self::makeVariablesScript( $vars );
|
||||
}
|
||||
|
||||
function getHeadScripts( $allowUserJs ) {
|
||||
/**
|
||||
* Return a random selection of the scripts we want in the header,
|
||||
* according to no particular rhyme or reason. Various other scripts are
|
||||
* returned from a haphazard assortment of other functions scattered over
|
||||
* various files. This entire hackish system needs to be burned to the
|
||||
* ground and rebuilt.
|
||||
*
|
||||
* @var $allowUserJs bool Should probably be identical to $wgAllowUserJs,
|
||||
* but is passed as a local variable for some
|
||||
* obscure reason.
|
||||
* @var $extraHtml string A bunch of raw HTML to jam into some arbitrary
|
||||
* place where MonoBook has historically wanted it.
|
||||
* Old-style skins formerly put it in a different
|
||||
* place, but if either of those is broken it's
|
||||
* likely to be the old-style skins.
|
||||
* @return string Raw HTML to output in some location in the <head> that's
|
||||
* entirely arbitrary but which will probably break
|
||||
* everything if you put it someplace else.
|
||||
*/
|
||||
function getHeadScripts( $allowUserJs, $extraHtml = '' ) {
|
||||
global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
|
||||
|
||||
$vars = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
|
||||
|
||||
$r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
|
||||
$r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n$extraHtml" );
|
||||
global $wgUseSiteJs;
|
||||
if( $wgUseSiteJs ) {
|
||||
$jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
|
||||
|
|
@ -460,7 +479,7 @@ class Skin extends Linker {
|
|||
htmlspecialchars( self::makeUrl( '-',
|
||||
"action=raw$jsCache&gen=js&useskin=" .
|
||||
urlencode( $this->getSkinName() ) ) ) .
|
||||
"\"><!-- site js --></script>";
|
||||
"\"></script>";
|
||||
}
|
||||
if( $allowUserJs && $wgUser->isLoggedIn() ) {
|
||||
$userpage = $wgUser->getUserPage();
|
||||
|
|
@ -469,7 +488,7 @@ class Skin extends Linker {
|
|||
'action=raw&ctype='.$wgJsMimeType ) );
|
||||
$r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
|
||||
}
|
||||
return $vars . "\t\t" . implode ( "\n\t\t", $r );
|
||||
return $vars . "\t" . implode ( "\n\t", $r );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -2055,4 +2074,16 @@ END;
|
|||
wfProfileOut( __METHOD__ );
|
||||
return $bar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Should we include common/wikiprintable.css? Skins that have their own
|
||||
* print stylesheet should override this and return false. (This is an
|
||||
* ugly hack to get Monobook to play nicely with
|
||||
* OutputPage::headElement().)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function commonPrintStylesheet() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1017,6 +1017,10 @@ class SkinTemplate extends Skin {
|
|||
wfProfileOut( __METHOD__ );
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function commonPrintStylesheet() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -64,49 +64,23 @@ class MonoBookTemplate extends QuickTemplate {
|
|||
* @access private
|
||||
*/
|
||||
function execute() {
|
||||
global $wgRequest;
|
||||
global $wgRequest, $wgOut, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
|
||||
$this->skin = $skin = $this->data['skin'];
|
||||
$action = $wgRequest->getText( 'action' );
|
||||
|
||||
// Suppress warnings to prevent notices about missing indexes in $this->data
|
||||
wfSuppressWarnings();
|
||||
|
||||
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="<?php $this->text('xhtmldefaultnamespace') ?>" <?php
|
||||
foreach($this->data['xhtmlnamespaces'] as $tag => $ns) {
|
||||
?>xmlns:<?php echo "{$tag}=\"{$ns}\" ";
|
||||
} ?>xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
|
||||
<?php $this->html('headlinks') ?>
|
||||
<title><?php $this->text('pagetitle') ?></title>
|
||||
<?php $this->html('csslinks') ?>
|
||||
$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
|
||||
);
|
||||
|
||||
<!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
|
||||
<meta http-equiv="imagetoolbar" content="no" /><![endif]-->
|
||||
echo $wgOut->headElement( $this->skin );
|
||||
|
||||
<?php print Skin::makeGlobalVariablesScript( $this->data ); ?>
|
||||
|
||||
<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
|
||||
<?php $this->html('headscripts') ?>
|
||||
<?php if($this->data['jsvarurl']) { ?>
|
||||
<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl') ?>"></script>
|
||||
<?php } ?>
|
||||
<?php if($this->data['pagecss']) { ?>
|
||||
<style type="text/css"><?php $this->html('pagecss') ?></style>
|
||||
<?php }
|
||||
if($this->data['usercss']) { ?>
|
||||
<style type="text/css"><?php $this->html('usercss') ?></style>
|
||||
<?php }
|
||||
if($this->data['userjs']) { ?>
|
||||
<script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('userjs' ) ?>"></script>
|
||||
<?php }
|
||||
if($this->data['userjsprev']) { ?>
|
||||
<script type="<?php $this->text('jsmimetype') ?>"><?php $this->html('userjsprev') ?></script>
|
||||
<?php }
|
||||
if($this->data['trackbackhtml']) print $this->data['trackbackhtml']; ?>
|
||||
</head>
|
||||
<body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
|
||||
?><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') ?>">
|
||||
<div id="globalWrapper">
|
||||
|
|
|
|||
Loading…
Reference in a new issue