mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/RelatedArticles
synced 2024-11-24 08:14:21 +00:00
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
This commit is contained in:
parent
371998e22e
commit
0fed50e266
|
@ -92,6 +92,7 @@
|
|||
"config": {
|
||||
"RelatedArticlesShowReadMore": false,
|
||||
"RelatedArticlesUseCirrusSearch": false,
|
||||
"RelatedArticlesOnlyUseCirrusSearch": false,
|
||||
"RelatedArticlesLoggingSamplingRate": 0.01
|
||||
},
|
||||
"ConfigRegistry": {
|
||||
|
|
|
@ -48,7 +48,10 @@ class ReadMoreHooks {
|
|||
$config = ConfigFactory::getDefaultInstance()->makeConfig( 'RelatedArticles' );
|
||||
|
||||
$vars['wgRelatedArticles'] = $out->getProperty( 'RelatedArticles' );
|
||||
|
||||
$vars['wgRelatedArticlesUseCirrusSearch'] = $config->get( 'RelatedArticlesUseCirrusSearch' );
|
||||
$vars['wgRelatedArticlesOnlyUseCirrusSearch'] =
|
||||
$config->get( 'RelatedArticlesOnlyUseCirrusSearch' );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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 (
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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 ) );
|
||||
|
|
Loading…
Reference in a new issue