Commit graph

1238 commits

Author SHA1 Message Date
Sam Smith 67eb3b1dcf i13n: Log EL events with mw.track
Currently, the mw.eventLog.Schema class samples per pageview. However,
we expect that if a user is bucketed for a session, then all
EventLogging events logged during that session are in the sample.

Moreover, loading the class in the way that we did - asynchronously,
using mw.loader#using - introduced an issue where the eventLogging
change listener would subscribe in the next tick of the JavaScript VM's
event loop and miss the "pageLoaded" event being queued (see T167273).

Changes:
* Make the schema module follow the form of the statsvInstrumentation
  module, i.e. make it expose the #isEnabled method, and add the
  associated getEventLoggingTracker function.
* Update the eventLogging change listener accept the tracker returned by
  getEventLoggingTracker.
* Update/fix related JSDoc documentation.

Bug: T167236
Bug: T167273
Change-Id: I4f653bbaf1bbc2c2f70327e338080e17cd3443d4
2017-06-17 00:51:32 +00:00
joakin 9ed1703cf8 Test: Upgrade mw-node-qunit and use globs
To get cross-shell and OS glob support and fix some of the sinon
deprecation warnings regarding getConfig.

Bug: T168054
Change-Id: Idd6d47c1e63836c8429156cd9030ef9fda4479b1
2017-06-16 14:50:19 +02:00
joakin 98d9415361 Hygiene: Rename builder vars on require preview/model
preview/model is just a module/namespace object, not a builder class or
similar.

This patch changes a couple of imports to reference some of the exposed
functions of the preview/model where required.

In a shiny future, this pattern would be:

    const { createModel, createNullModel } =
      require( '../preview/model' )

Bug: T165018
Change-Id: If6ad4611538ca4f24e2443c0c3ed433275e995a6
2017-06-16 14:50:19 +02:00
joakin 010a4d91a6 Hygiene: Simplify gateways
gateway/*/rest were copies of gateway/restProvider just passing
a different provider. Docs were the same, they were untested, and
looking at them they seemed like unnecessary abstraction.

This patch removes the plain vs html structure, and separates gateways
like before, by endpoint.

There is a light utility in gateway/restFormatters.js that adapts the
call from the rest gateway to use formatters.js functions. It needs
testing, that I'll add in the next patch.

The flow for creating a gateway ends up as follows:

1. index.js calls gateway/index#createGateway( mw.config )
2. createGateway chooses based on wgPopupsGateway and invokes
  * mediawiki.js#createMediaWikiApiGateway or
  * rest.js#createRESTBaseGateway w/ restFormatters.js#parsePlainTextResponse or
  * rest.js#createRESTBaseGateway w/ restFormatters.js#parseHTMLResponse

Changes:
* Removed src/gateway/{plain,html}/rest.js
  * Extracted formatter functions to src/gateway/restFormatters.js
* src/gateway/plain/mediawiki.js -> src/gateway/mediawiki.js
         * tests/node-qunit/gateway/plain/mediawiki.test.js ->
           tests/node-qunit/gateway/mediawiki.test.js
* gateway/restProvider{,.test}.js -> gateway/rest{,.test}.js
* Change gateway/index.js#createGateway to properly call the rest
  gateways with the rest formatters

Bug: T165018
Change-Id: Ia75695dfc192aad5bc581a68882514bad6c29646
2017-06-16 14:49:59 +02:00
joakin 8f408e2937 Fix the npm script test:node
npm scripts are run under sh. globstar support is only available in bash
> 4 with globstar enabled, so **/*.js was actually being resolved to
*/*.js only running tests 2 directories deep.

This made the test mediawiki.test.js not run since it was moved to the
3rd level deep folder (and actually broke), resulting in:

  208 tests
  403 passed

With this change, it fixes getting the test files, and fixes the
mediawiki.test.js, resulting in:

  215 tests
  413 passed

instead.

This makes it work everywhere and as nested as it will get for now. Will
consider adding glob support to mw-node-qunit later for easier use in
other projects too.

Bug: T165018
Change-Id: Id0164b2673c8afe8a24fd0eb4aa255c134253862
2017-06-16 14:49:33 +02:00
joakin b12599c871 Hygiene: Move createGateway to gateway/index.js
And add tests, given it is growing in complexity.

Additional changes:
* Interface ext.popups.Gateway -> Gateway in docs

Bug: T165018
Change-Id: I8a12333ad9d14d6a7fbde11afc42f607881e8ea3
2017-06-16 12:46:05 +02:00
joakin 490583bcb9 Hygiene: Capture jQuery at construction
and not from global scope all the time.

Bug: T165018
Change-Id: I90b55a65a7ca25c2998c811a98401feaeced165e
2017-06-15 20:10:08 +02:00
jenkins-bot a3b5bddefe Merge "i13n: Extract experiments module" 2017-06-14 20:09:02 +00:00
jenkins-bot 08fa97d8e0 Merge "Increase line number count of preview with tall image" 2017-06-14 18:44:17 +00:00
Sam Smith 6159af3151 i13n: Extract experiments module
... from the statsvInstrumentation module so that the bucketing logic
can be shared with other instrumentation modules.

Change-Id: I5732fa539a3911939fa85fa88c102fa8dcfa5613
2017-06-14 11:04:32 -07:00
Baha 686c1306ba Increase line number count of preview with tall image
Previews with tall image now have 9 lines of text as opposed to
the previous 7 lines.

Bug: T165978
Change-Id: Ib3d39f5164663f9c9ccaa3c0a974d524fc2f9463
2017-06-14 10:22:02 -04:00
Piotr Miazga f2fbef6ec7 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
2017-06-13 20:19:05 +02:00
jenkins-bot 9c2a4b143f Merge "eventLogging: Use base 32 instead of 16 for fnv-encoded hash" 2017-06-13 07:24:20 +00:00
Translation updater bot 39d78ebe84 Localisation updates from https://translatewiki.net.
Change-Id: Ib27d58f9128e8fada776eb70d49f9df289b0194f
2017-06-12 22:43:32 +02:00
Timo Tijhof 4996886eb9 eventLogging: Use base 32 instead of 16 for fnv-encoded hash
Follows-up 79f3b318d0.

Number#toString supports up to Base 32.
Same collision behaviour but with a shorter string.
Typical length with Base 32: 7 (max: 11)
Typical length with Base 16: 9 (max: 14)

Change-Id: I91e91341cbecdec24549ace6a6300550f5b449ee
2017-06-12 21:43:05 +01:00
joakin 38b061a468 Return empty extract if string is blank after formatting
Bug: T167626
Change-Id: Icb89cbe447226850231c3d7d74e61e5f6a5db809
2017-06-12 12:59:31 +02:00
Sam Smith fb8d54c7ce actions/rest: Use DB-key version of title
This reduces the number of 301 Redirect responses when fetching previews
from RESTBase.

Bug: T167633
Change-Id: I830947ab79e72dcc023193412c8d5bcee986e23f
2017-06-12 11:22:55 +01:00
Translation updater bot fb50482a7a Localisation updates from https://translatewiki.net.
Change-Id: I95828cf5adb566c0f77ea34ac7c485d13396a50f
2017-06-11 22:36:52 +02:00
Piotr Miazga ef283c2509 Extract rendering/parsing mediawiki responses into separate class
Page Previews should be able to consume HTML response generated by
MediaWiki. First we need to move out plain text crunching from
renderer.js and model.js. Mediawiki and Restbase gateways will have
to parse/htmlize plaintext into nice HTML by themselves.

Bug: T165018
Change-Id: I5d7e9f610bb809aa9fb035a4a9f96e9e8796c9d8
2017-06-09 18:34:25 +02:00
joakin b16a6fe735 Remove unused files processLinks{,.test}.js
Bug: T165572
Change-Id: I3139167e7caec7b7b2707c648e777e448b7de426
2017-06-08 19:37:37 +00:00
joakin 002f4c8e0c Use delegated events in container
...instead of 1 event per link

Supporting changes:
* Delegate events on the container when booting up
  * Check eligibility of title on event triggered
  * Pass the title from the event handlers into the actions instead of
    storing it in the dom
* Add title.fromElement as sugar over isvalid(gettitle())
  * Not tested as it is sugar over the other 2 functions
* Fix action tests and integration tests

processLinks to be removed next

Bug: T165572
Change-Id: I4d9837706dc77ec64121ac94410c0d2da83692e4
2017-06-08 12:31:06 -07:00
joakin 356678ffcd Add title#isValid
Which checks if a title is an eligible one for showing previews

Bug: T165572
Change-Id: I5ade3fb84d400293d24de05e10119996e711b41e
2017-06-08 12:29:33 -07:00
Sam Smith 343506bdfb gateway: Fix Accept header sent by rest gateway
... and update the RESTBASE_PROFILE constant to the latest "stable"
profile for the endpoint.

Prior to this change the Accept header sent by the rest gateway was

  application/json; charset=utf-8profile="..."

This was discovered while responding to T166605.

Change-Id: I00f277e724c561634b26c9ab10bd35332c6dba91
2017-06-08 12:19:32 -07:00
joakin ef2f99ef65 Rename getTitle.js to title.js
In order to create a title#shouldShowPreview function next in the
module.

Bug: T165572
Change-Id: I9e59bb0f525d2698f882543ca0d4a1bde6b2d5d2
2017-06-08 12:10:14 +02:00
jenkins-bot b0b10fff92 Merge "eventLogging: Add missing properties to "tapped settings cog" event" 2017-06-07 19:33:16 +00:00
Amir Sarabadani e8cba47338 Add CODE_OF_CONDUCT.md
Bug: T165540
Change-Id: Ib1b6315b6181d187e99d856f67805f3734cb7e22
2017-06-07 15:30:07 +04:30
Sam Smith 98864a7ce3 eventLogging: Add missing properties to "tapped settings cog" event
When there's an interaction, then the "tapped settings cog" event should
have the same properties set as the other interaction-specific events.

This was discovered while QAing T164256.

Bug: T164256
Change-Id: I4749b52656203c7e0c42ae742556ee996eee322a
2017-06-07 10:13:23 +01:00
Baha 39672c5f49 Make vertical preview show 7 lines
Bug: T165978
Change-Id: I3474ab271679d290be58afca0d31c25b17b0442b
2017-06-06 15:43:21 +00:00
jenkins-bot 88850bb8b1 Merge "Reduce height of horizontal gradient" 2017-06-01 20:39:36 +00:00
Baha f44218d2da Reduce height of horizontal gradient
Change padding to margin, and set the exact height of the container
to 7 lines.

Bug: T165974
Change-Id: Id4f97dddfb554ee2276b890a06030522076f8c88
2017-05-31 16:16:02 -04:00
jenkins-bot d98cc50275 Merge "Tools: Upgrade webpack to 2.6" 2017-05-31 19:17:58 +00:00
Piotr Miazga 4e60909171 Generate docs inside doc folder
Currently we have two docs folders:
 * doc which contains human-made documentation
 * docs which contains autogenerated documentation
To clean-up I moved the jsdoc target to doc/autogenerated so
we have only one documentation folder

Bug: T158236
Change-Id: I33166a84a4856e506e574e4194fa0c596b630b34
2017-05-30 10:16:57 -04:00
jdlrobson 918a74b1e6 Docs: Don't register methods as globals in documentation
This ensures all files belong to a module.
When generating documentation no globals should be present

Bug: T158236
Change-Id: I134f38620fe46db11ba94dbede739f4336e0482c
2017-05-26 10:35:07 -07:00
jdlrobson e21a640002 Run doc generation on npm test
The benefit of this is if there are any problems with the
documentation they will not enter our codebase.

We do a similar thing in MobileFrontend

Bug: T158236
Change-Id: I30329dd868fe596c490f95354c3226c9cd4a2fc7
2017-05-26 10:26:35 -07:00
Sam Smith 30e616a224 doc: Document reducers/eventLogging module
Bug: T158236
Change-Id: I327f11ba804063a912c355477e9247a99e9b6e32
2017-05-26 09:02:47 +01:00
jenkins-bot 75436d4c20 Merge "eventLogging: Add perceivedWait prop to all events" 2017-05-25 21:04:45 +00:00
Sam Smith 66234e021e eventLogging: Add perceivedWait prop to all events
... and the previewType property as well.

Per the Popups schema [0], the "opened" action should have the
perceivedWait and previewType properties set.

Bug: T166323
Change-Id: I957d123434a6b750aff6f5279865321a08367382
2017-05-25 17:00:13 -04:00
Translation updater bot 5fc590a91c Localisation updates from https://translatewiki.net.
Change-Id: If0dd53628938b689ce684b968eadae5b9c37e16b
2017-05-25 22:47:58 +02:00
jenkins-bot c57763427c Merge "doc: Add doc:start script" 2017-05-25 18:01:56 +00:00
Sam Smith b6bca56ad8 doc: Document userSettings module
Bug: T158236
Change-Id: Ia2365c7d6d1b9bc7438a3824656f1dde2a0170fb
2017-05-25 18:24:57 +01:00
Sam Smith 4eae6aebb3 doc: Add doc:start script
Like npm run start, npm run doc:start will rebuild the documentation if
any file in the src directory changes.

Supporting changes:
* Use nodemon@1.11.0.

Change-Id: I7b528525874e377533e92c0a80c8aae9f6a18620
2017-05-25 15:21:15 +00:00
jenkins-bot 18ebb84d34 Merge "doc: Document gateway modules" 2017-05-25 14:20:39 +00:00
Sam Smith 0670597434 doc: Document gateway modules
Additional changes:
* Fix the summary not showing up for the Container interface.

Bug: T158236
Change-Id: I7c5dee1b4525c2db28b89e57604d2d073620293d
2017-05-25 14:34:25 +01:00
jenkins-bot ddd2aa1634 Merge "doc: Document statsvInstrumentation module" 2017-05-25 13:15:49 +00:00
Translation updater bot 4cf8713ad9 Localisation updates from https://translatewiki.net.
Change-Id: Ib6db9d11147c1f6ab91663969987d811db4e9c40
2017-05-24 22:55:15 +02:00
Sam Smith e4f4041846 doc: Document statsvInstrumentation module
Bug: T158236
Change-Id: I138a1ef5305c0b49415d5f2a914ba45fd6aa869b
2017-05-24 10:45:49 +01:00
Translation updater bot 471e56111d Localisation updates from https://translatewiki.net.
Change-Id: I9a58b66c44aa2112d828ce1a4b9832ce296355b8
2017-05-23 22:59:46 +02:00
joakin d96be0384f Tools: Upgrade webpack to 2.6
To benefit from the bugfixes

See https://github.com/webpack/webpack/releases

Change-Id: Ia4a10c821d6dc4257bfea57658cf16d1ac028bf4
2017-05-23 20:28:23 +02:00
joakin 86c2edcf76 Deps: Upgrade mw-node-qunit
v2 updates it's dependencies itself, latest jsdom, qunit, sinon and
jquery

Change-Id: I52e9751e457100484133585b253e93b66bfee162
2017-05-23 20:20:27 +02:00
Sam Smith e9fb33af3a doc: Document isEnabled module
Bug: T158236
Change-Id: Ib80a5951e41765b982fecf4e2ac33767e4ef1738
2017-05-23 13:26:56 +01:00