Jdlrobson has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/335590 )
Change subject: Build previews with webpack
......................................................................
Build previews with webpack
Change-Id: Ieb9e3bf1bee550e4234a5796c0b51405ba458b1f
---
A build_resources/ext.popups/preview/index.js
R build_resources/ext.popups/preview/model.js
M extension.json
M resources/ext.popups/preview/index.js
M resources/ext.popups/reducers/index.js
M webpack.config.js
6 files changed, 273 insertions(+), 32 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Popups
refs/changes/90/335590/1
diff --git a/build_resources/ext.popups/preview/index.js
b/build_resources/ext.popups/preview/index.js
new file mode 100644
index 0000000..cbbfa3e
--- /dev/null
+++ b/build_resources/ext.popups/preview/index.js
@@ -0,0 +1,5 @@
+( function ( mw ) {
+
+ mw.popups.preview = require( './model' );
+
+}( mediaWiki ) );
diff --git a/resources/ext.popups/preview/model.js
b/build_resources/ext.popups/preview/model.js
similarity index 92%
rename from resources/ext.popups/preview/model.js
rename to build_resources/ext.popups/preview/model.js
index f075e0a..3e2e602 100644
--- a/resources/ext.popups/preview/model.js
+++ b/build_resources/ext.popups/preview/model.js
@@ -1,6 +1,7 @@
( function ( mw ) {
- var ONE_DAY = 24 * 60 * 60 * 1000, // ms.
+ var createModel,
+ ONE_DAY = 24 * 60 * 60 * 1000, // ms.
TYPE_GENERIC = 'generic',
TYPE_EXTRACT = 'extract';
@@ -22,16 +23,6 @@
*/
/**
- * @constant {String}
- */
- mw.popups.preview.TYPE_GENERIC = TYPE_GENERIC;
-
- /**
- * @constant {String}
- */
- mw.popups.preview.TYPE_EXTRACT = TYPE_EXTRACT;
-
- /**
* Creates a preview model.
*
* @param {String} title
@@ -43,7 +34,7 @@
* @param {Object|undefined} thumbnail
* @return {ext.popups.PreviewModel}
*/
- mw.popups.preview.createModel = function (
+ createModel = function (
title,
url,
languageCode,
@@ -149,4 +140,16 @@
return ( level === 0 ) ? result : extract;
}
+module.exports = {
+ /**
+ * @constant {String}
+ */
+ TYPE_GENERIC: TYPE_GENERIC,
+ /**
+ * @constant {String}
+ */
+ TYPE_EXTRACT: TYPE_EXTRACT,
+ createModel: createModel
+};
+
}( mediaWiki ) );
diff --git a/extension.json b/extension.json
index 82675fd..be0c822 100644
--- a/extension.json
+++ b/extension.json
@@ -82,7 +82,6 @@
"resources/ext.popups/counts.js",
"resources/ext.popups/preview/index.js",
- "resources/ext.popups/preview/model.js",
"resources/ext.popups/gateway.js",
"resources/ext.popups/renderer.js",
diff --git a/resources/ext.popups/preview/index.js
b/resources/ext.popups/preview/index.js
index 69754e5..2442f94 100644
--- a/resources/ext.popups/preview/index.js
+++ b/resources/ext.popups/preview/index.js
@@ -1,5 +1,219 @@
-( function ( mw ) {
+/******/ (function(modules) { // webpackBootstrap
+/******/ // The module cache
+/******/ var installedModules = {};
- mw.popups.preview = {};
+/******/ // The require function
+/******/ function __webpack_require__(moduleId) {
-}( mediaWiki ) );
+/******/ // Check if module is in cache
+/******/ if(installedModules[moduleId])
+/******/ return installedModules[moduleId].exports;
+
+/******/ // Create a new module (and put it into the cache)
+/******/ var module = installedModules[moduleId] = {
+/******/ exports: {},
+/******/ id: moduleId,
+/******/ loaded: false
+/******/ };
+
+/******/ // Execute the module function
+/******/ modules[moduleId].call(module.exports, module,
module.exports, __webpack_require__);
+
+/******/ // Flag the module as loaded
+/******/ module.loaded = true;
+
+/******/ // Return the exports of the module
+/******/ return module.exports;
+/******/ }
+
+
+/******/ // expose the modules object (__webpack_modules__)
+/******/ __webpack_require__.m = modules;
+
+/******/ // expose the module cache
+/******/ __webpack_require__.c = installedModules;
+
+/******/ // __webpack_public_path__
+/******/ __webpack_require__.p = "";
+
+/******/ // Load entry module and return exports
+/******/ return __webpack_require__(0);
+/******/ })
+/************************************************************************/
+/******/ ({
+
+/***/ 0:
+/***/ function(module, exports, __webpack_require__) {
+
+ ( function ( mw ) {
+
+ mw.popups.preview = __webpack_require__( 7 );
+
+ }( mediaWiki ) );
+
+
+/***/ },
+
+/***/ 7:
+/***/ function(module, exports) {
+
+ ( function ( mw ) {
+
+ var createModel,
+ ONE_DAY = 24 * 60 * 60 * 1000, // ms.
+ TYPE_GENERIC = 'generic',
+ TYPE_EXTRACT = 'extract';
+
+ /**
+ * @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 {Date|Number|undefined} lastModified
+ * @property {Bool|undefined} isRecent If `lastModified` is
`undefined`, then
+ * this will also be undefined; otherwise, whether or not
`lastModified` is
+ * less than 24 hours ago
+ * @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 {Date|Number|undefined} lastModified
+ * @param {Object|undefined} thumbnail
+ * @return {ext.popups.PreviewModel}
+ */
+ createModel = function (
+ title,
+ url,
+ languageCode,
+ languageDirection,
+ extract,
+ lastModified,
+ thumbnail
+ ) {
+ var processedExtract = processExtract( extract ),
+ result = {
+ title: title,
+ url: url,
+ languageCode: languageCode,
+ languageDirection: languageDirection,
+ extract: processedExtract,
+ type: processedExtract === undefined ?
TYPE_GENERIC : TYPE_EXTRACT,
+ thumbnail: thumbnail
+ };
+
+ if ( lastModified ) {
+ result.lastModified = lastModified;
+ result.isRecent = mw.now() - lastModified <
ONE_DAY;
+ }
+
+ 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_EXTRACT: TYPE_EXTRACT,
+ createModel: createModel
+ };
+
+ }( mediaWiki ) );
+
+
+/***/ }
+
+/******/ });
\ No newline at end of file
diff --git a/resources/ext.popups/reducers/index.js
b/resources/ext.popups/reducers/index.js
index 5c63f28..f5ed12a 100644
--- a/resources/ext.popups/reducers/index.js
+++ b/resources/ext.popups/reducers/index.js
@@ -47,9 +47,9 @@
( function ( popups ) {
popups.reducers = {
- eventLogging: __webpack_require__( 7 ),
- preview: __webpack_require__( 9 ),
- settings: __webpack_require__( 10 )
+ eventLogging: __webpack_require__( 8 ),
+ preview: __webpack_require__( 10 ),
+ settings: __webpack_require__( 11 )
};
}( mediaWiki.popups ) );
@@ -62,7 +62,8 @@
/* 4 */,
/* 5 */,
/* 6 */,
-/* 7 */
+/* 7 */,
+/* 8 */
/***/ function(module, exports, __webpack_require__) {
( function ( popups, nextState ) {
@@ -88,7 +89,7 @@
* @return {Object} The state as a result of processing the
action
*/
module.exports = function ( state, action ) {
- var nextCount;
+ var nextCount, abandonEvent;
if ( state === undefined ) {
state = {
@@ -133,6 +134,13 @@
event: undefined
} );
+ case popups.actionTypes.FETCH_END:
+ return nextState( state, {
+ interaction: nextState(
state.interaction, {
+ previewType:
action.result.type
+ } )
+ } );
+
case popups.actionTypes.PREVIEW_SHOW:
nextCount = state.previewCount + 1;
@@ -171,12 +179,23 @@
} );
case popups.actionTypes.ABANDON_END:
+ abandonEvent = {
+ linkInteractionToken:
state.interaction.token,
+ totalInteractionTime:
Math.round( state.interaction.finished - state.interaction.started )
+ };
+
+ // Has the preview been shown? If so,
then, in the context of the
+ // instrumentation, then the preview
has been dismissed by the user
+ // rather than the user has abandoned
the link.
+ if (
state.interaction.timeToPreviewShow !== undefined ) {
+ abandonEvent.action =
'dismissed';
+ abandonEvent.previewType =
state.interaction.previewType;
+ } else {
+ abandonEvent.action =
'dwelledButAbandoned';
+ }
+
return nextState( state, {
- event: {
- action:
state.interaction.timeToPreviewShow ? 'dismissed' : 'dwelledButAbandoned',
- linkInteractionToken:
state.interaction.token,
- totalInteractionTime:
Math.round( state.interaction.finished - state.interaction.started )
- }
+ event: abandonEvent
} );
default:
@@ -184,11 +203,11 @@
}
};
- }( mediaWiki.popups, __webpack_require__( 8 ) ) );
+ }( mediaWiki.popups, __webpack_require__( 9 ) ) );
/***/ },
-/* 8 */
+/* 9 */
/***/ function(module, exports) {
/**
@@ -232,7 +251,7 @@
/***/ },
-/* 9 */
+/* 10 */
/***/ function(module, exports, __webpack_require__) {
( function ( popups, nextState ) {
@@ -330,11 +349,11 @@
}
};
- }( mediaWiki.popups, __webpack_require__( 8 ) ) );
+ }( mediaWiki.popups, __webpack_require__( 9 ) ) );
/***/ },
-/* 10 */
+/* 11 */
/***/ function(module, exports, __webpack_require__) {
( function ( popups, nextState ) {
@@ -393,7 +412,7 @@
}
};
- }( mediaWiki.popups, __webpack_require__( 8 ) ) );
+ }( mediaWiki.popups, __webpack_require__( 9 ) ) );
/***/ }
diff --git a/webpack.config.js b/webpack.config.js
index ae47dee..504dda3 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -11,6 +11,7 @@
filename: '/[name]/index.js'
},
entry: {
+ 'ext.popups/preview':
'./build_resources/ext.popups/preview/index.js',
'ext.popups/reducers':
'./build_resources/ext.popups/reducers/index.js',
'ext.popups/changeListeners':
'./build_resources/ext.popups/changeListeners/index.js'
}
--
To view, visit https://gerrit.wikimedia.org/r/335590
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ieb9e3bf1bee550e4234a5796c0b51405ba458b1f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Popups
Gerrit-Branch: mpga
Gerrit-Owner: Jdlrobson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits