Commit graph

361 commits

Author SHA1 Message Date
Bartosz Dziewoński 8de8d80cde Deal with document body consistently
Use `DOMCompat::getBody( ... )` as a nicer getter than
`->getElementsByTagName( 'body' )->item( 0 )`.

Remove overly defensive checks and redundant annotations on its
return value. Since we're dealing with HTML documents throughout,
the document body is guaranteed to exist.

We previously needed some of them to convince Phan when it thought
the body may be null, but this seems to no longer be needed.

Change-Id: If7aee7b6adbfa78269c7ba28b26a6eaa21fe935b
2021-08-03 15:12:55 +02:00
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
C. Scott Ananian 5203d30ea6 Use DOMCompat::newDocument() to create a new Document
For compatibility with Parsoid's document abstraction (Parsoid may
switch to an alternate DOM library in the future), don't explicitly
create a new document object using `new DOMDocument`; instead use
the Parsoid wrapper `DOMCompat::newDocument()`.  This ensures that
the Document object created will be compatible with Parsoid.

There are a number of other subtle dependencies on the PHP `dom`
extension in DiscussionTools, like explicit `instanceof` tests; those
will be tweaked in a follow-up patch
(I3c4f41c3819770f85d68157c9f690d650b7266a3) since they do not affect
correctness so long as Parsoid is aliasing Document to a subclass of
the built-in DOMDocument.  Similarly, the Phan warnings we suppress
do not cause runtime errors (because of the fixes included in
c5265341afd9efde6b54ba56dc009aab88eff83c) but phan will be happier
once the follow-up patch lands and aligns all the DOM types.

Bug: T287611
Depends-On: If0671255779571a91d3472a9d90d0f2d69dd1f7d
Change-Id: Ib98bd5b76de7a0d32a29840d1ce04379c72ef486
2021-07-30 18:15:11 -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 4ebe4b29bb Only show [subscribe] links on sections that contain at least one comment
Bug: T285796
Change-Id: I48264d55464fa6bce56b47fc1075f5d348101676
2021-07-13 02:35:15 +02: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
jenkins-bot f8f776d4e7 Merge "CommentFormatter: Remove old cached compatibility code" 2021-06-29 22:32:54 +00:00
David Lynch ae0aeff3a3 Allow dtenable=0 to disable DiscussionTools
Bug: T285578
Change-Id: Ic722285d51ea1a51593ab63fac516b4f992eb1c8
2021-06-29 21:20:35 +00:00
jenkins-bot b6b60bbe0b Merge "Config option to enable topic subscriptions backend and dtenable=1 URL parameter" 2021-06-29 15:21:09 +00:00
Bartosz Dziewoński a38eb4fe18 CommentFormatter: Remove old cached compatibility code
Added in 4bbfe6cb5d.

Change-Id: I4a6b265897beb60abc2a7c1e6bfc4acc646fda56
2021-06-24 15:38:02 +02:00
Bartosz Dziewoński 1517e2e094 Remove unused RL module
Unused since 6a24ceaeca.

Change-Id: I96c8a7d7f7527e86ed728e72eb7232406aeb6942
2021-06-15 12:34:18 +02: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
jenkins-bot ea98787f41 Merge "Apply transformations in ParserCache for all CommentFormatter features" 2021-06-01 19:24:04 +00:00
Ed Sanders 6a24ceaeca Subscribe/unsubscribe with plain text links
Bug: T279149
Bug: T279151
Change-Id: Ie7d46ea2e8d458fcdad4f91bb89ba038969f6b62
2021-06-01 20:37:47 +02:00
jenkins-bot ffcbce4f2d Merge "Pass whole context to internal action API requests" 2021-05-26 16:46:13 +00:00
jenkins-bot ef413b73e6 Merge "Limit number of topic subscriptions per user" 2021-05-26 13:01:06 +00:00
jenkins-bot 052573efe1 Merge "Use the edited page's title for magic words in API error messages" 2021-05-26 13:00:11 +00:00
Bartosz Dziewoński fffffe8f8f Pass whole context to internal action API requests
Otherwise, the global context is used (RequestContext::getMain()),
which is undesirable when you're building a rubegoldbergian
contraption and we're already inside an internal action API request
with a fake context.

Change-Id: I01daf8dc70b5751bc1e157fe598988cd5d3219e5
2021-05-26 12:55:33 +00:00
jenkins-bot 90528f2b49 Merge "Fix adding comments in lists containing <dt> tags" 2021-05-25 19:19:49 +00:00
jenkins-bot 86732c56dd Merge "modifier: Guard against infinite loop" 2021-05-25 19:17:53 +00:00
jenkins-bot 14035f3c7e Merge "Remove cookie hack for loading unavailable tools" 2021-05-25 19:17:19 +00:00
Bartosz Dziewoński ee524d6bd6 Remove cookie hack for loading unavailable tools
Bug: T277783
Change-Id: I521db842b4b7a98d8d255d418abd0ccb167c5aa0
2021-05-25 20:27:46 +02:00
Bartosz Dziewoński 6a50d1203c Limit number of topic subscriptions per user
Per Manuel Arostegui in T263817#7033384. The limit is 5000.
(I picked it arbitrarily, there's no real rationale for it.)

Also log a warning when any user reaches half of the limit,
so that we might make a decision about changing this mechanism
before it starts affecting users. Maybe at that time we'll
have data to show that it's safe to remove the limit.

Bug: T263817
Change-Id: I18a8ee0ad7383759229c5721d5253fb591457d4d
2021-05-25 17:16:24 +02:00
Bartosz Dziewoński 0ad1ee3cff Use the edited page's title for magic words in API error messages
Bug: T247661
Depends-On: Ic3d70efc23744ef6e90abc445f3babebf45c4697
Change-Id: I8b0ad22232ef14f59887c24d5727271f46350eb9
2021-05-21 18:03:56 +02:00
Timo Tijhof 54eb6691fa Allow talk pages to have a different ParserCache expiry
Using `updateCacheExpiry()` in this way appears to be established
with examples of other use in WMF production such as:
- CategortyTree extension:
  custom cache expiry for pages with `<categorytree>`.
- RSS extension:
  custom cache expiry for pages with `<rss>`.
- intersection extension:
  custom cache expiry for pages with `<DynamicPageList>`.
- Math extension:
  custom cache expiry if `<math>` failed.
- Wikibase extension, Flow extension:
  no caching for certain namespaces or content types.
- Graph extension, Kartographer extension:
  via onParserAfterParse hook, no caching if on preview.

Bug: T280605
Change-Id: Iea41ab8599ffae4622c97d682258b1b64eaf9ba2
2021-05-14 16:59:09 +00:00
Umherirrender 33f94693fb Replace uses of DB_MASTER with DB_PRIMARY
This requires MediaWiki version 1.36

Change-Id: Idc9edb06b2a080ea9d64e6cdac0b68eb14c485f9
2021-05-13 02:11:45 +02:00
jenkins-bot e1f472bf17 Merge "SubscriptionStore: Allow empty array to be passed to fetchSubscriptions" 2021-05-05 20:10:35 +00:00
Ed Sanders 11d40d2663 SubscriptionStore: Allow empty array to be passed to fetchSubscriptions
Change-Id: Ib2b659645ed55bc7a64f9971f0e054907c86a552
2021-05-05 19:16:54 +01: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 911f1a68bd Apply transformations in ParserCache for all CommentFormatter features
i.e. for topic subscriptions as well as the reply tool.

Change-Id: I0a9e1a15e5a11adce0e1c55481fef0f4549360a6
2021-05-03 15:05:35 +01:00
Bartosz Dziewoński 475aa80057 Fetch user's topic subscriptions on the page in a single query
Previously, we have made a query per each topic on the page.

Bug: T281000
Change-Id: I1029e62a65fc191ca37e1178ea7ffc55afafa1b9
2021-04-28 21:54:26 +00:00
Bartosz Dziewoński 49c1dde336 Abort DiscussionTools checks early when viewing a special page
Previously we relied on the NamespaceInfo check below to reject
special pages, but after commit 07d885248bc54bdc0f12d9745916c794d45ec81c
in MediaWiki core, PageProps throws an exception when called with a
special page.

Bug: T281180
Depends-On: I32c94107fde96b9d6344c77b621be9b3b9b7faaf
Change-Id: I0fd893c63a6e92f6c84e7aa92270852e1137fcad
2021-04-26 18:38:06 +00:00
Ed Sanders eae0c1e6e1 Implement hidden tag for source mode with toolbar
Bug: T279157
Change-Id: I0244530580c7243e4db33848d36c336d8e5e8a08
2021-04-22 17:44:00 +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
Bartosz Dziewoński ffd680ee7f Fix adding comments in lists containing <dt> tags
The issue occurred when replying to a comment consisting of multiple
list items, starting with a <dt> (instead of the expected <dd>), so
that the comment is considered to be unindented.

Modifier tried to add the reply directly inside the list (<dl>) rather
than inside the last list item (<dt>), which caused it to be confused
about indentation levels and try to un-indent more times than there
were indentations.

The simplest solution, given the existing code, is to add the reply
outside the list instead, in a new list. This results in a "list gap"
(<dl><dt>...</dt><dd>...</dd></dl><dl><dd>...</dd></dl>), but I think
it's acceptable for this rare case.

There are separate tests cases for old Parser and for Parsoid HTML,
because they parse the original wikitext differently (with the old
Parser producing HTML with a list gap too).

Bug: T279445
Change-Id: Ie0ee960e7090cf051ee547b480c980e9530eda51
2021-04-21 16:00:07 +02:00
Ed Sanders 888d554ecf Don't split parser cache when reply tool is enabled by default
Bug: T279864
Change-Id: I16f1546e1373311563b8a90d6a025b0b45ffb793
2021-04-21 11:57:37 +00:00
Ed Sanders 722a4e5198 Avoid splitting ParserCache on user language
Bug: T280295
Change-Id: I87eab83803d24c11db4d723377bf7b40390b2e70
2021-04-21 11:57:30 +00:00
Bartosz Dziewoński 0b82162149 CommentFormatter: Fix regexp in topic subscription postprocessing
The regexps needs to be non-greedy, otherwise it could swallow up a
large chunk of the page (up to the next comment).

I noticed this when adding tests for this code, in the 'unclosed-font'
test case (Ief9648b8805fadcc170c54b627eb669cc8b907b6).

Change-Id: I5f67a9599b0cb07bdd53abeebac9ada221181b66
2021-04-21 11:57:21 +00:00
Bartosz Dziewoński 228b81fab9 Move implementation of subscribe buttons to CommentFormatter
Change-Id: Iad59ea047ed12bb34b483a94f443b39de6985bd3
2021-04-21 11:57:17 +00:00
Bartosz Dziewoński 1957c340b9 Remove unused variable
Change-Id: Ia4ad464b765c67aea27092a161d28ad1d890e96a
2021-04-21 11:57:11 +00:00
jenkins-bot 69fc17db81 Merge "Rename CommentFormatter::addReplyLinks" 2021-04-21 11:50:42 +00:00