Pmiazga has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/334716 )
Change subject: Use mw.experiment to enable related pages only to subset of users ...................................................................... Use mw.experiment to enable related pages only to subset of users Changes: - introduced new config variable: RelatedArticlesEnabledSamplingRate - do not trigger RelatedArticles clientside scripts if feature is disabled Bug: T156039 Change-Id: I7e9773131c5b9aea9e9fb554d4508842cdedede7 --- M extension.json M includes/FooterHooks.php M resources/ext.relatedArticles.readMore.bootstrap/index.js 3 files changed, 49 insertions(+), 15 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/RelatedArticles refs/changes/16/334716/1 diff --git a/extension.json b/extension.json index 1a7c8bb..6295ab1 100644 --- a/extension.json +++ b/extension.json @@ -78,6 +78,7 @@ "resources/ext.relatedArticles.readMore.bootstrap/index.js" ], "dependencies": [ + "mediawiki.experiments", "mediawiki.api", "mediawiki.Uri", "mediawiki.viewport", @@ -96,6 +97,7 @@ "RelatedArticlesUseCirrusSearch": false, "RelatedArticlesOnlyUseCirrusSearch": false, "RelatedArticlesLoggingSamplingRate": 0.01, + "RelatedArticlesEnabledSamplingRate": 0.9, "@RelatedArticlesFooterBlacklistedSkins": "List of skin names (e.g. 'minerva') where related articles won't be shown in the footer. If absent related articles will show in stable on Minerva or beta on all other skins.", "RelatedArticlesFooterBlacklistedSkins": [] }, diff --git a/includes/FooterHooks.php b/includes/FooterHooks.php index 7872220..ef6d58b 100644 --- a/includes/FooterHooks.php +++ b/includes/FooterHooks.php @@ -19,7 +19,7 @@ * Sets the value of the <code>wgRelatedArticles</code> global variable * to the list of related articles in the cached parser output. * - * @param array $vars + * @param array RelatedArticlesLoggingSamplingRate * @param OutputPage $out * @return boolean Always <code>true</code> */ @@ -27,8 +27,8 @@ $config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' ); $vars['wgRelatedArticles'] = $out->getProperty( 'RelatedArticles' ); - $vars['wgRelatedArticlesUseCirrusSearch'] = $config->get( 'RelatedArticlesUseCirrusSearch' ); + $vars['wgRelatedArticlesOnlyUseCirrusSearch'] = $config->get( 'RelatedArticlesOnlyUseCirrusSearch' ); @@ -168,7 +168,8 @@ $config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' ); $vars['wgRelatedArticlesLoggingSamplingRate'] = $config->get( 'RelatedArticlesLoggingSamplingRate' ); - + $vars['RelatedArticlesEnabledSamplingRate'] + = $config->get( 'RelatedArticlesEnabledSamplingRate' ); return true; } diff --git a/resources/ext.relatedArticles.readMore.bootstrap/index.js b/resources/ext.relatedArticles.readMore.bootstrap/index.js index d7b3a3e..92668bf 100644 --- a/resources/ext.relatedArticles.readMore.bootstrap/index.js +++ b/resources/ext.relatedArticles.readMore.bootstrap/index.js @@ -14,6 +14,35 @@ $window = $( window ); /** + * Return the RelatedArticles visibility for current user + * + * User's session ID is used to determine the eligibility for RelatedArticles functionality, + * thus the function will result the same outcome as long as the browser + * hasn't been restarted or the cookie hasn't been cleared. + * + * @return {number} + */ + function isVisibleForCurrentUser() { + var bucket, + samplingRate = mw.config.get( 'RelatedArticlesEnabledSamplingRate', 0 ); + + if ( !$.isFunction( navigator.sendBeacon ) ) { + return 0; + } + + bucket = mw.experiments.getBucket( { + name: 'ext.relatedArticles.visibility', + enabled: true, + buckets: { + control: 1 - samplingRate, + A: samplingRate + } + }, mw.user.sessionId() ); + console.log('RelatedArticles visiblity : ', bucket === 'A' ? 1 : 0); + return bucket === 'A' ? 1 : 0; + } + + /** * Load related articles when the user scrolls past half of the window height. * * @ignore @@ -41,18 +70,20 @@ } } - // Add container to DOM for checking distance on scroll - // If a skin has marked up a footer content area prepend it there - if ( $( '.footer-content' ).length ) { - $( '<div class="read-more-container" />' ).prependTo( '.footer-content' ); - } else { - $( '<div class="read-more-container post-content" />' ) - .insertAfter( '#content' ); - } + if (isVisibleForCurrentUser()) { + // Add container to DOM for checking distance on scroll + // If a skin has marked up a footer content area prepend it there + if ($('.footer-content').length) { + $('<div class="read-more-container" />').prependTo('.footer-content'); + } else { + $('<div class="read-more-container post-content" />') + .insertAfter('#content'); + } - // try related articles load on scroll - $window.on( 'scroll', debouncedLoad ); - // try an initial load, in case of no scroll - loadRelatedArticles(); + // try related articles load on scroll + $window.on('scroll', debouncedLoad); + // try an initial load, in case of no scroll + loadRelatedArticles(); + } }( jQuery, mediaWiki ) ); -- To view, visit https://gerrit.wikimedia.org/r/334716 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7e9773131c5b9aea9e9fb554d4508842cdedede7 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/RelatedArticles Gerrit-Branch: master Gerrit-Owner: Pmiazga <pmia...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits