Commit graph

491 commits

Author SHA1 Message Date
Bartosz Dziewoński 674353691b Improve unwrapFragment() for multi-paragraph comments
I've been reading some discussions in Special:DiscussionToolsDebug
and saw a good number of comments where the first paragraph has
a bullet point (`*`), and the following paragraphs are indented (`:`).

Change-Id: I1afadc49565e843c97286a3744941ffb4062ddec
2024-06-21 22:37:09 +02:00
Ed Sanders 6d572a8733 ESLint: Use sourceType:commonjs instead of no-implicit-globals:off
Change-Id: I409d24d7253bd2108d34fc5ec69f042f588b0b07
2024-06-14 12:32:25 +01:00
Umherirrender 3dc5e88842 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I492ddae3c3e9f81d551ea8b348b7148893f4f590
2024-06-09 00:02:35 +02:00
Ed Sanders dda9227947 ESLint: Manually fix remaining no-var violations
Change-Id: I4474bd0205e7a1ed8e60147e52675e3e0b93ccd9
2024-05-24 16:50:11 +01:00
Ed Sanders ca5157156a ESLint: Autofix no-var rule
Leave rule off for now as manual fixes are required.

Also temporarily disable prefer-const rule as that
will also require some manual fixes.

Change-Id: I8c3478f26f51287acb943bd38c9c1020c06b9f39
2024-05-24 16:49:36 +01:00
Ed Sanders 1e0aa2171f Replace $.extend with Object.assign
Change-Id: Id559ab68451a1d767e92ed17b1ef0832a5f243af
2024-05-02 16:49:43 +01:00
jenkins-bot 3c4b5364f2 Merge "Prefer short arrow functions" 2024-04-30 16:57:37 +00:00
Bartosz Dziewoński 67bad433dc Fix signature check not to look at the content of previous section
It needs to only look at the end of the added comments, and ignore
whatever is going on at the beginning, since the only thing it really
cares about is a functioning "Reply" button at the end.

Bug: T363285
Change-Id: Ia337be754deda741617d1343972f3e0a21c41b05
2024-04-25 23:15:18 +02:00
Bartosz Dziewoński 5def2227a2 Add more test cases for isSingleCommentSignedBy()
Inspired by the discussion at T363285, document some more intended
behaviors from 0ecc8a4c05.

Change-Id: Id190318a98563f4064c20477bc17e929dd59d74a
2024-04-25 22:09:40 +02:00
Bartosz Dziewoński d4c5aebd8f Prefer short arrow functions
When an arrow function body contains just a single `return` statement,
the braces can be omitted.

(Changes are mostly made by `grunt eslint --fix`, with only some line
breaks added by hand.)

Change-Id: I37f259f87085c8d20ed09cfa58a8456dd36cdc38
2024-04-20 00:08:51 +02:00
Ed Sanders a74c00ba8c Prefer arrow functions for callbacks
This allows us to remove our `this` bindings.

Change-Id: Ie8c8c38d36af8a033b5181870c39f8981a57b939
2024-04-19 12:34:23 +01:00
James D. Forrester 30d911b649 Replace wfGetDB() in test with $this->getDb()
Not spotted in code search due to wrong case, which PHP forgives.
Whoops.

Bug: T360991
Depends-On: I73e4d3ab3158659b6a3c0a942f6bef10820b4248
Change-Id: I2d1cfd0f05c962f2d62dde911e4b0eed1ca02d83
2024-03-26 12:01:16 +00:00
jenkins-bot f22dabfb80 Merge "Move some doc comments to real type hints" 2024-03-23 01:36:33 +00:00
jenkins-bot bd09ad6801 Merge "Move [subscribe] links outside of <h2> tags" 2024-03-11 17:07:14 +00:00
Bartosz Dziewoński d2d2d914ce Move some doc comments to real type hints
Change-Id: I64e3f7123c803ae2576c8b05824698d78a691018
2024-03-11 14:13:17 +01:00
Bartosz Dziewoński 69e8e948b2 Remove now redundant PHPDoc blocks
MediaWiki's PHPCS plugin requires documentation comments on all
methods, unless those methods are fully typed (all parameters and
return value).

It turns out that almost all of our methods are fully typed already.

Procedure:

1. Find: \*(\s*\*\s*(@param \??[\w\\]+(\|null)? &?\$\w+|@return \??[\w\\]+(\|null)?)\n)+\s*\*/
   Replace with: */
   This deletes type annotations, except those not representable
   as PHP type hints such as union types `a|b` or typed arrays `a[]`,
   or those with documentation beyond type hints, or those on
   functions with any other annotations.

2. Find: /\*\*/\n\s*
   Replace with nothing
   This deletes the remaining comments on methods that had no prose
   documentation.

3. Undo all changes that PHPCS complains about (those comments
   were not redundant)

4. Review the diff carefully, these regexps are imprecise :)

Change-Id: Ic82e8b23f2996f44951208dbd9cfb4c8e0738dac
2024-03-10 23:53:04 +00:00
Bartosz Dziewoński 9c9512ecf5 Move [subscribe] links outside of <h2> tags
Place the "[subscribe]" links used when the 'VISUALENHANCEMENTS'
feature is disabled in the same DOM position as the "🔔 Subscribe"
buttons used when it is enabled.

Recent changes in MediaWiki core caused them to move inside the
`<span class="mw-headline">`, breaking some gadgets (T13555#9615648).
Moving them all the way outside should avoid problems.

I don't remember why we placed them inside the `<h2>` tags, but there
doesn't seem to be any reason to do it now. It must have been easier
that way before we introduced the `<div class="mw-heading">` wrappers.

Note that I'm keeping the `<!--__DTSUBSCRIBELINK__...-->` placeholder
comments in case it turns out there is a reason, and we need to revert
this change. If everything goes well, they can be cleaned up in change
Ie3348671c486de5bbd9f286772a8d145e3609bd5 later.

Bug: T13555
Change-Id: Idb23b0f5e438d35ed74569ff50302c7fad5ba688
2024-03-08 21:18:53 +01:00
Bartosz Dziewoński 4958416caf Only include one set of DiscussionTools buttons in the page HTML
We no longer need to support toggling visual enhancements without
reloading the page, so we can remove the extraneous set of buttons
to reduce HTML size.

Bug: T322457
Change-Id: I54e57c754c54b7e611069f9832d1ebabf141a396
2024-03-01 16:51:17 +00:00
Bartosz Dziewoński 6419c19d1e Fix PHP getTitleFromUrl() when $wgArticlePath is '/$1'
In this case, the generated regexp would match the '/local' part in
the generated URL. Prefixing 'https://local' is no longer necessary
since 10899af666.

Add tests for this, and some tests to cover T261711 as well.

Bug: T358321
Change-Id: Idf54deba13f30b799b7b8d17de1897bc90f95701
2024-02-24 02:03:17 +01:00
Bartosz Dziewoński cf9f11167d CommentFormatterTest: Set ArticlePath in the test
Tests would fail if your wiki's config was different than this.

Change-Id: I148851a9d7b777f1fad5f17b01b835b0b9384a80
2024-02-24 01:19:16 +01:00
jenkins-bot 402f5de391 Merge "Support for core section heading formatting in post-cache transform" 2024-02-23 05:01:19 +00:00
jenkins-bot c12427f150 Merge "tests: Rebuild expected 'timestamplink' output" 2024-02-17 03:20:19 +00:00
Bartosz Dziewoński 08f61b2609 Support for core section heading formatting in post-cache transform
We already supported plain headings without the 'mw-headline'
wrappers, but now we need to parse the 'id' from a different
attribute.

Needed-By: If04d72f427ec3c3730e757cbb3ade8840c09f7d3
Bug: T357723
Change-Id: If85f89c40834618f23dc0ace2e599efb3b6d5ed4
2024-02-16 20:28:53 +00:00
Bartosz Dziewoński 7bee77d5fd Remove unused '*-formattedreply.html' test files
They were renamed in 9c68e058ef, but
b82af45735 accidentally added them back.

Change-Id: Ic0eaa09492d637f4dc54904856621ee1eb930a58
2024-02-16 19:28:05 +01:00
Bartosz Dziewoński 37257d68cf tests: Rebuild expected 'timestamplink' output
When rebuilding expected outputs by running the tests with
'DISCUSSIONTOOLS_OVERWRITE_TESTS=1', our code outputs the
JSON keys in a specific order (not alphabetical).

Change-Id: Ice57948ef1d4b780ae18cfcbb2e7373f518c8abc
2024-02-16 19:27:55 +01:00
Ed Sanders 9590a7297d CommentParser: Add test case for already-linked timestamp
Follow-up to 8069585489.

Bug: T356142
Change-Id: Iae9e165f00cc8bfedeb057f113e1c8c5ba7e3bf1
2024-02-12 20:33:06 +00:00
Bartosz Dziewoński f4090865d4 Add test cases for the main loop getting stuck on some signatures
Follow-up to 9db35873a4.

Bug: T356884
Change-Id: Ifef490209fdee2b9f52d3ef81a92ea20c5ff2155
2024-02-08 16:59:01 +01:00
Bartosz Dziewoński 0f6bdcf9cb Add first basic tests for ThreadItemStore::find*() methods
Just covering the basic scenarios of having comments on the page and
archiving them.

Bug: T356575
Change-Id: I9022b0a7cf3b02bd9f2f2d5605823eec21b92642
2024-02-03 23:14:08 +01:00
Umherirrender 94a5c86ceb Stop writing to tablesUsed in tests
Bug: T351733
Change-Id: I4e8feb7f60b45bb7fe5259d72ee29d964caefdfd
2024-01-20 12:27:39 +01:00
Umherirrender 6f487698cc tests: Fix tests when LiquidThreads is also installed
Change-Id: Ica43e90fb3e48ddd20ad2b4130fb3a5efb3a4696
2023-12-27 23:07:24 +01:00
Bartosz Dziewoński 6f92654137 CommentFormatter: Do not add wrapper if the heading has attributes
Bug: T353489
Change-Id: Idf49b40cd745b804dbad3c09960507790be20ae3
2023-12-20 16:56:12 +01:00
Bartosz Dziewoński 70022c4cee Avoid global state in tests involving CommentParser
Instead of setting global configuration variables, we create a custom
config object and all the other dependencies and pass them to the
CommentParser instead of the defaults.

Depends-On: I8d374b51511a2873dce646aa453c5e0e2c076a14
Change-Id: I9dfccc833d3e2695cf1d1f7bbee4b68eae9a8c25
2023-12-11 22:19:14 +01:00
Bartosz Dziewoński a27e27fc68 Move finding transclusion source from ContentThreadItem to CommentParser
Reasons:
* Various other methods dealing with ranges already live there
* It would be neat if ContentThreadItem was just a value class
  without a lot of logic, similar to DatabaseThreadItem,
  particularly for writing unit tests
* The methods access global state through Title, which can't
  be fixed while they're in ContentThreadItem (see I9dfccc83)

The computation is now always done, instead of only when needed,
but that's a small drawback, since it's fast (fast enough that
I don't see the difference in the time taken when running tests),
and we were already computing it for all comments in many places.

Change-Id: Ic718a964e309ae3a8e15e299081f46d4db860731
2023-12-11 22:18:30 +01:00
jenkins-bot ba7e8417a6 Merge "WikiImporter: Pass Authority for permissions instead of global context" 2023-12-11 19:49:59 +00:00
Umherirrender 64bcb583e9 Use namespaced classes
Done automatically via script
Change to extension.json done manually

Change-Id: Ied7bbddd357290ac6be6bf480be0ee9116e77365
2023-12-11 16:38:02 +01:00
Bartosz Dziewoński 855af15fba WikiImporter: Pass Authority for permissions instead of global context
Depends-On: Iea1d03dcdcbda2f9a9adbff1b0d319efd22c4d86
Change-Id: I4ec83fe0a887398a216e2b0392dfa852218fef1e
2023-12-08 22:16:16 +01:00
jenkins-bot d69dc24161 Merge "Ignore signatures with invalid timestamps" 2023-12-07 18:00:09 +00:00
Ed Sanders 4051c7faf4 Ignore signatures with invalid timestamps
Bug: T352455
Change-Id: Ie499db4594bfa23b618907383d0ac583849ff582
2023-12-05 13:23:15 +00:00
jenkins-bot c4d07f29d1 Merge "Add tests for CommentFormatter:isLanguageRequiringReplyIcon" 2023-12-04 21:02:37 +00:00
Ed Sanders ab8ab5a6e4 Add tests for CommentFormatter:isLanguageRequiringReplyIcon
Change-Id: If0503c1280696bb4440062250e2208da8187364f
2023-12-04 12:47:46 +00:00
Ed Sanders 584dc08020 Remove file headers and @copyright tags, not used consistently in this repo
Change-Id: I3c074c7cbae52d1775b14e1e6dae22c4276b8236
2023-12-04 12:30:56 +00:00
Ed Sanders f2f0ec2f65 build: Update linters and fix
Change-Id: Iec16f3330f94d38bb50492b7dcc9207786b964a4
2023-11-28 16:10:47 +00:00
jenkins-bot 048d5364e2 Merge "Replace preg_replace_callback with strtr in CommentParser" 2023-10-31 13:35:19 +00:00
thiemowmde 10dcd1f847 Replace preg_replace_callback with strtr in CommentParser
It does the same as before.

I think performance is not a concern here, and wasn't my motivation
either. But I hope this makes the code easier to read and to reason
with.

I added a pure unit test case (without involving an actual Language
object) to cover the previously uncovered digits feature.

Change-Id: I6a0fc86035817eabb42b55e58183ae094c052aa6
2023-10-31 08:55:40 +01:00
Ed Sanders c68081ada5 Remove old -ellipsisButton CSS class
Change-Id: I7e6fbcf6f81e9c94b7099824eaa94de34819bf70
2023-10-18 22:34:33 +01:00
Ed Sanders f8b76afef3 [BREAKING CHANGE] Remove isSectionEditable from overflow hook
Instead make isUneditableSection an optional property of
ContentHeadingItem.

Change-Id: Icfddf28aa789b5014ac183ff9f9699f38d78c121
2023-10-18 12:56:46 +01:00
jenkins-bot eca326ede5 Merge "Support ignoring "mw-notalk" before/after/between comments" 2023-10-13 17:44:20 +00:00
Kosta Harlan 7b336049d0
CommentFormatterTest: OutputPage returns a User, not UserIdentity
Why:

- Code that interacts with DiscussionTools CommentFormatterTest may
  expect a User object, instead of a UserIdentity, because OutputPage is
  typed to return a User object

What:

- Change the mock to return User, not UserIdentity

Change-Id: I1354f5f8132fd0656f274cdf4f17cde7f93d9042
2023-10-13 09:17:39 +02:00
Kosta Harlan ead2baf0f1 overflow menu: Only show edit button in mobile
Why:

- The button should only display for Minerva

What:

- Consult the skin name before adding the "Edit" button to the menu

Bug: T342251
Change-Id: I52cf2ca0663a4de0ee7add82910e745bcabf1c5f
2023-10-12 06:03:03 +00:00
Kosta Harlan 4c7ba1ba0e
CommentFormatterTest: Mock getConfig method
Why:

- Tests may invoke code that calls `getConfig` on the ContextSource

What:

- Mock the `getConfig` method

Follows-Up: I07b312b8c00f9b5d20e285874ed0a0153949dd18
Change-Id: I5c5b0d7cef24af108aeab461ba06b533eae4b739
2023-10-09 21:37:53 +02:00