From c4012b03bcf5d8c46343c9294260932ec55d6f5b Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 7 Jul 2009 21:49:45 +0000 Subject: [PATCH] Unify MonoBook 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 , but mainly to better match MonoBook, so they should work better if anything, not worse. dir= was added to the 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 -generation code like this. I'd even more strongly encourage people to totally rewrite the skin system, but that's a bigger job. :) --- includes/OutputPage.php | 33 ++++++++++++++++++----------- includes/Skin.php | 39 ++++++++++++++++++++++++++++++---- includes/SkinTemplate.php | 4 ++++ skins/MonoBook.php | 44 ++++++++------------------------------- 4 files changed, 69 insertions(+), 51 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 4e02598aeb..36ca6ae7f3 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 .= "\n"; } - $ret .= "\n"; + $ret .= "\n"; if ( '' == $this->getHTMLTitle() ) { $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() )); } - $rtl = $wgContLang->isRTL() ? " dir='RTL'" : ''; + $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr'; $ret .= " $ns) { $ret .= "xmlns:{$tag}=\"{$ns}\" "; } - $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n"; - $ret .= "\n" . htmlspecialchars( $this->getHTMLTitle() ) . "\n\t\t"; - $ret .= implode( "\t\t", array( + $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n"; + $ret .= "\n\t" . htmlspecialchars( $this->getHTMLTitle() ) . "\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 ) { diff --git a/includes/Skin.php b/includes/Skin.php index a6f024520d..644b06a9d8 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -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 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( "" ); + $r = array( "\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() ) ) ) . - "\">"; + "\">"; } if( $allowUserJs && $wgUser->isLoggedIn() ) { $userpage = $wgUser->getUserPage(); @@ -469,7 +488,7 @@ class Skin extends Linker { 'action=raw&ctype='.$wgJsMimeType ) ); $r[] = '"; } - 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; + } } diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 2238f835c3..5b238e0731 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -1017,6 +1017,10 @@ class SkinTemplate extends Skin { wfProfileOut( __METHOD__ ); return $out; } + + public function commonPrintStylesheet() { + return false; + } } /** diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 00b7141f82..d380e2ae06 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -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(); -?> -data['xhtmlnamespaces'] as $tag => $ns) { - ?>xmlns:xml:lang="text('lang') ?>" lang="text('lang') ?>" dir="text('dir') ?>"> - - - html('headlinks') ?> - <?php $this->text('pagetitle') ?> - html('csslinks') ?> - - + $path = htmlspecialchars( $wgStylePath ); + $wgOut->addScript( << + +HTML + ); - data ); ?> + echo $wgOut->headElement( $this->skin ); - -html('headscripts') ?> -data['jsvarurl']) { ?> - - -data['pagecss']) { ?> - -data['usercss']) { ?> - -data['userjs']) { ?> - -data['userjsprev']) { ?> - -data['trackbackhtml']) print $this->data['trackbackhtml']; ?> - -data['body_ondblclick']) { ?> ondblclick="text('body_ondblclick') ?>" +?>data['body_ondblclick']) { ?> ondblclick="text('body_ondblclick') ?>" data['body_onload']) { ?> onload="text('body_onload') ?>" class="mediawiki text('dir'); $this->text('capitalizeallnouns') ?> text('pageclass') ?> text('skinnameclass') ?>">
-- 2.20.1