From d2599c5211aa4f592fdcbbcd7a4a8ac502062668 Mon Sep 17 00:00:00 2001 From: Baha Date: Tue, 29 Dec 2015 07:55:43 +0500 Subject: [PATCH] Do not load related articles on diff comparision pages Bug: T122076 Change-Id: I1dc00b3bd76053d353dc31137c4c15a10286184e --- extension.json | 1 + .../index.js | 28 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/extension.json b/extension.json index 9917e582..852d3566 100644 --- a/extension.json +++ b/extension.json @@ -88,6 +88,7 @@ ], "dependencies": [ "mediawiki.api", + "mediawiki.Uri", "ext.relatedArticles.readMore.gateway", "jquery.throttle-debounce" ], diff --git a/resources/ext.relatedArticles.readMore.bootstrap/index.js b/resources/ext.relatedArticles.readMore.bootstrap/index.js index 208bb76d..5ef471b8 100644 --- a/resources/ext.relatedArticles.readMore.bootstrap/index.js +++ b/resources/ext.relatedArticles.readMore.bootstrap/index.js @@ -1,6 +1,7 @@ ( function ( $, mw ) { - var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode', 'wgIsMainPage' ] ), + var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode', + 'wgIsMainPage', 'wgAction' ] ), relatedPages = new mw.relatedPages.RelatedPagesGateway( new mw.Api(), mw.config.get( 'wgPageName' ), @@ -14,6 +15,11 @@ } ), $window = $( window ); + /** + * Load related articles when the user scrolls past half of the window height. + * + * @ignore + */ function loadRelatedArticles() { /** * Threshold value to load related articles - after about half scroll @@ -36,11 +42,29 @@ $window.off( 'scroll', debouncedLoad ); } } + + /** + * Is the current page a diff page? + * + * @ignore + * @return {boolean} + */ + function isDiffPage() { + var queryParams = new mw.Uri( window.location.href ).query; + + return !!( + queryParams.type === 'revision' || + queryParams.hasOwnProperty( 'diff' ) || + queryParams.hasOwnProperty( 'oldid' ) + ); + } + if ( config.wgNamespaceNumber === 0 && !config.wgIsMainPage && // T120735 - mw.config.get( 'wgAction' ) === 'view' && + config.wgAction === 'view' && + !isDiffPage() && // any skin except minerva stable ( config.skin !== 'minerva' || config.wgMFMode === 'beta' ) ) {