From 351ad488fd5c18dff932f6334a5155ca2004aa6c Mon Sep 17 00:00:00 2001 From: Krinkle Date: Sun, 1 May 2011 19:46:09 +0000 Subject: [PATCH] Added wgIsMainPage (Title->isMainPage) to mw.config * Instead of ugly javascript construction to compare href-attributes or re-constructing proper pagenames, let's use Title->isMainPage which does this much better * Kept function for compatibility. mw.util.isMainPage() was never released, should probably be removed before 1.18 branch point. --- includes/OutputPage.php | 1 + resources/mediawiki.util/mediawiki.util.js | 26 +++------------------- 2 files changed, 4 insertions(+), 23 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index eeaca5cf5b..9385c1f505 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -2662,6 +2662,7 @@ class OutputPage { 'wgUserGroups' => $this->getUser()->getEffectiveGroups(), 'wgCategories' => $this->getCategories(), 'wgBreakFrames' => $this->getFrameOptions() == 'DENY', + 'wgIsMainPage' => $title->isMainPage(), ); if ( $wgContLang->hasVariants() ) { $vars['wgUserVariant'] = $wgContLang->getPreferredVariant(); diff --git a/resources/mediawiki.util/mediawiki.util.js b/resources/mediawiki.util/mediawiki.util.js index 8da7de50f1..b0f1645cfe 100644 --- a/resources/mediawiki.util/mediawiki.util.js +++ b/resources/mediawiki.util/mediawiki.util.js @@ -272,32 +272,12 @@ /** * Checks wether the current page is the wiki's main page. - * This function requires the document to be ready! * - * @param alsoRelated Boolean value, if true this function also returns true if the current page is - * in an associated namespace page of the main page rather than the main page itself (eg. talk page) * @return Boolean + * @deprecated to be removed in 1.18: Use wgIsMainPage in mw.config instead. */ - 'isMainPage' : function( alsoRelated ) { - var isRelatedToMainpage = false; - - // Don't insert colon between namespace and title if the namespace is empty (eg. main namespace) - var namespace = mw.config.get( 'wgFormattedNamespaces' )[mw.config.get( 'wgNamespaceNumber' )]; - namespace = namespace ? namespace + ':' : ''; - - // We can't use (wgMainPageTitle == wgPageName) since the latter is escaped (underscores) and has other - // slight variations that make comparison harder. - var isTheMainPage = mw.config.get( 'wgMainPageTitle' ) === ( namespace + mw.config.get( 'wgTitle' ) ); - - // Also check for the title in related namespaces ? - if ( typeof alsoRelated !== 'undefined' && alsoRelated === true ) { - var tabLink = $( '#ca-talk' ).prev().find( 'a:first' ).attr( 'href' ); - isRelatedToMainpage = tabLink === mw.util.wikiGetlink( mw.config.get( 'wgMainPageTitle' ) ); - - return isRelatedToMainpage || isTheMainPage; - } - - return isTheMainPage; + 'isMainPage' : function() { + return mw.config.get( 'wgIsMainPage' ); }, -- 2.20.1