From: Daniel Friesen Date: Sun, 12 Aug 2012 09:23:50 +0000 (-0700) Subject: Fix up the preferred way to specify mw.util.$content X-Git-Tag: 1.31.0-rc.0~22518 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=70051c7fad1830edc774c74cb362b39105f0fb76;p=lhc%2Fweb%2Fwiklou.git Fix up the preferred way to specify mw.util.$content - 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 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index a6b49495cb..adc6a58fc3 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/resources/mediawiki/mediawiki.util.js b/resources/mediawiki/mediawiki.util.js index c697692fb4..e7e35beea5 100644 --- a/resources/mediawiki/mediawiki.util.js +++ b/resources/mediawiki/mediawiki.util.js @@ -69,25 +69,49 @@ } /* 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 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' ); @@ -297,7 +321,7 @@ /* * @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, diff --git a/skins/Modern.php b/skins/Modern.php index 6e87786738..4211bb844d 100644 --- a/skins/Modern.php +++ b/skins/Modern.php @@ -77,7 +77,7 @@ class ModernTemplate extends MonoBookTemplate { -
+
msg('tagline') ?>
diff --git a/skins/MonoBook.php b/skins/MonoBook.php index 5c7ca14f5f..0bd7134bc3 100644 --- a/skins/MonoBook.php +++ b/skins/MonoBook.php @@ -80,7 +80,7 @@ class MonoBookTemplate extends BaseTemplate { $this->html( 'headelement' ); ?>
-
+
data['sitenotice']) { ?>
html('sitenotice') ?>