Commit graph

19 commits

Author SHA1 Message Date
C. Scott Ananian 25272e7a4a Don't refer directly to PHP dom extension classes; avoid nonstandard behavior
These changes ensure that DiscussionTools is independent of DOM
library choice, and will not break if/when Parsoid switches to an
alternate (more standards-compliant) DOM library.

We run `phan` against the Dodo standards-compliant DOM library,
so this ends up flagging uses of non-standard PHP extensions to
the DOM.  These will be suppressed for now with a "Nonstandard DOM"
comment that can be grepped for, since they will eventually
will need to be rewritten or worked around.

Most frequent issues:

* Node::nodeValue and Node::textContent and Element::getAttribute()
can return null in a spec-compliant implementation.  Add `?? ''` to
make spec-compliant results consistent w/ what PHP returns.

* DOMXPath doesn't accept anything except DOMDocument.  These uses
should be replaced with DOMCompat::querySelectorAll() or similar
(which end up using DOMXPath under the covers for DOMDocument any way,
but are implemented more efficiently in a spec-compliant
implementation).

* A couple of times we have code like:
  `while ($node->firstChild!==null) { $node = $node->firstChild; }`
and phan's analysis isn't strong enough to determine that $node is still
non-null after the while.  This same issue should appear with DOMDocument
but phan doesn't complain for some reason.

One apparently legit issue:

* Node::insertBefore() is once called in a funny way which leans on
the fact that the second option is optional in PHP.  This seems to be
a workaround for an ancient PHP bug, and can probably be safely
removed.

Bug: T287611
Bug: T217867
Change-Id: I3c4f41c3819770f85d68157c9f690d650b7266a3
2021-07-30 18:15:40 -04:00
Bartosz Dziewoński d0e4aeaecb Fix notifications when new comment is under subheading
The user interface only allows you to subscribe to level 2 headings.
But we would generate events for whatever heading was the closest,
If it was e.g. level 3, no one would receive that notification.

Now we generate events for the closest level 2 heading, or we don't
generate the event at all if there isn't one (if the only headings are
of level 3 and below, or level 1, or if the comment is added before
the first heading on the page).

Bug: T286736
Change-Id: Iae99853070e353ab81c9cc29ef1d53c877adfc66
2021-07-24 05:28:10 +02:00
Bartosz Dziewoński 801b57b0f4 Add PHPUnit integration tests for EventDispatcher
Bug: T286608
Change-Id: I711483be80d455f4439e96d37844ee4552619a92
2021-07-24 05:28:04 +02:00
libraryupgrader b0884b177c build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0

npm:
* postcss: 7.0.35 → 7.0.36
  * https://npmjs.com/advisories/1693 (CVE-2021-23368)
* glob-parent: 5.1.1 → 5.1.2
  * https://npmjs.com/advisories/1751 (CVE-2020-28469)
* trim-newlines: 3.0.0 → 3.0.1
  * https://npmjs.com/advisories/1753 (CVE-2021-33623)

Change-Id: I7a71e23da561599da417db3b3077b78d91173bbc
2021-07-22 16:29:04 +00:00
Bartosz Dziewoński 37d6825c14 EventDispatcher: Ensure we fetch page content from the primary database
We used an internal API requests to fetch page content because it was
easy, but there's no way to guarantee that it returns data from the
primary database.

Use ParserOutputAccess::getParserOutput() to fetch from cache if
available. Also, use canonical output instead of user-specific,
not that it should matter.

Bug: T285895
Change-Id: I7dcd9659be77746dc2a0c4eeae2319887936b555
2021-07-01 14:52:13 +00:00
Bartosz Dziewoński 067f0c36de Config option to enable topic subscriptions backend and dtenable=1 URL parameter
…without making the topic subscriptions feature available in user preferences.

Follow-up to these commits, which added these checks in ad-hoc ways:
* 9420f22e9d
* f3422f40a6
* 23a490deca
* a555db7892

Bug: T284491
Change-Id: If2e3fb1e06d1cc489fbca14796ed77c83bb52991
2021-06-14 16:18:18 +02:00
Bartosz Dziewoński bd27a46deb Fix revealing content of deleted revisions in notifications
If the revision from which we generated the notification has been
deleted, we shouldn't include the content snippet, nor the direct link
to the comment (because the fragment ID is generated from the content).

This matches how Echo handles mention notifications.

Change-Id: Ica939f3a4efd39d0c295511d58280d3f9d584129
2021-06-03 02:45:15 +02:00
Bartosz Dziewoński 0dfb34eb50 Avoid parsing the comment snippet in notifications as wikitext
As it happens, most of Echo does not actually parse this message,
but it is for some reason parsed in HTML email notifications.

Change-Id: I414cd242d9bcc4d8b5a1c2a2a71be9e5f00ea8be
2021-06-03 02:43:56 +02:00
Bartosz Dziewoński fd080b7043 Ensure you can't get duplicate notifs for edits to your user talk page
We don't display [subscribe] buttons on your user talk page,
but the API still allows those subscriptions.

Use the same approach as for mentions to ensure this doesn't cause
duplicate notifications.

Remove some code in SubscribedNewCommentPresentationModel,
now guaranteed to be unused.

Change-Id: I99a276a48d8562552ed2c54cc0323e8e428845fd
2021-06-03 02:10:33 +02:00
Bartosz Dziewoński 4353b68646 EventDispatcher: Read revision IDs to compare from master
Bug: T284175
Change-Id: Iec99ea0afc659969108104cf5b2627856711544d
2021-06-02 19:47:35 +00:00
Ed Sanders 5a166cfab5 Notification unsubcribe button
Bug: T279150
Change-Id: Ib0bfe3c0dced2108bddbc837a7ddd7bea814e129
2021-06-01 23:29:53 +02:00
libraryupgrader 12fb65b9f1 build: Updating composer dependencies
* mediawiki/mediawiki-codesniffer: 35.0.0 → 36.0.0
* php-parallel-lint/php-parallel-lint: 1.2.0 → 1.3.0

Change-Id: I5c152292e83e7f3441e2c08b7d0ad23ac90f194b
2021-05-05 11:14:52 +00:00
Ed Sanders 2f40fd96b1 EventDispatcher: Store comment name in event metadata
This will probably be useful later, so better to ensure
the data is captured now.

Change-Id: I8936ee85a2775ad48839e9c3ebf5bc3d5355c501
2021-04-22 16:23:39 +00:00
Ed Sanders a9537782ac EventDispatcher: Compare new comments by name, not ID
Change-Id: I9d7907dda0f443e4e3b0463a127ea4def68051f3
2021-04-22 16:15:09 +00:00
Ed Sanders e20fcea122 EventDispatcher: Only generate events if author matches user
Bug: T280783
Change-Id: I8a0ea2ac3aefb66b693ee219b88619248bb25fb2
2021-04-22 16:14:01 +00:00
Ed Sanders f6c9508001 Create constants for feature strings
Change-Id: I2d7bf18faf6345a4816c2ebef9744c4e6f62cc40
2021-04-12 14:40:51 +00:00
Ed Sanders 23a490deca Topic subscriptions: Don't generate events when feature is unavailable
Bug: T279671
Change-Id: I8f57b2a1885619db868f25ea68208c2fad5fc040
2021-04-12 14:40:27 +00:00
Ed Sanders 6cafd7735d Topic subscriptions: Only check for events on talk pages
Change-Id: Ic2b7536baea58fb4868cec6f477e72bd8b717e3a
2021-04-12 14:40:13 +00:00
Ed Sanders 0a39c11914 Echo wiring for topic subscriptions
Depends-On: I60818d57552946857077dee93b0adb036621b791
Change-Id: I7e0996843cdd70141e19d5c7ce66122204efa1b7
2021-04-06 23:28:28 +02:00