r52864 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52863‎ | r52864 | r52865 >
Date:21:49, 7 July 2009
Author:simetrical
Status:ok
Tags:
Comment:
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. :)
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/skins/MonoBook.php (modified) (history)

Diff [purge]

Index: trunk/phase3/skins/MonoBook.php
@@ -64,49 +64,23 @@
6565 * @access private
6666 */
6767 function execute() {
68 - global $wgRequest;
 68+ global $wgRequest, $wgOut, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
6969 $this->skin = $skin = $this->data['skin'];
7070 $action = $wgRequest->getText( 'action' );
7171
7272 // Suppress warnings to prevent notices about missing indexes in $this->data
7373 wfSuppressWarnings();
7474
75 -?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
76 -<html xmlns="<?php $this->text('xhtmldefaultnamespace') ?>" <?php
77 - foreach($this->data['xhtmlnamespaces'] as $tag => $ns) {
78 - ?>xmlns:<?php echo "{$tag}=\"{$ns}\" ";
79 - } ?>xml:lang="<?php $this->text('lang') ?>" lang="<?php $this->text('lang') ?>" dir="<?php $this->text('dir') ?>">
80 - <head>
81 - <meta http-equiv="Content-Type" content="<?php $this->text('mimetype') ?>; charset=<?php $this->text('charset') ?>" />
82 - <?php $this->html('headlinks') ?>
83 - <title><?php $this->text('pagetitle') ?></title>
84 - <?php $this->html('csslinks') ?>
 75+ $path = htmlspecialchars( $wgStylePath );
 76+ $wgOut->addScript( <<<HTML
 77+<!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
 78+ <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
 79+HTML
 80+ );
8581
86 - <!--[if lt IE 7]><script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath') ?>/common/IEFixes.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
87 - <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
 82+ echo $wgOut->headElement( $this->skin );
8883
89 - <?php print Skin::makeGlobalVariablesScript( $this->data ); ?>
90 -
91 - <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('stylepath' ) ?>/common/wikibits.js?<?php echo $GLOBALS['wgStyleVersion'] ?>"></script>
92 -<?php $this->html('headscripts') ?>
93 -<?php if($this->data['jsvarurl']) { ?>
94 - <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('jsvarurl') ?>"></script>
95 -<?php } ?>
96 -<?php if($this->data['pagecss']) { ?>
97 - <style type="text/css"><?php $this->html('pagecss') ?></style>
98 -<?php }
99 - if($this->data['usercss']) { ?>
100 - <style type="text/css"><?php $this->html('usercss') ?></style>
101 -<?php }
102 - if($this->data['userjs']) { ?>
103 - <script type="<?php $this->text('jsmimetype') ?>" src="<?php $this->text('userjs' ) ?>"></script>
104 -<?php }
105 - if($this->data['userjsprev']) { ?>
106 - <script type="<?php $this->text('jsmimetype') ?>"><?php $this->html('userjsprev') ?></script>
107 -<?php }
108 - if($this->data['trackbackhtml']) print $this->data['trackbackhtml']; ?>
109 - </head>
110 -<body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
 84+?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
11185 <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
11286 class="mediawiki <?php $this->text('dir'); $this->text('capitalizeallnouns') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
11387 <div id="globalWrapper">
Index: trunk/phase3/includes/OutputPage.php
@@ -93,7 +93,7 @@
9494 array_push( $this->mKeywords, $text );
9595 }
9696 }
97 - function addScript( $script ) { $this->mScripts .= "\t\t" . $script . "\n"; }
 97+ function addScript( $script ) { $this->mScripts .= "\t" . $script . "\n"; }
9898
9999 function addExtensionStyle( $url ) {
100100 $linkarr = array( 'rel' => 'stylesheet', 'href' => $url, 'type' => 'text/css' );
@@ -1548,8 +1548,10 @@
15491549 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
15501550 global $wgContLang, $wgUseTrackbacks, $wgStyleVersion;
15511551
1552 - $this->addMeta( "http:Content-type", "$wgMimeType; charset={$wgOutputEncoding}" );
1553 - $this->addStyle( 'common/wikiprintable.css', 'print' );
 1552+ $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" );
 1553+ if ( $sk->commonPrintStylesheet() ) {
 1554+ $this->addStyle( 'common/wikiprintable.css', 'print' );
 1555+ }
15541556 $sk->setupUserCss( $this );
15551557
15561558 $ret = '';
@@ -1558,24 +1560,23 @@
15591561 $ret .= "<?xml version=\"1.0\" encoding=\"$wgOutputEncoding\" ?" . ">\n";
15601562 }
15611563
1562 - $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\"\n \"$wgDTD\">\n";
 1564+ $ret .= "<!DOCTYPE html PUBLIC \"$wgDocType\" \"$wgDTD\">\n";
15631565
15641566 if ( '' == $this->getHTMLTitle() ) {
15651567 $this->setHTMLTitle( wfMsg( 'pagetitle', $this->getPageTitle() ));
15661568 }
15671569
1568 - $rtl = $wgContLang->isRTL() ? " dir='RTL'" : '';
 1570+ $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
15691571 $ret .= "<html xmlns=\"{$wgXhtmlDefaultNamespace}\" ";
15701572 foreach($wgXhtmlNamespaces as $tag => $ns) {
15711573 $ret .= "xmlns:{$tag}=\"{$ns}\" ";
15721574 }
1573 - $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" $rtl>\n";
1574 - $ret .= "<head>\n<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t\t";
1575 - $ret .= implode( "\t\t", array(
 1575+ $ret .= "xml:lang=\"$wgContLanguageCode\" lang=\"$wgContLanguageCode\" dir=\"$dir\">\n";
 1576+ $ret .= "<head>\n\t<title>" . htmlspecialchars( $this->getHTMLTitle() ) . "</title>\n\t";
 1577+ $ret .= implode( "\n", array(
15761578 $this->getHeadLinks(),
15771579 $this->buildCssLinks(),
1578 - $sk->getHeadScripts( $this->mAllowUserJs ),
1579 - $this->mScripts,
 1580+ $sk->getHeadScripts( $this->mAllowUserJs, $this->mScripts ),
15801581 $this->getHeadItems(),
15811582 ));
15821583 if( $sk->usercss ){
@@ -1591,6 +1592,14 @@
15921593
15931594 protected function addDefaultMeta() {
15941595 global $wgVersion;
 1596+
 1597+ static $called = false;
 1598+ if ( $called ) {
 1599+ # Don't run this twice
 1600+ return;
 1601+ }
 1602+ $called = true;
 1603+
15951604 $this->addMeta( 'http:Content-Style-Type', 'text/css' ); //bug 15835
15961605 $this->addMeta( 'generator', "MediaWiki $wgVersion" );
15971606
@@ -1679,7 +1688,7 @@
16801689 }
16811690 }
16821691
1683 - return implode( "\n\t\t", $tags ) . "\n";
 1692+ return implode( "\n\t", $tags ) . "\n";
16841693 }
16851694
16861695 /**
@@ -1746,7 +1755,7 @@
17471756 $links[] = $link;
17481757 }
17491758
1750 - return implode( "\n\t\t", $links );
 1759+ return "\t" . implode( "\n\t", $links );
17511760 }
17521761
17531762 protected function styleLink( $style, $options ) {
Index: trunk/phase3/includes/SkinTemplate.php
@@ -1017,6 +1017,10 @@
10181018 wfProfileOut( __METHOD__ );
10191019 return $out;
10201020 }
 1021+
 1022+ public function commonPrintStylesheet() {
 1023+ return false;
 1024+ }
10211025 }
10221026
10231027 /**
Index: trunk/phase3/includes/Skin.php
@@ -447,12 +447,31 @@
448448 return self::makeVariablesScript( $vars );
449449 }
450450
451 - function getHeadScripts( $allowUserJs ) {
 451+ /**
 452+ * Return a random selection of the scripts we want in the header,
 453+ * according to no particular rhyme or reason. Various other scripts are
 454+ * returned from a haphazard assortment of other functions scattered over
 455+ * various files. This entire hackish system needs to be burned to the
 456+ * ground and rebuilt.
 457+ *
 458+ * @var $allowUserJs bool Should probably be identical to $wgAllowUserJs,
 459+ * but is passed as a local variable for some
 460+ * obscure reason.
 461+ * @var $extraHtml string A bunch of raw HTML to jam into some arbitrary
 462+ * place where MonoBook has historically wanted it.
 463+ * Old-style skins formerly put it in a different
 464+ * place, but if either of those is broken it's
 465+ * likely to be the old-style skins.
 466+ * @return string Raw HTML to output in some location in the <head> that's
 467+ * entirely arbitrary but which will probably break
 468+ * everything if you put it someplace else.
 469+ */
 470+ function getHeadScripts( $allowUserJs, $extraHtml = '' ) {
452471 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
453472
454473 $vars = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
455474
456 - $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>" );
 475+ $r = array( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n$extraHtml" );
457476 global $wgUseSiteJs;
458477 if( $wgUseSiteJs ) {
459478 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
@@ -460,7 +479,7 @@
461480 htmlspecialchars( self::makeUrl( '-',
462481 "action=raw$jsCache&gen=js&useskin=" .
463482 urlencode( $this->getSkinName() ) ) ) .
464 - "\"><!-- site js --></script>";
 483+ "\"></script>";
465484 }
466485 if( $allowUserJs && $wgUser->isLoggedIn() ) {
467486 $userpage = $wgUser->getUserPage();
@@ -469,7 +488,7 @@
470489 'action=raw&ctype='.$wgJsMimeType ) );
471490 $r[] = '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>";
472491 }
473 - return $vars . "\t\t" . implode ( "\n\t\t", $r );
 492+ return $vars . "\t" . implode ( "\n\t", $r );
474493 }
475494
476495 /**
@@ -2055,4 +2074,16 @@
20562075 wfProfileOut( __METHOD__ );
20572076 return $bar;
20582077 }
 2078+
 2079+ /**
 2080+ * Should we include common/wikiprintable.css? Skins that have their own
 2081+ * print stylesheet should override this and return false. (This is an
 2082+ * ugly hack to get Monobook to play nicely with
 2083+ * OutputPage::headElement().)
 2084+ *
 2085+ * @return bool
 2086+ */
 2087+ public function commonPrintStylesheet() {
 2088+ return true;
 2089+ }
20592090 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r52925fix for r52864: PHP Strict Standards: Declaration of SkinStandard::getHeadSc...ialex17:09, 8 July 2009
r53029Finish cross-skin unification of <head>...simetrical02:13, 10 July 2009

Status & tagging log