Commit graph

53 commits

Author SHA1 Message Date
Piotr Miazga 0837535bdd Always set the PagePreviews visibility state
Changes:
 - ignore autocreated flag and always set the popups visilibity state
 CentralAuth will create users with `autocreated=on` when user logs
 into different wikis
 - do not call saveSettings(). AuthManager will call
 $user->saveSettings() s after calling all hooks.

Bug: T191888
Change-Id: Iac753ebbaaf175636fdc3e20d8f37883771c33d2
2018-06-11 21:46:03 +02:00
jenkins-bot 8ea676892f Merge "Properly escape messages passed to HTMLForm" 2018-05-29 10:17:42 +00:00
jenkins-bot 4c397700d1 Merge "Change the PopupsVisibility state to visible to match anon experience" 2018-05-29 08:14:28 +00:00
Brion Vibber 9602856226 Fix for changes to preferences form
The PreferencesFormPreSave hook now may return any HTMLForm
subclass, not just a PreferencesForm. It may be the new
PreferencesFormLegacy, or the future PreferrencesFormOOUI.

Change the function signature to accept any HTMLForm,
which seems to fix saving of preferences.

Bug: T195580
Change-Id: I41e37d78d87ab8965995c6e19ef76db87f7616fa
2018-05-25 09:52:48 -07:00
Kunal Mehta 87fac42511 Properly escape messages passed to HTMLForm
THe messages in 'options' need to be HTML escaped.

Spotted by the phan-taint-check plugin.

Change-Id: I1e207e5ca644551ae56cdd484f5f29267b6d764f
2018-05-20 13:41:33 -07:00
Thiemo Kreuz 865bd524f2 Add missing "public" visibility in PopupsHooks.php
Public is the default, and hook handlers must be public. I assume this
was nothing but a mistake.

Change-Id: I20eedfd8c4cb954db770afdda3f373e272530b82
2018-05-20 21:13:36 +02:00
Piotr Miazga a492d5f609 Change the PopupsVisibility state to visible to match anon experience
PagePreviews are visible to anonymous users, we would like to match
the same experience, when user creates a new account. On account
creation we mark PagePreviews settings to ON or OFF (configurable
via PopupsOptInStateForNewAccounts settings). With that approach
we can provide the best experience for new users, and keep existing
users happy (not enabling feature by default for everyone).

Bug: T191888
Change-Id: I39f42aa7268ce59c51f038048025ccf1bdf16481
2018-05-10 00:57:44 +02:00
jdlrobson 912402e840 Remove A/B testing code
No longer needed. We can't turn something off again for people
now they expect it to exist.

Clarified usage instructions of PopupsEventLogging to make sure
it's more scary given the implications

Bug: T173952
Change-Id: I7be005b79da498d8e7b7df8f18b60c1327636a2c
2018-05-07 12:37:41 -07:00
jdlrobson 4e3282e5ff Remove BetaFeature code
Popups is out of beta feature and this code is no longer needed.
Removing code is the happiest activity a developer can do.

Other changes:
* Remove redundant type field on extension.json
(If not set, the extension will default to the "other" section.)
* Repurpose `name` with `namemsg` and make use of existing i18n
messages

Bug: T193053
Change-Id: Iea832cd1f37b0e7df6ff95efd66e4a1ff2a9004e
2018-04-26 15:51:48 -07:00
Piotr Miazga 915a9708fb PopupsContext::areDependenciesMet should respect PopupsGateway config
On all wikis Popups use Restbase as default gateway. In that case we
do not require the TextExtracts nor PageImages extensions. Code should
reflect that.

Bug: T190818
Change-Id: If4ce8f709b2ca1bb3cc381afa5e80e978adf2498
2018-03-28 16:31:15 -07:00
Stephen Niedzielski 4dd9df12eb Doc: update some of the popups / preview terminology
Bug: T165036
Change-Id: Id75543d4d886e4cca8278baaf4f4a21c8e4389b7
2018-03-23 11:18:26 +01:00
jdlrobson f5f21a8d09 RESTBase url is configurable
Allow developers to use different endpoints for summaries
= developer happiness

This is useful for the following use cases:
* A developer wants to test against a production endpoint via
CORS
* A developer has setup an API where REST is hosted elsewhere
e.g. http://localhost:6927/en.wikipedia.org/v1/
* A user wants to create their own REST summary compatible
endpoint
* A wiki e.g. wikidata wants to use a different endpoint which is compatible
with the summary endpoint.

We are unlikely to use it ourselves on Wikimedia wikis (the
default should suffice) but this will be a powerful tool for

When not configured this will continue to work as per normal

Change-Id: I8a7e12fbc43cddbac678e0d7b81d1e877b747b22
2018-03-09 16:15:19 +00:00
jdlrobson a702c0f499 Capture page view-like interactions
* New action added PREVIEW_SEEN
* The action will be used to signal that a page view needs
to be recorded.
* PREVIEW_SEEN is a delayed action which is triggered
as a side-effect of the previewShow action. It is only dispatched
if the user is still previewing the same card and the page
related to the card has preview type `page`
* The pageview changelistener is added when
$wgPopupsVirtualPageViews is set to true.
* The page view changelistener listens for page views and logs
them using EventLogging when needed using
https://meta.wikimedia.org/wiki/Schema:VirtualPageView

Note:
* Currently if a user has enabled the DNT header, the
event will not be logged. There is ongoing discussion on the
ticket and fixing this will be addressed separately.
* Only title and referrer are logged in the initial version.
The task demands that "namespace" is logged but this information
is not provided by the summary endpoints we use so will need
to be added later (if indeed needed) either via a change to that
endpoint of by using JavaScript to parse the URL.

Bug: T184793
Change-Id: Id1fe34e4bdada3a41f0d888a753af366d4756590
2018-02-16 23:03:33 +00:00
libraryupgrader cc611bbc85 build: Updating mediawiki/mediawiki-codesniffer to 13.0.0
Change-Id: Ibea048de7fc5f703d7ebf54d7844e35af8eac8d8
2017-09-24 12:31:23 +00:00
Bartosz Dziewoński 2b637e42ef Improve how we render help messages in preferences
* The 'help' parameter expects a string, not a Message object. It
  seemed to be working, but caused fatals when switching the
  preferences form to the OOUI implementation (T117781).
* Use 'help-message' instead, which also avoids using the global
  request context for Message objects.

Bug: T117781
Change-Id: I5b2e44df35a2696da0e7ba8394eccf41914f6dda
2017-09-12 17:07:37 +00:00
Quiddity 311bf8f683 Use Special:MyLanguage in help link for betafeature info
Bug: T145904
Change-Id: I59c0b952cb44b31d0918c3d4659d47f2ddec7761
2017-08-26 20:28:59 +00:00
Piotr Miazga 0de054cd79 Use canonical name for NS_SPECIAL titles when checking the blacklist
Changes
 - when verifying title use canonical names for pages in
 special namespace
 - improve unit tests to verify canonical names and translated titles

Bug: T170169
Change-Id: I49592133eb8286eacf04fd3034df091f7ef2aa50
2017-08-25 15:56:02 +02:00
Timo Tijhof 55f075bf11 Remove aborting of BeforePageDisplay hook
This caused random extensions to not be able to load any ResourceLoader
modules (or do other things) on a random subset of pages and wikis.

Follows-up 29770a3.

Bug: T173411
Change-Id: I8dfc1085cb7d902f9e9be8a71324dc4cd850a500
2017-08-18 16:38:42 -07:00
jdlrobson e4e9bb3bd6 Popups A/B test infrastructure
Introduce PopupsAnonsExperimentalGroupSize config variable. This defines
a population size who will be subject to experimentation. If the group
size is undefined or 0 (default) and PopupsBetaFeature is false
(default value) Popups will be enabled for everyone. If it is any other
value, half that group will see page previews.

Drop the config variable PopupsSchemaSamplingRate - we will now only
EventLog when an experiment is occuring. This means we can simplify the
MWEventLogger class as shouldLog will always be truthy. Given server
side eventlogging is only used for preference changes
traffic should be low and not need sampling.

Introduce getUserBucket which determines whether a user is in a bucket
on, off or control based on the value of
PopupsAnonsExperimentalGroupSize. Add tests showing how these
buckets are calculated.

Caution:
A kill switch wgPopupsEventLogging is provided for safety.
It defaults to false. Before merging, please check if any config changes
are necessary.

Bug: T171853
Change-Id: If2a0c5fceae78262c44cb522af38a925cc5919d3
2017-08-17 21:07:07 +00:00
Kunal Mehta 05fafbf8ba build: Updating mediawiki/mediawiki-codesniffer to 0.11.0
Change-Id: I7b00bf0beb47f54c4543de0d605c80ebdd6cdb4d
2017-08-11 00:21:26 -04:00
Umherirrender afb2db82ad Improve some parameter docs
Change-Id: Ic78a889eb7374731a282312c9eadb701483ae298
2017-08-10 13:24:00 +02:00
Baha 29770a3ff7 Disable Previews on blacklisted pages
Introduce a config variable `PopupsPageBlacklist`. Previews code won't
be shipped to pages listed in the config variable.

Bug: T170169
Change-Id: Ia8342b55c682f444ba79e959dcc1180527a31374
2017-07-31 09:10:30 -04:00
Piotr Miazga 3d0c5b1cc3 Hygiene: Dependency Injection for Popups
Changes:
 - removed ugly PopupsContext::getInstance
 - removed ugly PopupsContextTestWrapper helper
 - defined all services inside ServiceWirings
 - fixed unit tests to test classes directly or use MediawikiServices

Change-Id: Ie27e28bb07aebe01014848c290369b1b1f098e9b
2017-07-24 22:41:28 +00:00
Kunal Mehta 9dfa3e5ee5 build: Updating mediawiki/mediawiki-codesniffer to 0.10.1
Change-Id: I835fadf053efea56a3037d7b64af8feca12f9c0f
2017-07-23 00:35:36 -07:00
Piotr Miazga c0052fcb08 Re-enable MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic sniff
Bug: T168384
Change-Id: I4d4681121df974a8471d7c4c8df8a6158f8df22a
2017-07-13 21:14:29 +02:00
jenkins-bot 8ea2211719 Merge "Re-enable MediaWiki.Commenting.FunctionComment.MissingReturn sniff" 2017-07-13 17:42:22 +00:00
jenkins-bot 22d9ef3e24 Merge "Re-enable MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment sniff" 2017-07-13 17:42:21 +00:00
Piotr Miazga 75ef7c4f93 Re-enable MediaWiki.Commenting.FunctionComment.MissingReturn sniff
Bug: T168384
Change-Id: I8d7b750503ca9c951267a948862c3685ea036100
2017-07-13 15:47:00 +02:00
Piotr Miazga 5b62bc625b Re-enable MediaWiki.Commenting.FunctionComment.MissingParamTag sniff
Changes also solve the MediaWiki.Commenting.FunctionComment.ParamNameNoMatch
sniff

Bug: T168384
Change-Id: Idd80e42943a57a4b6211c50a4aac2f1d20e6232d
2017-07-13 10:43:00 +00:00
Piotr Miazga b8e7a79a20 Re-enable MediaWiki.Commenting.FunctionComment.MissingParamComment sniff
Bug: T168384
Change-Id: I8b29f0ec6804e24ea4d61fb1bf1a528dddaf8fb8
2017-07-13 11:33:04 +01:00
Piotr Miazga 18b6675b4a Re-enable MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment sniff
Bug: T168384
Change-Id: Id64269f5950d6da5fee3f18825ce2d713d0446b0
2017-07-12 22:44:12 +02:00
Piotr Miazga 8bba8c1417 Send disabled event when user disables Page Preview
Changes:
 - introduced new UserPreferencesChangeHandler class that listens to
 PreferencesFormPreSave hook
 - introduced wrapper for EventLogging extension plus NullLogger when
 EventLogging extension is not availalbe
 - when user changes PagePreview to disabled system will trigger
 disabled event

Bug: T167365
Change-Id: I63faecb0495eb30a9fc2763e7ddf3944baf7f55a
2017-07-12 15:59:42 +02:00
Kunal Mehta ba9e3c68f6 build: Updating mediawiki/mediawiki-codesniffer to 0.9.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.MissingParamComment
* MediaWiki.Commenting.FunctionComment.MissingParamTag
* MediaWiki.Commenting.FunctionComment.MissingReturn
* MediaWiki.Commenting.FunctionComment.ParamNameNoMatch
* MediaWiki.FunctionComment.Missing.Public
* MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.NewLineComment

Change-Id: Id9e98b7a4e87d00c63e7b509506c23f12cf0d380
2017-06-20 00:19:34 -07: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
Piotr Miazga 49c4cb4d42 Introduce PHPCS check in CI
Introduced PHPCS check in CI - using same configuration as in
MobileFrontend. Additionally fixed wrong code style.

Change-Id: I0c879553d355c2a277fcc4349a93e85c65eb2291
2017-05-16 19:59:29 +02:00
joakin c9d325d01e Tests: Migrate processLinks.test.js to node-qunit
Tests are basically unchanged, except for some stubs on beforeEach.

Supporting changes:
* Bring stubs from the mediawiki library for mw.Uri,
  mw.Title.newFromText and mw.RegExp into stubs.js
* Remove hook onResourceLoaderTestModules given there are no resource
  loader test modules after migrating processLinks.test.js

Why bring stubs from real source? This is not optimal. It could be the
case that the stubs would need to be updated at some point in the
future. That's why in the comment of each stub, it is specified where it
came from, and what was changed to make it work. It is not optimal but
it should help with a future update if necessary.

Also checked the history of the stubs and these three stubs are very
stable with a small commits per year, usually adding some extra
functionality (not breaking changes) (the rest of the commits are
docs/format stuff), so the core behavior that we rely on here shouldn't
change in a fundamental way. See the github links:

* https://github.com/wikimedia/mediawiki/commits/master/resources/src/mediawiki/mediawiki.Uri.js
* https://github.com/wikimedia/mediawiki/commits/master/resources/src/mediawiki/mediawiki.Title.js
* https://github.com/wikimedia/mediawiki/commits/master/resources/src/mediawiki/mediawiki.RegExp.js

Right now this stubs allow us to bring the test to run in isolation in
node.

The initial plan was to do change the test to be less test-case oriented
with dependencies on mediawiki.*.js and not to bring fake "real" stubs,
but after looking into it, given that:
1. the test cases in the test seem pretty informative showing the kind
   of links that popups accepts
2. the stubs are acceptably easy to bring in, and are pretty stable
I decided to go with this approach initially to finish the migration
without changing the meaning of the tests.

If we want to remove the stubs and morph the test to verify stub calls
and move the test cases to documentation on the source, I'll tackle that
on a future commit.

Bug: T160406
Change-Id: Ieea378c9b7fec9116222b4a099c226d1f1131f65
2017-04-26 12:26:43 +02:00
Piotr Miazga 9590284c70 Sanitize gadget name
MediaWikiGadgetsDefinition does some basic gadget name sanitization
and we have to do the same when checking "is gadget enabled for user"

Changes:
 - sanitize gadget name same way as
   MediaWikiGadgetsDefinitionRepo::newFromDefinition() does.
 - add try{} catch() when loading gadget as getGadget might throw an
   exception

Bug: T160081
Change-Id: Ia7a57e9dcfa3b25129d6d2bf75795372fad2b251
2017-04-17 17:29:32 +00:00
Sam Smith d55e8b9a17 Don't load entire codebase in QUnit tests
As noted in T160406, the only QUnit tests that requires a running
MediaWiki instance is the test for mw.popups.processLinks. The function
itself is isolated from the rest of the codebase.

Now, as noted in T162876#3182198, during boot the
ext.eventLogging.Schema module is loaded asynchronously with
mw.loader.using. Since boot is unconditional and happens ASAP this
happens when the tests are loaded and run.

In the short term this can be avoided by not making the tests depend on
the entire codebase. The long term solution is laid out in T160406.

Supporting changes:
* Bundle assets with webpack@2.4.1.

Bug: T162876
Change-Id: If1ee1853ba7a9b2a66b24bb93b4e6062b92b0dba
2017-04-14 17:59:32 +01:00
Ed Sanders d9d2be5de4 Remove hard dependency on BetaFeatures
Also fix typos in config file.

Bug: T161829
Change-Id: I91fd695ab9d2e4b142c67884f5e8c83f3142d240
2017-03-30 21:00:59 +01:00
Baha 9a94300858 Log events to statsv for monitoring PagePreviews performance
For logging to work:
1. $wgWMEStatsdBaseUri needs to point to a valid statsv endpoint,
   e.g. 'https://en.wikipedia.org/beacon/statsv'.
2. $wgPopupsStatsvSamplingRate needs to be set. Note that the codebase
   already contains the EventLogging functionality, which is configured
   separately. Separately configuring different logging mechanisms
   allows us to avoid sampling mistakes that may arise while choosing
   one or the other. For example, let's say we want to use EventLogging for
   10% of users and statsv for 5%. We'd sample all users into two
   buckets: 50/50. And then we'd have to set the sampling rates as
   20% and 10% respectively, only because of the bucketing above. To avoid
   this kind of complications, separate sampling rates are used for each
   logging mechanism. This, of course, may result in situations where a
   session is logged via both EventLogging and statsv.
3. The WikimediaEvents extension needs to be installed. The extension
   adds the `ext.wikimediaEvents` module to the output page. The
   logging functionality is delegated to this module.

Notable changes:
* The FETCH_START and FETCH_END actions are converted to a timed action.
* The experiments stub used in tests has been extracted to the stubs
  file.

Logged data is visualized at
https://grafana.wikimedia.org/dashboard/db/reading-web-page-previews

Bug: T157111
Change-Id: If3f1a06f1f623e8e625b6c30a48b7f5aa9de24db
2017-03-14 08:51:10 +00:00
joakin d6497c5a66 Hygiene: Remove stubs files from browser qunit tests
Changes:
* Remove tests/qunit/ext.popups/stubs/ files
* Remove RL module ext.popups.tests.stubs from PopupsHooks.php
* Change PopupsHooksTest to assert 1 qunit resource module instead of 2

Change-Id: Ic6e971b69e4d5898d237c37982f400671412ddda
2017-03-06 17:09:15 +01:00
Baha 5d4cc8d15a Allow bucketing anons
* Logged in users bypass bucketing. They keep working as before.
* When Page Previews is configured as a beta feature, logged out users
  won't see the feature.
* If an anonymous user has enabled/disabled the feature using
  the settings cog then they will see or not see the feature
  depending on the value of their setting.
* The other anonymous users are bucketed. By default 90% of these
  users see the feature, the other 10% don't. These numbers can be
  controlled by the config variable `wgPopupsAnonsEnabledSamplingRate`.

Bug: T157700
Change-Id: I5307587b10f4849c4e82d3b064ff759121c2de67
2017-03-01 10:45:32 +00:00
Sam Smith 61b4e70dea tests: Actually run QUnit tests
I225019b8 introduced a regression where empty Resource Loader modules,
i.e. modules without any scripts, were being added in the
ResourceLoaderTestModules handler because the base directory wasn't
being calculated properly.

Change-Id: I25b01b2b5a4fe78e5c784eeba25bdaec37198abf
2017-02-22 12:01:12 +00:00
Piotr Miazga 2988a6e620 Hygiene: Move Popups.hooks into includes folder
Lets keep all extenion PHP files in one folder

Change-Id: I225019b895df038c1d43a082ac4244053d0b96dd
2017-02-14 21:04:49 +01:00
jdlrobson 64e7bfd620 Hygiene: Rename isEnabledByUser to shouldSendModuleToUser
Sometimes we make choices on the users behalf if we don't have
sufficient information, so this name is more applicable.

If beta features is disabled and the user is anon they have not
explicitly opted in.

Change-Id: I5d816f569fc54f8bf74d6e5a06246b7fa7036e06
2017-02-10 10:07:28 -08:00
jdlrobson 4e2ce1ce39 Only add Popups code to output page where needed
If the Popups code is enabled in beta feature mode only then
only add it to the page if the beta feature is enabled.

isEnabledByUser now returns false if the user is anonymous
and Popups is restricted to beta mode.

Bug: T156290
Change-Id: If152d2a67a079050173c6d642e0960b59730bc6d
2017-02-09 10:43:53 -08:00
Piotr Miazga c13ab30bfa Move conflicting NavPopups gadget name into config var
Changes:
 - removed hardcoded comflicting Navigation Popups gadget name
 - introduced a config variable to specify conflicting gadget name

Bug: T151058
Change-Id: Ief5c6f90ec6dd6c074931f7d9ff20297d4718fe5
2017-01-12 18:07:20 +01:00
Piotr Miazga 211f1d1658 Disable Page Previews preferences when NavPopups are enabled
Changes:
 - introduced PopupsGadgetsIntegration class handles all checks
 - show help message on Preferences page when NavPopups is enabled
 - unit test everything

Bug: T151058
Change-Id: Ia474b1b30378efe84dedf3ad47c1f833e88d69b5
2017-01-11 01:06:48 +01:00
Piotr Miazga 05eccb31c1 Hygiene: use UserGetDefaultOptions instead of ExtensionRegistration
Changes:
 - removed onExtensionRegistration and related TODOs
 - introduced onUserGetDefaultOptions hook

Change-Id: I6648802c19d90df36a211d6494033aca30c078ca
2017-01-10 18:34:43 +01:00
Piotr Miazga c587a9785b Hygiene: Improve code quality by reaching 100% coverage
Changes:
 - added missing unit tests
 - introduced PopupsContextTestWrapper, removed all unit-tests logic
   from Hooks/Context classes
 - removed getModule() from Popups.hooks.php, it's hooks responsibility
   to keep single context instance
 - removed class_exists calls, use ExtensionRegistry instead
 - pass ExtensionRegistry as a dependency so it's easy to mock
 - reach 100% code coverage
 - introduce PoupsContext::isBetaOn() as it was used in many places

Change-Id: Id014efe72edf24628539c76968e53eb3e06709f4
2016-12-21 16:03:33 +01:00