Commit graph

69 commits

Author SHA1 Message Date
Bartosz Dziewoński af68c835bb Update exception handling for new code conventions
Change code to match the documented consensus formed on T321683:
https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#Exception_handling

* Do not directly throw Exception, Error or MWException
* Document checked exceptions with @throws
* Do not document unchecked exceptions

For this extension, I think it makes sense to consider DOMException an
unchecked exception too (in addition to the usual LogicException and
RuntimeException).

Depends-On: Id07e301c3f20afa135e5469ee234a27354485652
Depends-On: I869af06896b9757af18488b916211c5a41a8c563
Depends-On: I42d9b7465d1406a22ef1b3f6d8de426c60c90e2c
Change-Id: Ic9d9efd031a87fa5a93143f714f0adb20f0dd956
2023-01-22 18:17:11 +00:00
Bartosz Dziewoński 433e57394c Use PHP 7.4 property types
Change-Id: I788db64f0c0c00894d77256b7f016d44eda4bbb1
2022-10-28 21:56:38 +02:00
Sam Smith 50853a3db6 EventDispatcher: Remove reference to $wgWMESchemaEditAttemptStepOversample
At the time of writing, $wgWMESchemaEditAttemptStepOversample is not a
global variable in PHP [0].

[0] https://codesearch.wmcloud.org/search/?q=WMESchemaEditAttemptStepOversample

Bug: T312016
Change-Id: I6a8abceddc9fce2f28f7a154fa2fc566538ed5e8
2022-10-03 12:05:23 +01:00
jenkins-bot 2ce1822484 Merge "Use cheaper getRawVal/getCheck instead of getVal where possible" 2022-09-03 05:33:08 +00:00
Thiemo Kreuz 62ddb8bceb Use cheaper getRawVal/getCheck instead of getVal where possible
getVal/getText can be expensive because they do Unicode normalization.
We can skip this when we know we aren't going to do anything meaningful
with the value anyway.

Change-Id: I9d939a44df6b67bcd8429096d89600ce1566ca39
2022-09-03 05:27:20 +00:00
Bartosz Dziewoński d33996f8b4 Notify users when a topic they are subscribed to is removed from a page
In the future the notifications can be improved to look up
the new location of the comment, using the permalinks data.

Depends-On: Ia8a21749a8edc20f34b2a3e445278ea6922b9109
Bug: T299657
Change-Id: I5f5e7b73fb84ff0d31fb8260b24066a17da71628
2022-08-25 03:52:58 +02:00
Umherirrender 0a53b4d468 EventDispatcher: Remove use of UserFactory in logAddedComments
Possible since 1828d40

Change-Id: I0cc49a101858177bd9f7e75c18003277dd97725d
2022-08-05 01:43:16 +02:00
Bartosz Dziewoński 880f9755e0 Separate ContentThreadItem and DatabaseThreadItem etc.
Rename ThreadItem to ContentThreadItem, then create a new ThreadItem
interface containing only the methods that we'll be able to implement
using only the persistently stored data (no parsing), then create a
DatabaseThreadItem. Do the same for CommentItem and HeadingItem.

ThreadItemSet gets a similar treatment, but it's basically only for
Phan's type checking. (This is sad.)

Change-Id: I1633049befe8ec169753b82eb876459af1f63fe8
2022-07-04 23:35:50 +02:00
Reedy 54464f0b0c Add return type to jsonSerialize()
Bug: T311919
Change-Id: Ie77d7bc2902760972b8981a840bef91aae4ce5a3
2022-07-02 17:32:04 +00:00
Ed Sanders af54bae2ec Prefer late static binding over self::
While in many cases the class will never be sub-classed, it's easier
just to always use static:: and not worry about predicting which
classes might have problems in the future.

Change-Id: I23072a1701b5acf62bb3379a877de97627d8fcf3
2022-06-09 15:12:48 +01:00
Bartosz Dziewoński c7723baf72 CommentParser: Replace uses of Title with TitleValue
Another small step towards removing the reliance on global state.

Change-Id: Ifb4a5bcbef6606d02f1c7aa7385d72822cb0bad0
2022-03-18 18:24:34 +00:00
jenkins-bot 738e5461f8 Merge "Fix logic for finding the oldest comment in a bundle" 2022-03-08 02:23:57 +00:00
Ed Sanders 039d8e21e4 Fix logic for finding the oldest comment in a bundle
Follow-up to Ifba218871122901031a891034e709b886fc406da.

Bug: T302014
Change-Id: If1572a3ff13e922d86c0eca3d252cb196d329ea7
2022-03-08 02:13:54 +00:00
Reedy 524c8edf5c Use namespaced EventLogging class
Change-Id: Ic9f11b12edb5da08c2f4b31bea2a6517737ee6af
2022-03-06 16:10:40 +00:00
Ed Sanders dc8b4e8d4f Highlight all comments since the oldest in a thread bundle
For topic subscriptions, further restrict this to comments
in the same thread.

Bug: T302014
Change-Id: Ifba218871122901031a891034e709b886fc406da
2022-02-28 21:58:10 +00:00
Bartosz Dziewoński 8e44b43df0 Split off ThreadItemSet from CommentParser
Goal:
-----
Finishing the work from Iadb7757debe000025e52770ca51ebcf24ca8ee66
by changing CommentParser::parse() to return a data object, instead of
the whole parser.

Changes:
--------
ThreadItemSet.php:
ThreadItemSet.js:
* New data class to access the results of parsing a discussion. Most
  methods and properties are moved from CommentParser with no changes.

CommentParser.php:
Parser.js:
* parse() returns a new ThreadItemSet.
* Remove methods moved to ThreadItemSet.
* Placeholder headings are generated slightly differently, as we process
  things in a different order.
* Grouping threads and computing IDs/names is no longer lazy. We always
  needed IDs/names anyway.
* computeId() explicitly uses a ThreadItemSet to check the existing IDs
  when de-duplicating.

controller.js:
* Move the code for turning some nodes annotated by CommentFormatter
  into a ThreadItemSet (previously a Parser) from controller#init to
  ThreadItemSet.static.newFromAnnotatedNodes, and rewrite it to handle
  assigning parents/replies and recalculating legacy IDs more nicely.
* mw.dt.pageThreads is now a ThreadItemSet.

Change-Id: I49bfe019aa460651447fd383f73eafa9d7180a92
2022-02-21 16:22:32 +00:00
Bartosz Dziewoński 4613ae78e7 Change CommentParser into a service
Goal:
-----
To have a method like CommentParser::parse(), which just takes a node
to parse and a title and returns plain data, so that we don't need to
keep track of the config to construct a CommentParser object (the
required config like content language is provided by services) and
we don't need to keep that object around after parsing.

Changes:
--------
CommentParser.php:
* …is now a service. Constructor only takes services as arguments.
  The node and title are passed to a new parse() method.
* parse() should return plain data, but I split this part to a separate
  patch for ease of review: I49bfe019aa460651447fd383f73eafa9d7180a92.
* CommentParser still cheats and accesses global state in a few places,
  e.g. calling Title::makeTitleSafe or CommentUtils::getTitleFromUrl,
  so we can't turn its tests into true unit tests. This work is left
  for future commits.

LanguageData.php:
* …is now a service, instead of a static class.

Parser.js:
* …is not a real service, but it's changed to behave in a similar way.
  Constructor takes only the required config as argument,
  and node and title are instead passed to a new parse() method.

CommentParserTest.php:
parser.test.js:
* Can be simplified, now that we don't need a useless node and title
  to test internal methods that don't use them.

testUtils.js:
* Can be simplified, now that we don't need to override internal
  ResourceLoader stuff just to change the parser config.

Change-Id: Iadb7757debe000025e52770ca51ebcf24ca8ee66
2022-02-19 19:51:57 +01:00
Bartosz Dziewoński ae9f26a9e5 Various code quality tweaks
(suggested by PhpStorm)

composer.json:
* Document required PHP extensions

Parser.js:
* Remove incorrect param documentation
* Fix some typos in comments (missing parentheses)

CommentParser.php:
* Fix some typos in comments (missing parentheses)

ImmutableRange.php:
* Remove unused property
* Add a `throw` to indicate that code path is unreachable

SubscribedNewCommentPresentationModel.php:
* Add missing `return false`

CommentParserTest.php:
* Remove unnecessary pass-by-reference

CommentModifierTest.php:
* Remove unused variable

CommentParserTest.php:
* Don't construct Element objects directly. PHP's DOMElement allows
  it, but Parsoid/Dodo's doesn't, and we use the latter for static
  analysis. This generates all kinds of confusing warnings.

Change-Id: Ia9598ebea0e99830dd485296e94a9d96acc4b258
2022-02-19 19:36:52 +01:00
David Lynch d1e62d364d Log talk_page_edit events for adding a new topic
Bug: T301496
Change-Id: I618339f254c89db45891ee403f037c555afdda6e
2022-02-14 11:48:16 -06:00
Ed Sanders 6d655dee0a Remove DiscussionToolsEnableTopicSubscriptionBackend config
This is now deployed on all wikis, and going forward I don't think
we need to make this configurable.

Change-Id: I231976267ba6cdfeec622efaa15983a84c330649
2022-02-04 18:22:10 +00:00
Bartosz Dziewoński 5919e4e371 Don't try to parse section titles as wikitext in subscription notifs
Bug: T299572
Depends-On: Idb3a87fd18330f90a8cdc1276994d54288e17b28
Change-Id: I3b58f337bb2ea1f5255fc0a41dbd7a5ad8c433db
2022-01-21 00:12:58 +01:00
Bartosz Dziewoński d2405cc11c Simplify handling of sections in bundled notification links
This code previously ensured that the fragment identifier linking
to a section was only included if all events had the same section.
It doesn't actually seem worth the effort, since we handle scrolling
to the highlighted comments client-side anyway.

And the links were not quite correct, because we didn't parse and
strip the section title as expected by built-in Echo events. Just
use Echo's code for this.

Depends-On: Idb3a87fd18330f90a8cdc1276994d54288e17b28
Change-Id: Icae0d3654dd02109337ff8737b16f55bbd514f43
2022-01-21 00:06:36 +01:00
Ed Sanders 34011b7a07 Parser: Pass in title of page being parsed
Will be used to parse selflinks in the future.

Change-Id: I2bc29d1c5c69cb6309f582f162f9af7d96ce8913
2022-01-12 21:17:59 +00:00
Alexander Vorwerk 397dc2cea5 Replace usages of deprecated wfWikiID()
The global function wfWikiID() is deprecated since 1.35 and it's usages
should be replaced with WikiMap::getCurrentWikiId().

Bug: T298059
Change-Id: Ie878a5479b7427e9ffab7d7f92ee2802997e3161
2021-12-21 01:45:54 +00:00
Umherirrender d32dcfbb3c Use ParserOptions::newFromAnon instead of ParserOptions::newCanonical
ParserOptions::newCanonical is deprecated.

Change-Id: I26667c9102c37d962ceaa81c082566819b503744
2021-12-18 20:15:02 +01:00
Ed Sanders d2443f7785 Rename DiscussionToolsAutoTopicSubWhere to DiscussionToolsAutoTopicSubEditor
Better describes that we are checking the editor used to make
the edit, rather than descibing some virtual "location".

Change options to 'discussiontoolsapi' and 'any'.

Change-Id: I3024517e70ed61c738e4bf46a2ac7b58c975d98a
2021-12-15 16:24:35 +00:00
jenkins-bot 43c2a3204f Merge "Add 'legacyPrimary' links to API data for users without DT-enhanced HTML" 2021-12-10 18:03:23 +00:00
Bartosz Dziewoński a96c52869b Fix PageRecord lookup
According to Daniel it only worked by accident, and stopped working
after de63ad823abe:

getPageByReference() used to do an opportunistic lookup by ID when given
an instance of PageIdentity -- which is correct for EventDispatcher,
but problematic in the general case, causing T296063.

The correct thing to do here is to use getPageById(), since the canonical
association between revision and page is by page ID.

Bug: T297431
Change-Id: Icc1df0c9ca5345e65ef5f8daf0815013d7db0943
2021-12-10 12:46:55 +00:00
Ed Sanders dd896deb45 Add 'legacyPrimary' links to API data for users without DT-enhanced HTML
The 'legacyPrimary' links will take you to the section
the comment is in and should be used when you don't have
access to comment IDs.

Bug: T296018
Change-Id: I944feb90e7c3a69f81366f42fa110c58cac26dbb
2021-12-09 15:20:26 +00:00
Ed Sanders 8e4f08182e Add missing typehints
Change-Id: Ia25c5bea1834a3fdd26f32a9d5ed097789329824
2021-12-01 14:57:09 +00:00
David Lynch 17a3ac295e Fixes for talk_page_edit logging
* Add a N/A value for edit counts from anonymous users
* Only oversample with $wgDTSchemaEditAttemptStepOversample if the edit
  is from DiscussionTools
* Consider $wgWMESchemaEditAttemptStepOversample for oversampling

Bug: T286076
Bug: T295995
Depends-On: Ieb3f6c6e1775c1ef53747c37003b17e3634d1c44
Change-Id: I91245a61dfbde8b5ec9b2893b9170cc4d73f7b0a
2021-11-19 17:02:15 +00:00
Bartosz Dziewoński 8d3cf30f60 Automatic topic subscriptions (only for reply tool and new topic tool)
Bug: T284836
Change-Id: I0f98c26c997f66b7a43cd4b971fe72a37d12db5d
2021-11-15 22:45:42 +01:00
Bartosz Dziewoński 0d57aa9762 Automatic topic subscriptions (on any edit)
Bug: T284836
Change-Id: Ia42ad087218fd91a0cdd1664157d1049738e3c01
2021-11-15 22:45:42 +01:00
Ed Sanders 0fba9b0048 Suppress events from comments that are more than 10 minutes old
Bug: T290803
Change-Id: Ic0e23f439eef8a1b785f408d4557bec0abe9104b
2021-11-09 16:37:46 +00:00
David Lynch df47f9fda3 Logging for new comments
Bug: T286076
Change-Id: Ic78a49aedcb03d160d74ba3fa9660f3583f0e568
2021-10-28 21:50:23 +00:00
jenkins-bot abd6c2fedd Merge "Enhance Echo user talk edit and mention notifications" 2021-09-24 02:17:57 +00:00
Bartosz Dziewoński 435b0c65c7 Enhance Echo user talk edit and mention notifications
If the user talk edit or mention coincides with exactly one new comment:
* Change the primary link to be a direct link to the comment
* Add a text snippet to notifications that don't already include one
  (user talk edits that are not new sections).

This is done for all such notifications, regardless of whether anyone
has topic subscriptions enabled.

Bug: T281590
Bug: T253082
Change-Id: I98fbca8e57845cd7c82ad533c393db953e4e5643
2021-09-20 15:05:42 +02:00
Bartosz Dziewoński 0ae97ef550 Deduplicate logic for subscribable headings
Change-Id: I1cd96cf0bcce2101455702f1350d8a4336c60790
2021-09-07 21:38:35 +00:00
Bartosz Dziewoński 4bbbdc9703 EventDispatcher: Try really, really hard to read from master
Follow-up to 37d6825c14.

Bug: T289717
Depends-On: I2a614915c7d9ffbc4f466204b2684478fb52f30e
Change-Id: Id2e040a19e457a2a8f4121b04ebd43bf6ea64181
2021-08-25 21:38:10 +02:00
Bartosz Dziewoński bcd92a5d33 Minor cleanups in topic subscription code
For automatic topic subscriptions, I plan to introduce a third
subscription state to indicate them. This patch includes minor tweaks
I wanted to add while working on that:

* Introduce constants instead of numbers
* Remove a TODO that doesn't seem like a good idea any more
* Remove a `"length": 1` on sub_state that did not do anything
  (but it might have been meant to indicate that it was supposed
  to be a boolean, which would be wrong)

Bug: T284836
Change-Id: I6e6096968ad38510102287bccd349090b6ca4280
2021-08-17 22:22:15 +02:00
jenkins-bot 781992de2d Merge "Create a hidden revision tag for talk page comments" 2021-08-17 02:07:10 +00:00
jenkins-bot e090c455cc Merge "EventDispatcher: Fix ignoring level 3+ headings" 2021-08-16 22:08:42 +00:00
jenkins-bot 2cd97c4be5 Merge "Handle highlighting and scrolling to comments for bundled notifications" 2021-08-16 20:43:37 +00:00
Bartosz Dziewoński db28a3d3a7 Handle highlighting and scrolling to comments for bundled notifications
Notifications are bundled by section, so instead of linking to the
comment, link to the section.

Additionally, add a parameter to the URL listing all the comment IDs
from the bundle, and highlight them all and scroll to the topmost one.

Having to handle both URL fragments and URL query parameters makes
this code kind of a mess :(

Also, some unexpected changes became necessary:

* EventDispatcher.php: Store the section title in events using
  HeadingItem::getLinkableTitle() instead of ThreadItem::getText().
  The result is mostly the same, except in case of wacky markup like
  images or extension tags. We can more reliably use it to link to the
  section on the page, and we already use getLinkableTitle() when
  generating edit summaries in the reply tool for this reason.

* dt.init.less: Change the mix-blend-mode for the highlights from
  'multiply' to 'darken', so that multiple overlapping highlights do
  not look more opaque. This affects how the highlights look on
  non-white backgrounds and images (they're less blue, and on darker
  backgrounds entirely invisible), but it seems worth it.

Bug: T286620
Change-Id: I21bb5c003abc2747f0350d3f3af558dfb55693e9
2021-08-16 22:03:30 +02:00
Bartosz Dziewoński ad04b24ffd Create a hidden revision tag for talk page comments
Bug: T262107
Depends-On: I21159d03eebaf46ad94f4273ba698a59b8019185
Change-Id: Iceddfaf6a4bcc5e8b5c85c8cd5638bf14aa7db03
2021-08-16 15:42:51 +00:00
Bartosz Dziewoński 47510a22f3 EventDispatcher: Fix ignoring level 3+ headings
The code (prior to d25825a754) assumed
that level 3+ headings would always follow a level 2 heading or the
placeholder heading, but we don't generate a placeholder heading if
there are no comments in section zero.

Add more tests to confirm that comments under level 3+ headings (that
are not sub-headings of level 2), and level 1 headings, are ignored
when generating notifications, and do not mess with normal headings.

Bug: T288775
Change-Id: Ic57b56752a4797cb01234f66e0ed7b849752bd70
2021-08-16 15:42:06 +00:00
Bartosz Dziewoński d25825a754 EventDispatcher: Remove failing invariant check
To be investigated in the future.

Bug: T288775
Change-Id: Ic27418a0ec976347be5fa586bbd32cc4a0d8d511
2021-08-12 22:37:51 +02:00
jenkins-bot 10c23d0eb1 Merge "Deal with document body consistently" 2021-08-06 03:08:28 +00:00
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
Bartosz Dziewoński a5099739a6 Improve notifications for comments posted in close succession
In case 4 and case 6, no notifications are expected. In all other
cases we now get the expected notifications.

Bug: T285528
Change-Id: I9e813bb3a053bc1232783f9eae1ad75672b4fa7e
2021-08-01 12:27:33 +02:00