From 010c456825ef537851976ee91802a2cc5553b3bf Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Fri, 15 Jan 2010 01:16:52 +0000 Subject: [PATCH] Merge all skins' output of opening tag This fixes a few minor discrepancies, like Vector outputting dir="" (redundant to the one on ), and non-Monobook-based skins omitting the capitalize-all-nouns class (!). This adds Html::openElement() and refactors Html::rawElement() accordingly, so I checked that all parser tests still pass. I wasn't able to figure out if I broke some feature of right-floating quickbars in the Standard skin, because I wasn't able to figure out what the feature was in the first place. Hopefully either it works, or nobody cares, or someone else will figure out what it was supposed to do. (This is the stuff in getBodyOptions() in Standard.php I deleted; I'm not sure the addition to sticky.js does what I want.) --- includes/Html.php | 56 ++++++++++++++++++++++---------------- includes/OutputPage.php | 33 ++++++++++++++++++++++ includes/Skin.php | 29 -------------------- includes/SkinTemplate.php | 7 ----- skins/Modern.php | 3 +- skins/MonoBook.php | 4 +-- skins/Standard.php | 17 ------------ skins/Vector.php | 1 - skins/common/oldshared.css | 7 +++++ skins/common/sticky.js | 2 ++ 10 files changed, 77 insertions(+), 82 deletions(-) diff --git a/includes/Html.php b/includes/Html.php index 667e58b675..a17e033466 100644 --- a/includes/Html.php +++ b/includes/Html.php @@ -106,6 +106,37 @@ class Html { * @return string Raw HTML */ public static function rawElement( $element, $attribs = array(), $contents = '' ) { + global $wgWellFormedXml; + $start = self::openElement( $element, $attribs ); + if ( in_array( $element, self::$voidElements ) ) { + if ( $wgWellFormedXml ) { + # Silly XML. + return substr( $start, 0, -1 ) . ' />'; + } + return $start; + } else { + return "$start$contents"; + } + } + + /** + * Identical to rawElement(), but HTML-escapes $contents (like + * Xml::element()). + */ + public static function element( $element, $attribs = array(), $contents = '' ) { + return self::rawElement( $element, $attribs, strtr( $contents, array( + # There's no point in escaping quotes, >, etc. in the contents of + # elements. + '&' => '&', + '<' => '<' + ) ) ); + } + + /** + * Identical to rawElement(), but has no third parameter and omits the end + * tag (and the self-closing / in XML mode for empty elements). + */ + public static function openElement( $element, $attribs = array() ) { global $wgHtml5, $wgWellFormedXml; $attribs = (array)$attribs; # This is not required in HTML5, but let's do it anyway, for @@ -155,29 +186,8 @@ class Html { } } - $start = "<$element" . self::expandAttributes( - self::dropDefaults( $element, $attribs ) ); - if ( in_array( $element, self::$voidElements ) ) { - if ( $wgWellFormedXml ) { - return "$start />"; - } - return "$start>"; - } else { - return "$start>$contents"; - } - } - - /** - * Identical to rawElement(), but HTML-escapes $contents (like - * Xml::element()). - */ - public static function element( $element, $attribs = array(), $contents = '' ) { - return self::rawElement( $element, $attribs, strtr( $contents, array( - # There's no point in escaping quotes, >, etc. in the contents of - # elements. - '&' => '&', - '<' => '<' - ) ) ); + return "<$element" . self::expandAttributes( + self::dropDefaults( $element, $attribs ) ) . '>'; } /** diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 8bd6906cb3..a33efb9676 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1604,6 +1604,7 @@ class OutputPage { global $wgDocType, $wgDTD, $wgContLanguageCode, $wgOutputEncoding, $wgMimeType; global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version; global $wgContLang, $wgUseTrackbacks, $wgStyleVersion, $wgHtml5, $wgWellFormedXml; + global $wgUser, $wgRequest, $wgLang; $this->addMeta( "http:Content-Type", "$wgMimeType; charset={$wgOutputEncoding}" ); if ( $sk->commonPrintStylesheet() ) { @@ -1665,6 +1666,38 @@ class OutputPage { $ret .= $this->getTitle()->trackbackRDF(); $ret .= "\n"; + + $bodyAttrs = array(); + + # Crazy edit-on-double-click stuff + $action = $wgRequest->getVal( 'action', 'view' ); + + if ( $this->mTitle->getNamespace() != NS_SPECIAL + && !in_array( $action, array( 'edit', 'submit' ) ) + && $wgUser->getOption( 'editondblclick' ) ) { + $bodyAttrs['ondblclick'] = "document.location = '" . Xml::escapeJsString( $this->mTitle->getEditURL() ) . "'"; + } + + # Class bloat + $bodyAttrs['class'] = "mediawiki $dir"; + + if ( $wgLang->capitalizeAllNouns() ) { + # A class is probably not the best way to do this . . . + $bodyAttrs['class'] .= ' capitalize-all-nouns'; + } + $bodyAttrs['class'] .= ' ns-' . $this->mTitle->getNamespace(); + if ( $this->mTitle->getNamespace() == NS_SPECIAL ) { + $bodyAttrs['class'] .= ' ns-special'; + } elseif ( $this->mTitle->isTalkPage() ) { + $bodyAttrs['class'] .= ' ns-talk'; + } else { + $bodyAttrs['class'] .= ' ns-subject'; + } + $bodyAttrs['class'] .= ' ' . Sanitizer::escapeClass( 'page-' . $this->mTitle->getPrefixedText() ); + $bodyAttrs['class'] .= ' skin-' . Sanitizer::escapeClass( $wgUser->getSkin()->getSkinName() ); + + $ret .= Html::openElement( 'body', $bodyAttrs ) . "\n"; + return $ret; } diff --git a/includes/Skin.php b/includes/Skin.php index 9cc94f487d..93f92e9449 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -303,12 +303,6 @@ class Skin extends Linker { $out->out( $out->headElement( $this ) ); - $out->out( "\ngetBodyOptions(); - foreach ( $ops as $name => $val ) { - $out->out( " $name='$val'" ); - } - $out->out( ">\n" ); if ( $wgDebugComments ) { $out->out( "\n" ); @@ -657,29 +651,6 @@ CSS; $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' ); } - function getBodyOptions() { - global $wgUser, $wgOut, $wgRequest, $wgContLang; - - extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) ); - - if ( 0 != $this->mTitle->getNamespace() ) { - $a = array( 'bgcolor' => '#ffffec' ); - } - else $a = array( 'bgcolor' => '#FFFFFF' ); - if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) && - $this->mTitle->quickUserCan( 'edit' ) ) { - $s = $this->mTitle->getFullURL( $this->editUrlOptions() ); - $s = 'document.location = "' .Xml::escapeJsString( $s ) .'";'; - $a += array( 'ondblclick' => $s ); - } - $a['class'] = - 'mediawiki' . - ' '.( $wgContLang->getDir() ). - ' '.$this->getPageClasses( $this->mTitle ) . - ' skin-'. Sanitizer::escapeClass( $this->getSkinName() ); - return $a; - } - function getPageClasses( $title ) { $numeric = 'ns-'.$title->getNamespace(); if( $title->getNamespace() == NS_SPECIAL ) { diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 42a5be4c7e..d2a5781ec1 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -485,13 +485,6 @@ class SkinTemplate extends Skin { $content_actions = $this->buildContentActionUrls(); $tpl->setRef( 'content_actions', $content_actions ); - // XXX: attach this from javascript, same with section editing - if( $this->iseditable && $wgUser->getOption( 'editondblclick' ) ){ - $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) ); - $tpl->set( 'body_ondblclick', 'document.location = "' . $encEditUrl . '";' ); - } else { - $tpl->set( 'body_ondblclick', false ); - } $tpl->set( 'sidebar', $this->buildSidebar() ); $tpl->set( 'nav_urls', $this->buildNavUrls() ); diff --git a/skins/Modern.php b/skins/Modern.php index 0100d1aec8..14742b2d92 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -62,8 +62,7 @@ class ModernTemplate extends QuickTemplate { wfSuppressWarnings(); $this->html( 'headelement' ); -?>data['body_ondblclick']) { ?> ondblclick="text('body_ondblclick') ?>" - class="mediawiki text('dir') ?> text('pageclass') ?> text('skinnameclass') ?>"> +?>

html('title') ?>

diff --git a/skins/MonoBook.php b/skins/MonoBook.php index da5517d45c..6f156216ca 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -69,9 +69,7 @@ class MonoBookTemplate extends QuickTemplate { wfSuppressWarnings(); $this->html( 'headelement' ); -?>data['body_ondblclick']) { ?> ondblclick="text('body_ondblclick') ?>" - class="mediawiki text('dir'); $this->text('capitalizeallnouns') ?> text('pageclass') ?> text('skinnameclass') ?>"> -
+?>
html("specialpageattributes") ?>> diff --git a/skins/Standard.php b/skins/Standard.php index 2a17b0ea82..fb8beda084 100644 --- a/skins/Standard.php +++ b/skins/Standard.php @@ -59,23 +59,6 @@ class SkinStandard extends Skin { return $s; } - /** - * - */ - function getBodyOptions() { - $a = parent::getBodyOptions(); - - if ( 3 == $this->qbSetting() ) { # Floating left - $qb = "setup(\"quickbar\")"; - if( $a['onload'] ) { - $a['onload'] .= ";$qb"; - } else { - $a['onload'] = $qb; - } - } - return $a; - } - function doAfterContent() { global $wgContLang, $wgLang; wfProfileIn( __METHOD__ ); diff --git a/skins/Vector.php b/skins/Vector.php index f86cc0630c..5ad6c354a9 100644 --- a/skins/Vector.php +++ b/skins/Vector.php @@ -448,7 +448,6 @@ class VectorTemplate extends QuickTemplate { // Output HTML Page $this->html( 'headelement' ); ?> - data['body_ondblclick'] ): ?> ondblclick="text( 'body_ondblclick' ) ?>" class="mediawiki text( 'dir' ) ?> text( 'pageclass' ) ?> text( 'skinnameclass' ) ?>" dir="text( 'dir' ) ?>">
diff --git a/skins/common/oldshared.css b/skins/common/oldshared.css index b585eb7105..1bd1544e6f 100644 --- a/skins/common/oldshared.css +++ b/skins/common/oldshared.css @@ -374,3 +374,10 @@ table.multipageimage td { form#specialpages { display: inline; } + +body { + background-color: #ffffec; +} +body.ns-0 { + background-color: white; +} diff --git a/skins/common/sticky.js b/skins/common/sticky.js index a4904c03ff..d77a4b668e 100644 --- a/skins/common/sticky.js +++ b/skins/common/sticky.js @@ -31,6 +31,8 @@ lastY=10;YOffset=0;staticYOffset=10;refreshMS=25; //mySticky.css.visibility="visible"; } +hookEvent( 'load', function() { setup( 'quickbar' ); } ); + // ------------------------- // emulate css 'position: fixed' in IE5+ Win -- 2.20.1