jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/341349 )
Change subject: Hygiene: Remove duplicate file preview/index.js
......................................................................
Hygiene: Remove duplicate file preview/index.js
The same file is on preview/model.js which is the one actually used by
the application. For some reason the file is a duplicate of model.js,
and it is the file that is required on its QUnit tests.
This patch removes it and points the unit tests to the correct file,
preview/model.js
It was also required by popups.js which was removed in the previous
commit.
Change-Id: Id175a764d9b67fb8d0e8fbf4a4623a3420f76094
---
D src/preview/index.js
M tests/node-qunit/gateway/mediawiki.test.js
2 files changed, 1 insertion(+), 140 deletions(-)
Approvals:
jenkins-bot: Verified
Jdlrobson: Looks good to me, approved
diff --git a/src/preview/index.js b/src/preview/index.js
deleted file mode 100644
index 89dadb5..0000000
--- a/src/preview/index.js
+++ /dev/null
@@ -1,139 +0,0 @@
-var createModel,
- TYPE_GENERIC = 'generic',
- TYPE_PAGE = 'page';
-
-/**
- * @typedef {Object} ext.popups.PreviewModel
- * @property {String} title
- * @property {String} url The canonical URL of the page being previewed
- * @property {String} languageCode
- * @property {String} languageDirection Either "ltr" or "rtl"
- * @property {String|undefined} 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 {Object|undefined} thumbnail
- */
-
-/**
- * Creates a preview model.
- *
- * @param {String} title
- * @param {String} url The canonical URL of the page being previewed
- * @param {String} languageCode
- * @param {String} languageDirection Either "ltr" or "rtl"
- * @param {String} extract
- * @param {Object|undefined} thumbnail
- * @return {ext.popups.PreviewModel}
- */
-createModel = function (
- title,
- url,
- languageCode,
- languageDirection,
- extract,
- thumbnail
-) {
- var processedExtract = processExtract( extract ),
- result = {
- title: title,
- url: url,
- languageCode: languageCode,
- languageDirection: languageDirection,
- extract: processedExtract,
- type: processedExtract === undefined ? TYPE_GENERIC :
TYPE_PAGE,
- thumbnail: thumbnail
- };
-
- return result;
-};
-
-/**
- * Processes the extract returned by the TextExtracts MediaWiki API query
- * module.
- *
- * @param {String|undefined} extract
- * @return {String|undefined}
- */
-function processExtract( extract ) {
- var result;
-
- if ( extract === undefined || extract === '' ) {
- return undefined;
- }
-
- result = extract;
- result = removeParentheticals( result );
- result = removeEllipsis( result );
-
- return result.length > 0 ? result : undefined;
-}
-
-/**
- * Removes the trailing ellipsis from the extract, if it's there.
- *
- * This function was extracted from
- * `mw.popups.renderer.article#removeEllipsis`.
- *
- * @param {String} extract
- * @return {String}
- */
-function removeEllipsis( extract ) {
- return extract.replace( /\.\.\.$/, '' );
-}
-
-/**
- * Removes parentheticals from the extract.
- *
- * If the parenthesis are unbalanced or out of order, then the extract is
- * returned without further processing.
- *
- * This function was extracted from
- * `mw.popups.renderer.article#removeParensFromText`.
- *
- * @param {String} extract
- * @return {String}
- */
-function removeParentheticals( extract ) {
- var
- ch,
- result = '',
- level = 0,
- i = 0;
-
- for ( i; i < extract.length; i++ ) {
- ch = extract.charAt( i );
-
- if ( ch === ')' && level === 0 ) {
- return extract;
- }
- if ( ch === '(' ) {
- level++;
- continue;
- } else if ( ch === ')' ) {
- level--;
- continue;
- }
- if ( level === 0 ) {
- // Remove leading spaces before brackets
- if ( ch === ' ' && extract.charAt( i + 1 ) === '(' ) {
- continue;
- }
- result += ch;
- }
- }
-
- return ( level === 0 ) ? result : extract;
-}
-
-module.exports = {
- /**
- * @constant {String}
- */
- TYPE_GENERIC: TYPE_GENERIC,
- /**
- * @constant {String}
- */
- TYPE_PAGE: TYPE_PAGE,
- createModel: createModel
-};
diff --git a/tests/node-qunit/gateway/mediawiki.test.js
b/tests/node-qunit/gateway/mediawiki.test.js
index 773a9af..9b81ee4 100644
--- a/tests/node-qunit/gateway/mediawiki.test.js
+++ b/tests/node-qunit/gateway/mediawiki.test.js
@@ -1,4 +1,4 @@
-var createModel = require( '../../../src/preview' ).createModel,
+var createModel = require( '../../../src/preview/model' ).createModel,
createMediaWikiApiGateway = require( '../../../src/gateway/mediawiki' ),
DEFAULT_CONSTANTS = {
THUMBNAIL_SIZE: 300
--
To view, visit https://gerrit.wikimedia.org/r/341349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id175a764d9b67fb8d0e8fbf4a4623a3420f76094
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: master
Gerrit-Owner: Jhernandez <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits