From f2fbef6ec763a37952eb7cf0b2ad22ae07f37522 Mon Sep 17 00:00:00 2001 From: Piotr Miazga Date: Thu, 8 Jun 2017 15:29:57 +0200 Subject: [PATCH] Implement html/rest.js gateway which handles HTML Restbase responses Refactor existing Restbase gateway and extract shared logic into shared Restbase provider. Also introduced new createNullModel() which defines an empty preview model. Additionally improve naming in new gateways/formatter so function names are more explicity. * Htmlize() became formatPlainTextExtract() as it should be used only with plain text extracts * removeEllipsis() became removeTrailingEllipsis() as it removes only trailing ellipsis. * src/gateway/index.js defines gateways by configuration name stored in extension.json Bug: T165018 Change-Id: Ibe54dddfc1080e94814d1562d41e85cb6b43bfc1 Depends-On: I4f42c61b155a37c5dd42bc40034583865abd5d7a --- extension.json | 4 +- includes/PopupsHooks.php | 2 +- resources/dist/index.js | Bin 34289 -> 35250 bytes resources/dist/index.js.map | Bin 270521 -> 280105 bytes src/formatter.js | 10 ++-- src/gateway/html/rest.js | 35 ++++++++++++++ src/gateway/index.js | 5 +- src/gateway/{ => plain}/mediawiki.js | 18 +++---- src/gateway/plain/rest.js | 30 ++++++++++++ src/gateway/{rest.js => restProvider.js} | 26 +++++----- src/index.js | 15 ++++-- src/preview/model.js | 44 ++++++++++------- tests/node-qunit/formatter.test.js | 4 +- .../gateway/{ => plain}/mediawiki.test.js | 4 +- .../{rest.test.js => restProvider.test.js} | 45 ++++++++++-------- tests/phpunit/PopupsHooksTest.php | 2 +- 16 files changed, 165 insertions(+), 79 deletions(-) create mode 100644 src/gateway/html/rest.js rename src/gateway/{ => plain}/mediawiki.js (86%) create mode 100644 src/gateway/plain/rest.js rename src/gateway/{rest.js => restProvider.js} (88%) rename tests/node-qunit/gateway/{ => plain}/mediawiki.test.js (97%) rename tests/node-qunit/gateway/{rest.test.js => restProvider.test.js} (87%) diff --git a/extension.json b/extension.json index 1e8ac646d..d1cbca13e 100644 --- a/extension.json +++ b/extension.json @@ -55,8 +55,8 @@ "PopupsOptInDefaultState": "0", "@PopupsConflictingNavPopupsGadgetName": "@var string: Navigation popups gadget name", "PopupsConflictingNavPopupsGadgetName": "Navigation_popups", - "@PopupsAPIUseRESTBase": "Whether to use RESTBase rather than the MediaWiki API for fetching Popups data.", - "PopupsAPIUseRESTBase": false, + "@PopupsGateway": "Which gateway to use for fetching Popups data. Available options: [mwApiPlain|restbasePlain|restbaseHTML]. Full and always up to date list is available in src/gateway/index.js", + "PopupsGateway": "mwApiPlain", "@PopupsAnonsEnabledSamplingRate": "Sampling rate for showing popups to anonymous users.", "PopupsAnonsEnabledSamplingRate": 0.9, "@PopupsStatsvSamplingRate": "Sampling rate for logging performance data to statsv.", diff --git a/includes/PopupsHooks.php b/includes/PopupsHooks.php index f7b7d001c..d53e0ef18 100644 --- a/includes/PopupsHooks.php +++ b/includes/PopupsHooks.php @@ -120,7 +120,7 @@ class PopupsHooks { $conf = PopupsContext::getInstance()->getConfig(); $vars['wgPopupsSchemaSamplingRate'] = $conf->get( 'PopupsSchemaSamplingRate' ); $vars['wgPopupsBetaFeature'] = $conf->get( 'PopupsBetaFeature' ); - $vars['wgPopupsAPIUseRESTBase'] = $conf->get( 'PopupsAPIUseRESTBase' ); + $vars['wgPopupsGateway'] = $conf->get( 'PopupsGateway' ); $vars['wgPopupsAnonsEnabledSamplingRate'] = $conf->get( 'PopupsAnonsEnabledSamplingRate' ); $vars['wgPopupsStatsvSamplingRate'] = $conf->get( 'PopupsStatsvSamplingRate' ); } diff --git a/resources/dist/index.js b/resources/dist/index.js index e69f7f22f5dfe237b6998d188d12b369e0d8af01..53007caa96b50519c73c5d46c842c153d975a9b1 100644 GIT binary patch delta 5972 zcmc&&eQX@Zb;psCMcJ~b4^lEo(L5f>^R8~Wykl&A+-b@3<3!S;NLoDVi>B%2-5hVk zz1{Qd9*+`zrY*N>n>eZMNov$p?bI!`#lyn|W{Ey!U(W&HJCJdyUsU+odvjon|F-o-N3XI7Ma# z#kWe<3Knzh#H!AMR1-tmI*qgE9%_>@o7N3OqCSyAmFl-6qhn~DQH4JDg^2)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zAS!MKAI)JR&9rgyZ#0z>!T93_cFMdpflG}e1pC9Rin`FSm4+b-o26cvq02J(vp%p6yCHYJRi;(zLiB)*QdPL~NEnnz@4_s}*L8wW( z^u}!J_I$n!pO;r;#P-pHby=(vpP6cIR!MGSi<8RHyis1aB+iZ=s#})p29>6(RFapU zSH>HfR1(|R;zetDM?!pe^nh+sEp_}C%eqR5Rsv^z~!$Q;5e zW#e<-cz)}$}udxjeG-O+#(s%(w%;K0khG3nPPw=93fZwX#A~BCnl^2PPs| z(LCKEUYt;`mUBoMv2!xH!+Rc;E4t{OI(Qp0^0w*N+-Phvb}~M!2eQmvV)fFGXQ2LZo3*9xs}i6w@| z=4KLuCpQ$9+eP7A!?ukxqed^bSjL@izB50t>25P)Q)kxI5Nq?Dn4dnG7)*@#9(6P^xXK= z=;&s#i?%B+3HCwoX>=f6r+uJ}OD>@YcM3m%Z**7@q7#=HlG(N#%ElfA%Xf;7p z@G`4tnvz04xF9|Az@jSNwjkZ=EJ(ie*uroVC+i#VHw1GM_~#=6GS1dsTe#XMp8{(& z=4szyCIQN$N9$=WYx$-$Qux}%{9nB-V#z)U`On%a+E?vGoH$n)*~j`5n*7&=8_bR8 zfdN`>0IdBhh2d6ENcqyo0^md1Nf`yYX+_g{nMM=muR~irf9h%wWAD~KI`2QkN`NwX z&yB*HMr`5*@6p(L{w47F3ZD|+=l6TBo3}cLA*$rGc7l+nxNVvVyAa|LOS3Z>R7=f8 z7yRC%Um-4@c80LN#%qLSV+A{&<+ec`vNUvRrrJ#|@m60d*P=l9dU=S#*HXFJJhBL^+Vvt=Rjw zRS7spFG@MdiyaXD_KQjR?tSSl!+VmC-~GG)*&=nOM7gZV##&C|k^=d2EkxP<(Oi=zekM Q4fUcg*|0Wu|4hxl06d4uh5!Hn diff --git a/resources/dist/index.js.map b/resources/dist/index.js.map index 06b9f6a362c0102182ba938a4c07256c3baf7625..39a0fdfc616b862e79143398ddc3c65cd78d0464 100644 GIT binary patch delta 19407 zcmeHvd2C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zxBukKl(J_)QYP1WXPW`&TzJ|#=Bzh2T;mKyapIHDTGwjlwH;3IDQm#F{26O~cdVSv zbvtf|EGw&K&|HtR8t{-jp zH$%=t_cwfF{qH{5aNYeiqk6mU3@?a`FWjd-TAAAYp;sSUqy9pdR&j?VrTo= zdN1?GdmfAeP!3BoxUa9!?vp#>&C`HE|Y^H{+3rR}|s6CQCjUrwF}y0__d zcz9E~>&qjqLznzdJkD$T|IfJ@2W}?loa%OYoz8n*oHJbJ>? thumbnail.height ) { width = thumbSize; height = Math.floor( ( thumbSize / thumbnail.width ) * thumbnail.height ); @@ -148,15 +143,16 @@ function generateThumbnailData( thumbnail, original, thumbSize ) { * @name RESTBaseGateway#convertPageToModel * @param {Object} page * @param {Number} thumbSize + * @param {Function} extractParser * @returns {PreviewModel} */ -function convertPageToModel( page, thumbSize ) { - return createModel( +function convertPageToModel( page, thumbSize, extractParser ) { + return modelBuilder.createModel( page.title, new mw.Title( page.title ).getUrl(), page.lang, page.dir, - plainTextHTMLizer( page.extract, page.title ), + extractParser( page ), page.thumbnail ? generateThumbnailData( page.thumbnail, page.originalimage, thumbSize ) : undefined ); } diff --git a/src/index.js b/src/index.js index 25f1fb8c3..b011658a9 100644 --- a/src/index.js +++ b/src/index.js @@ -8,8 +8,7 @@ var mw = mediaWiki, ReduxThunk = require( 'redux-thunk' ), constants = require( './constants' ), - createRESTBaseGateway = require( './gateway/rest' ), - createMediaWikiApiGateway = require( './gateway/mediawiki' ), + gatewayBuilder = require( './gateway/index' ), createUserSettings = require( './userSettings' ), createPreviewBehavior = require( './previewBehavior' ), createSchema = require( './schema' ), @@ -47,10 +46,16 @@ var mw = mediaWiki, * @return {ext.popups.Gateway} */ function createGateway( config ) { - if ( config.get( 'wgPopupsAPIUseRESTBase' ) ) { - return createRESTBaseGateway( $.ajax, constants ); + switch ( config.get( 'wgPopupsGateway' ) ) { + case 'mwApiPlain': + return gatewayBuilder.mwApiPlain( new mw.Api(), constants ); + case 'restbasePlain': + return gatewayBuilder.restbasePlain( $.ajax, constants ); + case 'restbaseHTML': + return gatewayBuilder.restbaseHTML( $.ajax, constants ); + default: + throw new Error( 'Unknown gateway' ); } - return createMediaWikiApiGateway( new mw.Api(), constants ); } /** diff --git a/src/preview/model.js b/src/preview/model.js index 608ce1cd0..42aca7aa0 100644 --- a/src/preview/model.js +++ b/src/preview/model.js @@ -2,19 +2,15 @@ * @module preview/model */ +/** + * @constant {String} + */ var TYPE_GENERIC = 'generic', +/** + * @constant {String} + */ TYPE_PAGE = 'page'; -/** - * @constant {String} - */ -exports.TYPE_GENERIC = TYPE_GENERIC; - -/** - * @constant {String} - */ -exports.TYPE_PAGE = TYPE_PAGE; - /** * @typedef {Object} PreviewModel * @property {String} title @@ -24,11 +20,17 @@ exports.TYPE_PAGE = TYPE_PAGE; * @property {?Array} extract `undefined` if the extract isn't * viable, e.g. if it's empty after having ellipsis and parentheticals * removed - * @property {String} type Either "EXTRACT" or "GENERIC" + * @property {String} type Either "extract" or "generic" * @property {?Object} thumbnail * * @global */ +module.exports = { + TYPE_GENERIC: TYPE_GENERIC, + TYPE_PAGE: TYPE_PAGE, + createModel: createModel, + createNullModel: createNullModel +}; /** * Creates a preview model. @@ -41,7 +43,7 @@ exports.TYPE_PAGE = TYPE_PAGE; * @param {?Object} thumbnail * @return {PreviewModel} */ -exports.createModel = function createModel( +function createModel( title, url, languageCode, @@ -60,7 +62,17 @@ exports.createModel = function createModel( type: processedExtract === undefined ? TYPE_GENERIC : TYPE_PAGE, thumbnail: thumbnail }; -}; +} + +/** + * Creates an empty preview model. + * + * @param {String} title + * @return {PreviewModel} + */ +function createNullModel( title ) { + return createModel( title, '', '', '', [], '' ); +} /** * Processes the extract returned by the TextExtracts MediaWiki API query @@ -69,11 +81,11 @@ exports.createModel = function createModel( * If the extract is `undefined`, `null`, or empty, then `undefined` is * returned. * - * @param {?Array} extract - * @return {?String} + * @param {Array|undefined|null} extract + * @return {Array|undefined} Array when extract is an not empty array, undefined otherwise */ function processExtract( extract ) { - if ( extract === undefined || extract.length === 0 ) { + if ( extract === undefined || extract === null || extract.length === 0 ) { return undefined; } return extract; diff --git a/tests/node-qunit/formatter.test.js b/tests/node-qunit/formatter.test.js index 94116ca5c..a188e7f7a 100644 --- a/tests/node-qunit/formatter.test.js +++ b/tests/node-qunit/formatter.test.js @@ -55,7 +55,7 @@ QUnit.test( 'Title is bold', function ( assert ) { function test( extract, title, expected, msg ) { var $div = $( '
' ).append( - formatter.htmlize( extract, title ) + formatter.formatPlainTextExtract( extract, title ) ); assert.equal( $div.html(), expected, msg ); } @@ -86,7 +86,7 @@ QUnit.test( 'it strips ellipsis and parentheticals', function ( assert ) { testCase = cases[ i ]; $div = $( '
' ).append( - formatter.htmlize( testCase[ 0 ], 'Test' ) + formatter.formatPlainTextExtract( testCase[ 0 ], 'Test' ) ); assert.equal( $div.html(), testCase[ 1 ] ); diff --git a/tests/node-qunit/gateway/mediawiki.test.js b/tests/node-qunit/gateway/plain/mediawiki.test.js similarity index 97% rename from tests/node-qunit/gateway/mediawiki.test.js rename to tests/node-qunit/gateway/plain/mediawiki.test.js index fabdddb28..f4f42d277 100644 --- a/tests/node-qunit/gateway/mediawiki.test.js +++ b/tests/node-qunit/gateway/plain/mediawiki.test.js @@ -1,5 +1,5 @@ var createModel = require( '../../../src/preview/model' ).createModel, - createMediaWikiApiGateway = require( '../../../src/gateway/mediawiki' ), + createMediaWikiApiGateway = require( '../../../src/gateway/plain/mediawiki' ), DEFAULT_CONSTANTS = { THUMBNAIL_SIZE: 300, EXTRACT_LENGTH: 525 @@ -146,7 +146,7 @@ QUnit.test( 'MediaWiki API gateway is correctly converting the page data to a mo page = gateway.extractPageFromResponse( MEDIAWIKI_API_RESPONSE ); assert.deepEqual( - gateway.convertPageToModel( gateway.htmlize( page ) ), + gateway.convertPageToModel( gateway.formatPlainTextExtract( page ) ), MEDIAWIKI_API_RESPONSE_PREVIEW_MODEL ); } ); diff --git a/tests/node-qunit/gateway/rest.test.js b/tests/node-qunit/gateway/restProvider.test.js similarity index 87% rename from tests/node-qunit/gateway/rest.test.js rename to tests/node-qunit/gateway/restProvider.test.js index 7c4ab0ad4..b1350c58a 100644 --- a/tests/node-qunit/gateway/rest.test.js +++ b/tests/node-qunit/gateway/restProvider.test.js @@ -1,5 +1,5 @@ var createModel = require( '../../../src/preview/model' ).createModel, - createRESTBaseGateway = require( '../../../src/gateway/rest' ), + createRESTBaseGateway = require( '../../../src/gateway/restProvider' ), DEFAULT_CONSTANTS = { THUMBNAIL_SIZE: 512 }, @@ -97,7 +97,7 @@ var createModel = require( '../../../src/preview/model' ).createModel, 'url/Barack Obama', // Generated in the stub below 'en', 'ltr', - [ document.createTextNode( 'Barack Hussein Obama II born August 4, 1961) ' ) ], + '!Barack Hussein Obama II born August 4, 1961) ...!', { source: 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/President_Barack_Obama.jpg/409px-President_Barack_Obama.jpg', width: 409, @@ -105,19 +105,17 @@ var createModel = require( '../../../src/preview/model' ).createModel, } ); +function provideParsedExtract( page ) { + return '!' + page.extract + '!'; +} + QUnit.module( 'gateway/rest', { beforeEach: function () { - window.mediaWiki.RegExp = { - escape: this.sandbox.spy( function ( str ) { - return str.replace( /([\\{}()|.?*+\-\^$\[\]])/g, '\\$1' ); - } ) - }; window.mediaWiki.Title = function ( title ) { this.getUrl = function () { return 'url/' + title; }; }; }, afterEach: function () { - window.mediaWiki.RegExp = null; window.mediaWiki.Title = null; } } ); @@ -134,15 +132,22 @@ QUnit.test( 'RESTBase gateway is called with correct arguments', function ( asse }; gateway.fetch( 'Test Title' ); - assert.deepEqual( getSpy.getCall( 0 ).args[ 0 ], expectedOptions, 'options' ); } ); +QUnit.test( 'RESTBase provider uses extract parser', function ( assert ) { + var getSpy = this.sandbox.spy(), + gateway = createRESTBaseGateway(); + + gateway.convertPageToModel( RESTBASE_RESPONSE, 512, getSpy ); + assert.deepEqual( getSpy.getCall( 0 ).args[ 0 ], RESTBASE_RESPONSE ); +} ); + QUnit.test( 'RESTBase gateway is correctly converting the page data to a model ', function ( assert ) { var gateway = createRESTBaseGateway(); assert.deepEqual( - gateway.convertPageToModel( RESTBASE_RESPONSE, 512 ), + gateway.convertPageToModel( RESTBASE_RESPONSE, 512, provideParsedExtract ), RESTBASE_RESPONSE_PREVIEW_MODEL ); } ); @@ -151,7 +156,7 @@ QUnit.test( 'RESTBase gateway doesn\'t stretch thumbnails', function ( assert ) var model, gateway = createRESTBaseGateway(); - model = gateway.convertPageToModel( RESTBASE_RESPONSE, 2000 ); + model = gateway.convertPageToModel( RESTBASE_RESPONSE, 2000, provideParsedExtract ); assert.deepEqual( model.thumbnail, @@ -160,7 +165,7 @@ QUnit.test( 'RESTBase gateway doesn\'t stretch thumbnails', function ( assert ) ); // --- - model = gateway.convertPageToModel( RESTBASE_RESPONSE, RESTBASE_RESPONSE.originalimage.height ); + model = gateway.convertPageToModel( RESTBASE_RESPONSE, RESTBASE_RESPONSE.originalimage.height, provideParsedExtract ); assert.deepEqual( model.thumbnail, @@ -169,7 +174,7 @@ QUnit.test( 'RESTBase gateway doesn\'t stretch thumbnails', function ( assert ) ); // --- - model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITH_SMALL_IMAGE, 320 ); + model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITH_SMALL_IMAGE, 320, provideParsedExtract ); assert.deepEqual( model.thumbnail, @@ -178,7 +183,7 @@ QUnit.test( 'RESTBase gateway doesn\'t stretch thumbnails', function ( assert ) ); // --- - model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITH_LANDSCAPE_IMAGE, 640 ); + model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITH_LANDSCAPE_IMAGE, 640, provideParsedExtract ); assert.deepEqual( model.thumbnail, @@ -200,7 +205,7 @@ QUnit.test( 'RESTBase gateway handles awkwardly thumbnails', function ( assert ) response.thumbnail = Object.assign( {}, RESTBASE_RESPONSE.thumbnail ); response.thumbnail.source = 'http://foo.bar/baz/Qux-320px-Quux.png/800px-Qux-320px-Quux.png'; - model = gateway.convertPageToModel( response, 500 ); + model = gateway.convertPageToModel( response, 500, provideParsedExtract ); assert.deepEqual( model.thumbnail.source, @@ -213,7 +218,7 @@ QUnit.test( 'RESTBase gateway stretches SVGs', function ( assert ) { var model, gateway = createRESTBaseGateway(); - model = gateway.convertPageToModel( SVG_RESTBASE_RESPONSE, 2000 ); + model = gateway.convertPageToModel( SVG_RESTBASE_RESPONSE, 2000, provideParsedExtract ); assert.equal( model.thumbnail.source, @@ -238,7 +243,7 @@ QUnit.test( 'RESTBase gateway handles the API failure', function ( assert ) { QUnit.test( 'RESTBase gateway does not treat a 404 as a failure', function ( assert ) { var deferred = $.Deferred(), api = this.sandbox.stub().returns( deferred.reject( { status: 404 } ).promise() ), - gateway = createRESTBaseGateway( api ), + gateway = createRESTBaseGateway( api, { THUMBNAIL_SIZE: 200 }, provideParsedExtract ), done = assert.async( 1 ); gateway.getPageSummary( 'Test Title' ).done( function () { @@ -251,7 +256,7 @@ QUnit.test( 'RESTBase gateway returns the correct data ', function ( assert ) { var api = this.sandbox.stub().returns( $.Deferred().resolve( RESTBASE_RESPONSE ).promise() ), - gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS ), + gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ), done = assert.async( 1 ); gateway.getPageSummary( 'Test Title' ).done( function ( result ) { @@ -263,7 +268,7 @@ QUnit.test( 'RESTBase gateway returns the correct data ', function ( assert ) { QUnit.test( 'RESTBase gateway handles missing images ', function ( assert ) { var model, gateway = createRESTBaseGateway(); - model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITHOUT_IMAGE, 300 ); + model = gateway.convertPageToModel( RESTBASE_RESPONSE_WITHOUT_IMAGE, 300, provideParsedExtract ); assert.equal( model.originalimage, @@ -283,7 +288,7 @@ QUnit.test( 'RESTBase gateway handles missing pages ', function ( assert ) { api = this.sandbox.stub().returns( $.Deferred().reject( response ).promise() ), - gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS ), + gateway = createRESTBaseGateway( api, DEFAULT_CONSTANTS, provideParsedExtract ), done = assert.async( 1 ); gateway.getPageSummary( 'Missing Page' ).fail( function () { diff --git a/tests/phpunit/PopupsHooksTest.php b/tests/phpunit/PopupsHooksTest.php index 6dc50fdf8..0e4cdcdc6 100644 --- a/tests/phpunit/PopupsHooksTest.php +++ b/tests/phpunit/PopupsHooksTest.php @@ -178,7 +178,7 @@ class PopupsHooksTest extends MediaWikiTestCase { $config = [ 'wgPopupsSchemaSamplingRate' => 10, 'wgPopupsBetaFeature' => true, - 'wgPopupsAPIUseRESTBase' => false, + 'wgPopupsGateway' => 'mwApiPlain', 'wgPopupsAnonsEnabledSamplingRate' => 0.9, 'wgPopupsStatsvSamplingRate' => 0 ];