Commit graph

217 commits

Author SHA1 Message Date
Umherirrender eef833a112 Use namespaced classes
Changes to the use statements done automatically via script

Change-Id: Ife9826099657bcaeca1beec94863a1600fdf55f8
2024-10-19 23:39:18 +02:00
DLynch f96eba7e6e Revert "Invert logic on empty talk page"
This reverts commit 7e5f9b59a2.

Reason for revert: Causes empty state to always appear on wikis using Talkpageheader

Bug: T373100
Change-Id: I23a3f937201d93c7c7645a09c4fccfcf1c14008a
2024-08-22 17:48:33 +00:00
Arlo Breault 7e5f9b59a2 Invert logic on empty talk page
Record if a talk page is not empty, rather than empty.

This helps prevent Parsoid from mislabelling pages as empty when they
contain extension tags it needs to call out to the legacy parser to
process.  Metadata from the legacy parse is merged into the overall
metadata for the page.

For example, a templatestyles extension tag parsed in the context of a
talk page would set the empty state which would then fail to cleared if
the overall parse of the page wasn't empty.

Bartosz (@matmarex) proposed this idea in T371125#10053043

Setting and using these flags all appear to be post-retrieval from
cache.

Alternative to I1deb679ef0e19dc3a36e377c183dd1b4ab0003e9

Bug: T371125
Change-Id: I5c1877f7f9eb73f88a33e001ca3c2f3d06bb90e4
2024-08-14 18:26:25 -04:00
Bartosz Dziewoński eddf9bd997 tests: Normalize timestamp values returned by different database engines
Bug: T370671
Change-Id: Icfccbe7543e1bbcf6447a05c23c0dbfeac3df649
2024-07-22 20:21:50 +02:00
jenkins-bot d51585e02f Merge "Stop using setMwGlobals in tests" 2024-07-09 15:16:08 +00:00
jenkins-bot 80d1e3aa65 Merge "Use MainConfigNames constants in tests where possible" 2024-07-09 15:16:07 +00:00
thiemowmde 13d3a218b0 Use MainConfigNames constants in tests where possible
I believe this makes the code less brittle, and also makes it a bit
more obvious what these strings are meant to represent.

Change-Id: I01adaff0ed75f792d1130bbc75e7840b3d044c54
2024-07-09 14:16:24 +00:00
thiemowmde 6af3876b86 Stop using setMwGlobals in tests
In favor of the more recent, less error prone overrideConfigValue(s).

Change-Id: Ie3aa275f5d670c19d3f69467ed0b9383405f1440
2024-07-09 12:40:34 +02:00
Wandji69 43d023a2be Test: Replace db with getDb method
Bug: T316841
Change-Id: Iaf32040979522f311289b4c2f5723cae9079e662
2024-07-05 16:49:58 +01:00
Fomafix 32069364ff Use $this->getServiceContainer() in maintenance and tests
Use
	$this->getServiceContainer()
instead of
	MediaWikiServices::getInstance()
in maintenance and tests.

Change-Id: I4066d7b2029296f1edb164acc5f8c812ccfba808
2024-07-03 08:44:55 +00:00
jenkins-bot 5b415eb241 Merge "Reduce unused mocks in CommentFormatterTest" 2024-06-24 16:07:28 +00:00
thiemowmde 15a9304bc5 Reduce unused mocks in CommentFormatterTest
For example, in case nothing is ever called it's sometimes helpful to
use "NoOp" mocks to make this more visible.

There is also no actual OutputPage needed, just the much more narrow
interface.

Change-Id: I44522276726786abd75c85c02a7003c33a5602bb
2024-06-23 13:56:34 +00:00
jenkins-bot 7281eec5b2 Merge "Improve unwrapFragment() for multi-paragraph comments" 2024-06-22 09:48:56 +00:00
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
Bartosz Dziewoński 20ff1a519f Fix parsing usernames with +
urldecode() should be used for decoding URL query parameters,
rawurldecode() should be used for decoding URL paths.

Bug: T367977
Change-Id: I7a7b14da85fb89f612c701d2746803d830017842
2024-06-19 17:14:10 +02: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
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
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 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
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 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
Ed Sanders ab8ab5a6e4 Add tests for CommentFormatter:isLanguageRequiringReplyIcon
Change-Id: If0503c1280696bb4440062250e2208da8187364f
2023-12-04 12:47:46 +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
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
Ed Sanders 4447b6d201 Always pass whole OutputPage (as IContextSource) to postprocess functions
Change-Id: I07b312b8c00f9b5d20e285874ed0a0153949dd18
2023-10-09 15:41:28 +01:00
Kosta Harlan c6c7dd2fb0 overflow menu: Add hooks for registering and interacting with items
Why:

- We want to allow extensions to register interactive menu items in the
  overflow menu.

What:

- Create a PHP hook to allow extensions to provide menu items
  for rendering in the overflow menu
  - The hook allows for registering resource loader modules required by
    the menu item
  - The hook passes in some contextual information, like the thread
    item data, context source object, and if the page is editable
- Create a JS hook that fires when a user selects one of the menu items
- Example implementation: Ie9afbedb4f24cbd75eb48bb21dc9f6d8d732d853

Misc:

- Remove b/c code that existed to handle a transitional period where
  JSON encoded overflow menu data did not necessarily exist in the
  parser cache
- Rename code instances of ellipsis button / data / menu to refer to
  "overflow menu"
  - Some renames will have to wait until parser cache is updated; these
    are noted with TODOs

Bug: T342251
Change-Id: I5f2a51791f8ba7619d1399a4b93111e9bb44e172
2023-10-05 15:50:33 +01:00
Ed Sanders b63884f561 Turn comment timestamps into permalinks
Bug: T275729
Change-Id: Ica9cfd9743a67fce170e8b078016fa79bf6fbb84
2023-10-02 14:53:47 +01:00
Umherirrender fd0de6b09a Use namespaced Title
Bug: T321681
Change-Id: I66a498679d0743b7740887c636eca001efc170cd
2023-08-19 20:16:15 +02:00
Daimona Eaytoy ec41af6e8b Avoid DB access in non-database tests
Use mocks in CommentFormatterTest to avoid DB access, because the test
doesn't need it.

Add EventDispatcherTest to the Database group because it uses Parser,
whose DB access is hard to prevent.

Change-Id: Idfbf6c83a454f359e491e8c61e0629aad643d54f
2023-08-07 21:46:14 +02:00
Ed Sanders e389fc48f1 Always use === in PHP
Change-Id: I30ca7cdf73921dcae48997841816099972cdbed0
2023-07-26 14:29:40 +01:00
jenkins-bot 7b147cffbf Merge "ApiDiscussionToolsPageInfo: Allow excluding signatures" 2023-07-11 15:17:02 +00:00
Bartosz Dziewoński 43731ac2d6 ThreadItemStoreTest: Update workaround for T256006
Change-Id: Ib07d1a9817f28d1c43ef8e44a4ec4fd758d7c06c
2023-07-04 17:38:54 +02:00
thiemowmde 0cf68818a8 Add various, more specific type hints
* Add @var comments to untyped getService() calls so IDEs and tools
  are able to understand where the callers are.
* Use the more specific IReadableDatabase where possible.
* Fix missing import.

Change-Id: I9c1153cb9fe872227753628a947f40bd5ee447fa
2023-06-09 13:44:42 +02:00
Umherirrender 378769a974 Create HookRunner class and the hook handler interface
Bug: T273303
Change-Id: I6d00848f07fc7d17f3dc7f44b7b6b61553219558
2023-06-04 20:12:56 +02:00
Derick Alangi 6295079d77 phpunit: Use recent overrideConfigValues() over setMwGlobals()
Change-Id: I928dc450adb149e4a4a2260482b148c5cd1670c1
2023-06-02 10:37:15 +03:00
Bartosz Dziewoński 2d40cbb6d5 ApiDiscussionToolsPageInfo: Allow excluding signatures
Special:DiscussionToolsDebug falsely promised that the API delivers
the same information, but in fact the API included the signatures in
each comment's HTML unconditionally. Allow excluding them.

Change-Id: Ie1e38d28bed0b6d5713d9051b84cc08a23da94c2
2023-05-30 15:55:41 +02:00
Umherirrender 8b551618bb tests: Make PHPUnit data providers static
Initally used a new sniff with autofix (T333745)

Bug: T332865
Change-Id: I3b341ec4d14591e6265f86c5179b7dbff07d1076
2023-05-20 15:57:13 +02:00
jenkins-bot 4bcee681fc Merge "Make use of named MainConfigNames::… constants" 2023-05-19 13:23:17 +00:00
gerritbot 3f2cfa423b Update moved class RawMessage
See T321882. Moved in I195cf4c67bd514

Bug: T321681
Change-Id: I6c456405dc038fff7aa3124fdb4b9d6be0d0ffcb
2023-05-19 10:30:50 +00:00