Fix up the preferred way to specify mw.util.$content
authorDaniel Friesen <pub-github@nadir-seen-fire.com>
Sun, 12 Aug 2012 09:23:50 +0000 (02:23 -0700)
committerDaniel Friesen <pub-github@nadir-seen-fire.com>
Thu, 30 Aug 2012 21:43:18 +0000 (14:43 -0700)
- Setting a .mw-body class is the preferred way for $content to be defined
- You can set an extra .mw-body-primary if you use multiple .mw-body classes or for some legacy reasons .mw-body is at a different depth than the content area
- No extensions appear to be using util.$content in a way that would imply they want the body text rather than the overall content area
- Anyone that actually needs the body text can use #mw-content-text.

Change-Id: Ic7b756f139047e4100fcab8f63a968d45ca2b2fe

RELEASE-NOTES-1.20
resources/mediawiki/mediawiki.util.js
skins/Modern.php
skins/MonoBook.php

index a6b4949..adc6a58 100644 (file)
@@ -136,6 +136,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * Added ResourceLoader module "jquery.jStorage".
 * (bug 39273) Added AJAX support for "Show changes" (diff) in LivePreview.
 * Added ResourceLoader module "jquery.badge".
+* mw.util.$content now points to the overall content area in the skin rather than just
+  page text content area. If you need the old behaviour please use $( '#mw-content-text').
 
 === Bug fixes in 1.20 ===
 * (bug 30245) Use the correct way to construct a log page title.
index c697692..e7e35be 100644 (file)
                        }
 
                        /* Fill $content var */
-                       if ( $( '#bodyContent' ).length ) {
-                               // Vector, Monobook, Chick etc.
-                               util.$content = $( '#bodyContent' );
-
-                       } else if ( $( '#mw_contentholder' ).length ) {
-                               // Modern
-                               util.$content = $( '#mw_contentholder' );
-
-                       } else if ( $( '#article' ).length ) {
-                               // Standard, CologneBlue
-                               util.$content = $( '#article' );
+                       util.$content = ( function () {
+                               var $content, selectors = [
+                                       // The preferred standard for setting $content (class="mw-body")
+                                       // You may also use (class="mw-body mw-body-primary") if you use
+                                       // mw-body in multiple locations.
+                                       // Or class="mw-body-primary" if you want $content to be deeper
+                                       // in the dom than mw-body
+                                       '.mw-body-primary',
+                                       '.mw-body',
+
+                                       /* Legacy fallbacks for setting the content */
+                                       // Vector, Monobook, Chick, etc... based skins
+                                       '#bodyContent',
+
+                                       // Modern based skins
+                                       '#mw_contentholder',
+
+                                       // Standard, CologneBlue
+                                       '#article',
+
+                                       // #content is present on almost all if not all skins. Most skins (the above cases)
+                                       // have #content too, but as an outer wrapper instead of the article text container.
+                                       // The skins that don't have an outer wrapper do have #content for everything
+                                       // so it's a good fallback
+                                       '#content',
+
+                                       // If nothing better is found fall back to our bodytext div that is guaranteed to be here
+                                       '#mw-content-text',
+
+                                       // Should never happen... well, it could if someone is not finished writing a skin and has
+                                       // not inserted bodytext yet. But in any case <body> should always exist
+                                       'body'
+                               ];
+                               for ( var i = 0, l = selectors.length; i < l; i++ ) {
+                                       $content = $( selectors[i] ).first();
+                                       if ( $content.length ) {
+                                               return $content;
+                                       }
+                               }
 
-                       } else {
-                               // #content is present on almost all if not all skins. Most skins (the above cases)
-                               // have #content too, but as an outer wrapper instead of the article text container.
-                               // The skins that don't have an outer wrapper do have #content for everything
-                               // so it's a good fallback
-                               util.$content = $( '#content' );
-                       }
+                               // Make sure we don't unset util.$content if it was preset and we don't find anything
+                               return util.$content;
+                       } )();
 
                        // Table of contents toggle
                        $tocTitle = $( '#toctitle' );
 
                /*
                 * @var jQuery
-                * A jQuery object that refers to the page-content element
+                * A jQuery object that refers to the content area element
                 * Populated by init().
                 */
                $content: null,
index 6e87786..4211bb8 100644 (file)
@@ -77,7 +77,7 @@ class ModernTemplate extends MonoBookTemplate {
        <!-- contentholder does nothing by default, but it allows users to style the text inside
             the content area without affecting the meaning of 'em' in #mw_content, which is used
             for the margins -->
-       <div id="mw_contentholder">
+       <div id="mw_contentholder" class="mw-body">
                <div class='mw-topboxes'>
                        <div id="mw-js-message" style="display:none;"<?php $this->html('userlangattributes')?>></div>
                        <div class="mw-topbox" id="siteSub"><?php $this->msg('tagline') ?></div>
index 5c7ca14..0bd7134 100644 (file)
@@ -80,7 +80,7 @@ class MonoBookTemplate extends BaseTemplate {
 
                $this->html( 'headelement' );
 ?><div id="globalWrapper">
-<div id="column-content"><div id="content">
+<div id="column-content"><div id="content" class="mw-body-primary">
        <a id="top"></a>
        <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>