Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.js |
— | — | @@ -273,6 +273,36 @@ |
274 | 274 | '$content' : null, |
275 | 275 | |
276 | 276 | /** |
| 277 | + * Checks wether the current page is the wiki's main page. |
| 278 | + * |
| 279 | + * @param alsoRelated Boolean value, if true this function also returns true if the current page is |
| 280 | + * in a different namespace page of the main page rather than the main page itself (eg. talk page) |
| 281 | + * @return Boolean |
| 282 | + */ |
| 283 | + 'isMainPage' : function( alsoRelated ) { |
| 284 | + var isRelatedToMainpage = false; |
| 285 | + |
| 286 | + // Don't insert colon between namespace and title if the namespace is empty (eg. main namespace) |
| 287 | + var namespace = mw.config.get( 'wgFormattedNamespaces' )[mw.config.get( 'wgNamespaceNumber' )]; |
| 288 | + namespace = namespace ? namespace + ':' : ''; |
| 289 | + |
| 290 | + // We can't use (wgMainPageTitle == wgPageName) since the latter is escaped (underscores) and has other |
| 291 | + // slight variations that make comparison harder. |
| 292 | + var isTheMainPage = mw.config.get( 'wgMainPageTitle' ) === ( namespace + mw.config.get( 'wgTitle' ) ); |
| 293 | + |
| 294 | + // Also check for the title in related namespaces ? |
| 295 | + if ( typeof alsoRelated !== 'undefined' && alsoRelated === true ) { |
| 296 | + var contentTabLink = wgServer + $( '#ca-talk' ).prev( 'li' ).find( 'a:first' ).attr( 'href' ); |
| 297 | + isRelatedToMainpage = contentTabLink === mw.util.wikiGetlink( mw.config.get( 'wgMainPageTitle' ) ); |
| 298 | + |
| 299 | + return isRelatedToMainpage || isTheMainPage; |
| 300 | + } |
| 301 | + |
| 302 | + return isTheMainPage; |
| 303 | + }, |
| 304 | + |
| 305 | + |
| 306 | + /** |
277 | 307 | * Add a link to a portlet menu on the page, such as: |
278 | 308 | * |
279 | 309 | * p-cactions (Content actions), p-personal (Personal tools), |