jenkins-bot has submitted this change and it was merged.

Change subject: Optionally disable Read More using extension data
......................................................................


Optionally disable Read More using extension data

By default, the Read More feature tries to use editor-curated articles
before using the CirrusSearch morelike: feature. Add a configuration
variable that disables the former behaviour but leave the default in
place.

Changes:

* Add the wgReadMoreOnlyUseCirrusSearch configuration variable, which
  defaults to false, and pass it in to
  mw.relatedArticles.RelatedPagesGateway at construction time
* Add the onlyUseCirrusSearch parameter to
  mw.relatedArticles.RelatedPagesGateway, which controls whether to
  ignore the editorCuratedArticles parameter

Bug: T117443
Change-Id: I0dfa67f4a68e8dc17302fef7ebf8d23c0c1d892c
---
M extension.json
M includes/ReadMoreHooks.php
M resources/ext.relatedArticles.readMore.bootstrap/index.js
M resources/ext.relatedArticles.readMore/RelatedPagesGateway.js
M tests/qunit/ext.relatedArticles.readMore/test_RelatedPagesGateway.js
5 files changed, 50 insertions(+), 7 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index f3f0a9d..ebea57c 100644
--- a/extension.json
+++ b/extension.json
@@ -92,6 +92,7 @@
        "config": {
                "RelatedArticlesShowReadMore": false,
                "RelatedArticlesUseCirrusSearch": false,
+               "RelatedArticlesOnlyUseCirrusSearch": false,
                "RelatedArticlesLoggingSamplingRate": 0.01
        },
        "ConfigRegistry": {
diff --git a/includes/ReadMoreHooks.php b/includes/ReadMoreHooks.php
index ec76bd8..c823342 100644
--- a/includes/ReadMoreHooks.php
+++ b/includes/ReadMoreHooks.php
@@ -48,7 +48,10 @@
                $config = ConfigFactory::getDefaultInstance()->makeConfig( 
'RelatedArticles' );
 
                $vars['wgRelatedArticles'] = $out->getProperty( 
'RelatedArticles' );
+
                $vars['wgRelatedArticlesUseCirrusSearch'] = $config->get( 
'RelatedArticlesUseCirrusSearch' );
+               $vars['wgRelatedArticlesOnlyUseCirrusSearch'] =
+                       $config->get( 'RelatedArticlesOnlyUseCirrusSearch' );
 
                return true;
        }
diff --git a/resources/ext.relatedArticles.readMore.bootstrap/index.js 
b/resources/ext.relatedArticles.readMore.bootstrap/index.js
index 8b1d08f..aa4e1bc 100644
--- a/resources/ext.relatedArticles.readMore.bootstrap/index.js
+++ b/resources/ext.relatedArticles.readMore.bootstrap/index.js
@@ -1,10 +1,13 @@
 ( function ( $ ) {
 
        var config = mw.config.get( [ 'skin', 'wgNamespaceNumber', 'wgMFMode', 
'wgIsMainPage' ] ),
-               relatedPages = new mw.relatedArticles.RelatedPagesGateway( new 
mw.Api(),
-                       mw.config.get( 'wgPageName' ), mw.config.get( 
'wgRelatedArticles' ),
-                       mw.config.get( 'wgRelatedArticlesUseCirrusSearch' ) ),
-
+               relatedPages = new mw.relatedArticles.RelatedPagesGateway(
+                       new mw.Api(),
+                       mw.config.get( 'wgPageName' ),
+                       mw.config.get( 'wgRelatedArticles' ),
+                       mw.config.get( 'wgRelatedArticlesUseCirrusSearch' ),
+                       mw.config.get( 'wgRelatedArticlesOnlyUseCirrusSearch' )
+               ),
                LIMIT = 4;
 
        if (
diff --git a/resources/ext.relatedArticles.readMore/RelatedPagesGateway.js 
b/resources/ext.relatedArticles.readMore/RelatedPagesGateway.js
index 53a8cd4..0eb2d9e 100644
--- a/resources/ext.relatedArticles.readMore/RelatedPagesGateway.js
+++ b/resources/ext.relatedArticles.readMore/RelatedPagesGateway.js
@@ -8,13 +8,26 @@
         * @param {mw.Api} api
         * @param {string} currentPage the page that the editorCuratedArticles 
relate to
         * @param {Array} editorCuratedArticles a list of articles curated by 
editors for the current page
-        * @param {boolean} useCirrusSearch whether to hit the API when no 
editor curated articles are available
+        * @param {boolean} useCirrusSearch whether to hit the API when no 
editor-curated articles are available
+        * @param {boolean} [onlyUseCirrusSearch=false] whether to ignore the 
list of editor-curated articles
         */
-       function RelatedPagesGateway( api, currentPage, editorCuratedArticles, 
useCirrusSearch ) {
+       function RelatedPagesGateway(
+               api,
+               currentPage,
+               editorCuratedArticles,
+               useCirrusSearch,
+               onlyUseCirrusSearch
+       ) {
                this.api = api;
                this.currentPage = currentPage;
-               this.editorCuratedArticles = editorCuratedArticles || [];
                this.useCirrusSearch = useCirrusSearch;
+
+               if ( onlyUseCirrusSearch ) {
+                       editorCuratedArticles = [];
+               }
+
+               this.editorCuratedArticles = editorCuratedArticles || [];
+
        }
        OO.initClass( RelatedPagesGateway );
 
diff --git 
a/tests/qunit/ext.relatedArticles.readMore/test_RelatedPagesGateway.js 
b/tests/qunit/ext.relatedArticles.readMore/test_RelatedPagesGateway.js
index cb3641c..ea49d08 100644
--- a/tests/qunit/ext.relatedArticles.readMore/test_RelatedPagesGateway.js
+++ b/tests/qunit/ext.relatedArticles.readMore/test_RelatedPagesGateway.js
@@ -68,4 +68,27 @@
                } );
        } );
 
+       QUnit.test( 'Ignore related pages from editor curated content', 1, 
function ( assert ) {
+               var wgRelatedArticles = [
+                               'Bar',
+                               'Baz',
+                               'Qux'
+                       ],
+                       gateway = new RelatedPagesGateway( this.api, 'Foo', 
wgRelatedArticles, true, true ),
+                       spy;
+
+               spy = this.sandbox.stub( this.api, 'get' )
+                       .returns( $.Deferred().resolve( relatedPages ) );
+
+               gateway.getForCurrentPage( 1 ).then( function () {
+                       var parameters = spy.lastCall.args[ 0 ];
+
+                       assert.strictEqual(
+                               parameters.generator,
+                               'search',
+                               'it should hit the CirrusSearch API even though 
wgRelatedArticles is non-empty'
+                       );
+               } );
+       } );
+
 }( mw.mobileFrontend, jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/252438
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I0dfa67f4a68e8dc17302fef7ebf8d23c0c1d892c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/RelatedArticles
Gerrit-Branch: dev
Gerrit-Owner: Phuedx <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Phuedx <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to