Merge all skins' output of opening <body> tag
authorAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 15 Jan 2010 01:16:52 +0000 (01:16 +0000)
committerAryeh Gregor <simetrical@users.mediawiki.org>
Fri, 15 Jan 2010 01:16:52 +0000 (01:16 +0000)
This fixes a few minor discrepancies, like Vector outputting dir=""
(redundant to the one on <html>), 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
includes/OutputPage.php
includes/Skin.php
includes/SkinTemplate.php
skins/Modern.php
skins/MonoBook.php
skins/Standard.php
skins/Vector.php
skins/common/oldshared.css
skins/common/sticky.js

index 667e58b..a17e033 100644 (file)
@@ -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</$element>";
+               }
+       }
+
+       /**
+        * 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.
+                       '&' => '&amp;',
+                       '<' => '&lt;'
+               ) ) );
+       }
+
+       /**
+        * 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</$element>";
-               }
-       }
-
-       /**
-        * 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.
-                       '&' => '&amp;',
-                       '<' => '&lt;'
-               ) ) );
+               return "<$element" . self::expandAttributes(
+                       self::dropDefaults( $element, $attribs ) ) . '>';
        }
 
        /**
index 8bd6906..a33efb9 100644 (file)
@@ -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 .= "</head>\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 <body> 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;
        }
 
index 9cc94f4..93f92e9 100644 (file)
@@ -303,12 +303,6 @@ class Skin extends Linker {
 
                $out->out( $out->headElement( $this ) );
 
-               $out->out( "\n<body" );
-               $ops = $this->getBodyOptions();
-               foreach ( $ops as $name => $val ) {
-                       $out->out( " $name='$val'" );
-               }
-               $out->out( ">\n" );
                if ( $wgDebugComments ) {
                        $out->out( "<!-- Wiki debugging output:\n" .
                          $out->mDebugtext . "-->\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 ) {
index 42a5be4..d2a5781 100644 (file)
@@ -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() );
 
index 0100d1a..14742b2 100644 (file)
@@ -62,8 +62,7 @@ class ModernTemplate extends QuickTemplate {
                wfSuppressWarnings();
 
                $this->html( 'headelement' );
-?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
- class="mediawiki <?php $this->text('dir') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
+?>
 
        <!-- heading -->
        <div id="mw_header"><h1 id="firstHeading"><?php $this->html('title') ?></h1></div>
index da5517d..6f15621 100644 (file)
@@ -69,9 +69,7 @@ class MonoBookTemplate extends QuickTemplate {
                wfSuppressWarnings();
 
                $this->html( 'headelement' );
-?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
- class="mediawiki <?php $this->text('dir'); $this->text('capitalizeallnouns') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
-       <div id="globalWrapper">
+?>     <div id="globalWrapper">
                <div id="column-content">
        <div id="content" <?php $this->html("specialpageattributes") ?>>
                <a id="top"></a>
index 2a17b0e..fb8beda 100644 (file)
@@ -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__ );
index f86cc06..5ad6c35 100644 (file)
@@ -448,7 +448,6 @@ class VectorTemplate extends QuickTemplate {
                // Output HTML Page
                $this->html( 'headelement' );
 ?>
-       <body<?php if ( $this->data['body_ondblclick'] ): ?> ondblclick="<?php $this->text( 'body_ondblclick' ) ?>"<?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>
                <div id="head-base" class="noprint"></div>
                <!-- content -->
index b585eb7..1bd1544 100644 (file)
@@ -374,3 +374,10 @@ table.multipageimage td {
 form#specialpages {
        display: inline;
 }
+
+body {
+       background-color: #ffffec;
+}
+body.ns-0 {
+       background-color: white;
+}
index a4904c0..d77a4b6 100644 (file)
@@ -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