Commit graph

788 commits

Author SHA1 Message Date
Umherirrender c3af3157b4 Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: I48fcc02c61d423c9c5111ae545634fdc5c5cc710
2024-06-12 20:01:35 +02:00
STran f5d7b68908 Force full evaluation of filter in FilterEvaluator->getUsedVars()
In some cases, evaluation short-circuits when getting a list of
used variables resulting in an incomplete array of variables. This
subsequently causes issues when using those arrays for validation
checks (eg. if protected variables are used).

- Force full evaluation by setting `mAllowShort` to false

Bug: T364485
Change-Id: Idf2112d9ebf63846cde3ce9b8a8ade0ed909505d
2024-06-11 02:43:47 -07:00
Matěj Suchánek 469d643530 Drop af_user(_text) and afh_user(_text) fields
They have been migrated to their respective _actor counterparts.

Bug: T188180
Change-Id: I76ab3a4eeaf93bf009ba3a5d4a0315443b6839ef
2024-06-10 18:48:21 +02:00
jenkins-bot a5afeff49c Merge "Drop $wgAbuseFilterActorTableSchemaMigrationStage" 2024-06-10 13:27:07 +00:00
Matěj Suchánek c2da0d4857 Drop $wgAbuseFilterActorTableSchemaMigrationStage
First patch in a series of dropping the old columns.
Wikis now need to run the maintenance script (e.g., via
update.php) prior to serving this commit.

Wikimedia wikis are already on SCHEMA_COMPAT_NEW stage.

Bug: T188180
Change-Id: I86ec2b816eed17b62bf02bfd085570f132011b3e
2024-06-10 12:08:30 +00:00
STran 1c96981117 Clarify protected status in filter checkboxes
The UI/UX for acknowledging a filter will be protected/is protected
could be clearer. The checkbox implemented currently doesn't make
it clear that the acknowledgement is mandatory and filters that are
already protected allow for the checkbox to be unchecked even though
that doesn't reflect that the filter cannot be unprotected.

- Update copy for the protected filter acknowledgement to make it clear
  that it's a mandatory acknowledgement, not an optional one
- Update copy for the error that shows when a filter that should be
  protected doesn't have the acknowledgement checked
- When a filter is already protected, disable the acknowledgement
  checkbox to indicate this is not mutable

Bug: T364485
Change-Id: I667fcca4511dff1ac3ca69930c5b5e5eb5001787
2024-06-06 00:23:39 -07:00
jenkins-bot 3897096fd7 Merge "Implement 'protected' filter acknowledgement checkbox" 2024-06-05 13:42:33 +00:00
STran 69a28f7f03 Implement 'protected' filter acknowledgement checkbox
- Add a basic checkbox on the filter edit page that must be checked if a
  filter uses a protected variable to ensure that the user is aware that
  their filter will also become protected

Bug: T364485
Change-Id: I7c7652f7d1a81223229b839ff7eee5da4af74c8a
2024-06-05 05:43:25 -07:00
jenkins-bot 4e14afa6fb Merge "Allow variables to be restricted by user right" 2024-06-04 17:20:17 +00:00
STran bf28dbce0e Allow variables to be restricted by user right
Some exposed variables (eg. `user_ip`) used in filters are sensitive
and need to only be available to restricted groups of users.

Back-end changes:
- Add `AbuseFilterProtectedVariables` which defines what variables are
  protected by the new right `abusefilter-access-protected-vars`
- Add the concept of a `protected` variable, the use of which will
  denote the entire filter as protected via a flag on `af_hidden`

New UX features:
- Display changes to the protected status of filters on history and diff
  pages
- Check for protected variables and the right to see them in filter
  validation and don't allow a filter to be saved if it uses a variable
  that the user doesn't have access to
- Check for the right to view protected variables before allowing access
  and edits to existing filters that use them

Bug: T364465
Bug: T363906
Change-Id: I828bbb4015e87040f69a8e10c7888273c4f24dd3
2024-06-04 06:54:53 -07:00
libraryupgrader efa5460918 build: Updating npm dependencies
* eslint-config-wikimedia: 0.27.0 → 0.28.0
* grunt-stylelint: 0.19.0 → 0.20.0
* stylelint-config-wikimedia: 0.16.1 → 0.17.0

Change-Id: I7a36d9db97da9274f6b81097beb0cbf089022043
2024-06-04 00:33:18 +00:00
jenkins-bot 10663ed4fd Merge "Convert af_hidden into a bitmask" 2024-05-30 18:11:24 +00:00
Bartosz Dziewoński 94251ca97e Use StatusValue::getMessages() instead of deprecated methods
Added in MediaWiki in Ibc4ce11594cf36ce7b2495d2636ee080d3443b04.

Change-Id: I0b51f1210b9501961586fa25bf1f49bc68bab3d1
2024-05-28 21:04:59 +00:00
STran ca23e9f06b Convert af_hidden into a bitmask
Protected variables will cause the filter using them to become
protected as well. `af_hidden` can be used to track this flag,
as it is a TINYINT and can be converted into a bitmask with no
schema changes.

This is not a backwards-compatible change, as now all checks must
check the `hidden` flag specifically or otherwise will be cast to
true if any flag is set.

To support this change:
- "hidden" is considered a flag set in the `af_hidden`. This is a
  change in concept with no need for updates to the column values,
  as there is currently only one flag in the bitmask.
- `Flag`s store the bitmask as well as the state of single flags
  and can return either.
- Any checks against the `af_hidden` value no longer check a
  boolean value and instead now check the `hidden` flag value.

Bug: T363906
Change-Id: I358205cb1119cf1e4004892c37e36e0c0a864f37
2024-05-28 00:59:08 -07:00
jenkins-bot 58c5edce98 Merge "Add user_unnamed_ip variable" 2024-05-23 18:10:52 +00:00
STran fe0b1cb9e9 Add user_unnamed_ip variable
After temporary accounts are enabled, filters that rely on an ip
in the `user_name` will fail (eg. `ip_in_range` and `ip_in_ranges`).
To keep these filters working:

- Expose the IP through another variable, `user_unnamed_ip`, that can be
  used instead of `user_name`.
- The variable is scoped to only reveal the IPs of temporary accounts
  and un-logged in users.
- Wikis that don't have temporary accounts enabled will be able to see
  this variable but it won't provide information that `user_name`
  wasn't already providing
- Introduce the concept of transforming variable values before writing
  to the blob store and after retrieval, as IPs need to be deleted from
  the logs eventually and can't be stored as-is in the amend-only blob
  store

Bug: T357772
Change-Id: I8c11e06ccb9e78b9a991e033fe43f5dded8f7bb2
2024-05-23 07:19:48 -07:00
Kosta Harlan cd24c0ba2a
RCVariableGeneratorTest: Handle anonymous user test with temp accounts enabled
Why:

- Temp accounts will be enabled by default in CI, eventually. For tests
  that verify anonymous user editing behavior, we need to disable the
  temp user feature

What:

- Check if the user identity isn't registered, and if so, disable auto
  creating a temp user

Bug: T365645
Change-Id: I477fb6b44655e4190b5906c85390133e3e3a9feb
2024-05-23 09:41:05 +02:00
jenkins-bot ecf3268789 Merge "Provide integration with ConfirmEdit to show CAPTCHA" 2024-05-13 10:25:44 +00:00
Kosta Harlan f948c79066
Provide integration with ConfirmEdit to show CAPTCHA
Why:

- We want AbuseFilter to able to require a CAPTCHA if an action
  matches conditions in an AbuseFilter

What:

- Implement the ConfirmEditTriggersCaptcha hook, and check to see if
  the CaptchaConsequence set a global flag that indicates if we
  should show a CAPTCHA

Depends-On: Ie87e3d850541c7dc44aaeb6b30489a32a0c8cc60
Bug: T20110
Change-Id: I110a5f5321649dcf85993a0c209ab70b9886057c
2024-05-10 21:00:47 +02:00
xtex bc6240fbda
Replace some deprecated functions
Change-Id: I4070a3655f2fac1d7afe1c3a244a64cb55019b9a
2024-05-04 21:32:04 +08:00
jenkins-bot eb1db27c77 Merge "Clean up ActionVariablesIntegrationTest" 2024-05-03 07:16:12 +00:00
Umherirrender 06ccd0c0b8 tests: Use IDatabase for mocking instead of DBConnRef
DBConnRef is internal, use of IDatabase interface is more common

Change-Id: Ib14496dd4e5c02bb80a1e7f43e9489d5c22bda39
2024-05-02 22:32:05 +02:00
Matěj Suchánek 7f3ded3004 Clean up ActionVariablesIntegrationTest
Change-Id: Ia9ad89b699dac351e6b14a3d33dc0ceea7ed74b3
2024-05-01 16:22:15 +02:00
Umherirrender 6dccb17255 Migrate to IReadableDatabase::newSelectQueryBuilder
Also use expression builder to avoid raw sql

Bug: T312420
Change-Id: I83eb39f1c65a698108ae5bb72f633afda37a9f23
2024-04-30 20:45:51 +02:00
jenkins-bot 0038f18b9b Merge "Migrate to IDatabase::newUpdateQueryBuilder" 2024-04-20 20:40:53 +00:00
Umherirrender 6c870529e4 tests: Return FakeResultWrapper from mocked IReadableDatabase::select
To match the return type documentation of IReadableDatabase::select

Change-Id: I6a03c9468aa23f830f550e83eebf734ba0167c23
2024-04-19 21:20:07 +02:00
Timo Tijhof 4743f9d267 tests: Widen @covers tags in phpunit tests
Follows-up I5a5420df13893386.

> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
>
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".
>
> Given all used methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, this
> maintains the spirit and intent. PHPUnit offers a more precise
> tool when you need it (i.e. when testing legacy monster classes),
> but for well-written code, the class-wide tag suffices.

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: If7304d8b5b43ab8a051fbcecced331a787bab960
2024-04-17 01:44:40 +01:00
Umherirrender 3691d773d3 Migrate to IDatabase::newUpdateQueryBuilder
Change-Id: I0b3fd864e5227068114ca7aa9e98361046f393c1
2024-04-15 23:07:44 +02:00
jenkins-bot f17f231a70 Merge "tests: Widen @covers tags in SpecsTest" 2024-04-15 16:56:57 +00:00
jenkins-bot 1807a07755 Merge "Remove small pieces of unused code from SpecsFormatterTest" 2024-04-15 16:02:31 +00:00
Timo Tijhof 56c0f6313e tests: Widen @covers tags in SpecsTest
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
>
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".
>
> Given all used methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, this
> maintains the spirit and intent. PHPUnit offers a more precise
> tool when you need it (i.e. when testing legacy monster classes),
> but for well-written code, the class-wide tag suffices.

Ref https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

Change-Id: I5a5420df1389338644a099ebfd072063653e6849
2024-04-15 16:36:36 +01:00
jenkins-bot be54bef5d8 Merge "Clean up injection of DatabaseBlockStore" 2024-04-15 04:01:23 +00:00
jenkins-bot 5c61521cbb Merge "Migrate to IDatabase::newInsertQueryBuilder/newDeleteQueryBuilder" 2024-04-14 18:28:13 +00:00
jenkins-bot bd2e33e3e5 Merge "Replace array_merge in tests with the [ ... ] syntax" 2024-04-12 09:32:57 +00:00
Matěj Suchánek ad2600b6c0 Clean up injection of DatabaseBlockStore
The static method has already been migrated.

Also rewrite the test cases to avoid non-static provider (T337144).

Change-Id: Ibf98539f442e1ba8a9e9eb510784d40778123f17
2024-04-12 11:01:00 +02:00
thiemowmde 07a04b74d7 Remove small pieces of unused code from SpecsFormatterTest
Change-Id: Ifbef4f3c73b5744dd1ead9df1743631753bd306a
2024-04-12 08:37:00 +00:00
thiemowmde 0b0fab9d1b Fix wrong getMockMessage() calls in tests
MessageLocalizer::msg( $key, ...$params ) accepts a variable number
of arguments, but getMockMessage does not. Passing only the first
argument as a string to getMockMessage is not supported.

Required for I86ff2d6.

Change-Id: I30ab799ceab36b80c330d1233f3009814d7f6c98
2024-04-11 15:32:17 +00:00
thiemowmde 7f214ec15c Replace array_merge in tests with the [ ... ] syntax
It does the same and is well supported in the PHP versions we
currently use, at least when the arrays contain integer keys.

Change-Id: Id038142621dab47bfc03db48ce676ed0b2cdc28b
2024-04-11 14:01:25 +02:00
Matěj Suchánek 68ff668543 Add new variable for last edit time
Bug: T269769
Change-Id: Ia41ecc2f8e6921ef3d5a16fec58202d584ad0727
2024-04-10 23:12:45 +00:00
Umherirrender 2df93d2b0f Migrate to IDatabase::newInsertQueryBuilder/newDeleteQueryBuilder
InsertQueryBuilder does not ignore insert of no rows,
adding some conditions to avoid calling the query builder

Change-Id: I1752b90cc3a7ec3a7f9ee32a1873bf8c82b6e02e
2024-04-02 21:15:40 +02:00
Timo Tijhof 473b4b1ec4 tests: Remove redundant wgMainCacheType=hash
Introduced in 2019 with 4c8dac4dc6. Redundant since 2020 with
commit c6c62e2c8f in MediaWiki core.

Bug: T139216
Change-Id: I51e9fc3899cf5505917d7899a395350dd86f5c0b
2024-03-29 15:37:58 -07:00
Matěj Suchánek 4c2b09fa4e Replace deprecated ChangeTags method calls with ChangeTagStore
Bug: T360664
Change-Id: Icd7c38be9a8b54c29da7d33dfa9691e1c94feeb1
2024-03-29 11:08:41 +01:00
jenkins-bot 430b7f81ad Merge "FilterLookup: Stop using DBAccessObjectUtils::getDBOptions()" 2024-03-25 18:20:52 +00:00
Amir Sarabadani fe0fed1d8f FilterLookup: Stop using DBAccessObjectUtils::getDBOptions()
And more db clean ups:
 - Use QueryBuilders
 - Stop relying on actor migration to simplify query building
 - Using expression builder in one case.
 - Change the default actor migration stage to read new and write both.

Bug: T354194
Depends-On: I7c116cab0c748707d9a9fd17feeffe26e7d188ec
Depends-On: I74002911749335f4323a03fb430d02f936771b7e
Change-Id: Id84d1db7a2991f3cccc2f4f1502ba77643ddef24
2024-03-21 20:22:02 +01:00
libraryupgrader a8c9fab2cc build: Updating mediawiki/mediawiki-codesniffer to 43.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.MissingDocumentationPublic

Change-Id: I6075c76d53a899aac56af027f9a956a6b9e6a667
2024-03-16 18:53:05 +00:00
Dreamy Jazz 85022190e5 Add user_type variable
Why:
* An AbuseFilter variable is needed that allows filters to determine
  what type the current user is. That is, whether the user is an
  IP address, temporary account, named user or external user.
* Currently filters implement this by inspecting the value in
  the 'user_name' variable, but this is likely to break when
  temporary accounts are enabled as IPs would be hidden.
* Giving a dedicated variable that indicates the type of the user
  allows filters to work out this information without having to
  know the specific username of the user before performing the
  check.

What:
* Add the 'user_type' variable which is lazily computed. It can have
  the value 'named', 'temp', 'ip' or 'external' depending on the
  type of the user. If the user does not match any of these, then
  the value is 'unknown'.
* Replace call to deprecated User::newFromIdentity with a use of the
  UserFactory service that is dependency injected.
* Add and update tests to ensure consistent test coverage.

Bug: T357615
Change-Id: Ifffa891879e7e49d2430a0330116b34c5a03049d
2024-03-07 10:38:25 +00:00
Derick Alangi 82d876ada8 Handlers: Drop AutoPromoteGroupsHandler::factory()
This patch solves a pending TODO which is to remove the ::factory()
method from the AutoPromoteGroupsHandler class. If the cache instance
is injected, we'll use it otherwise we'll default to a HashBagOStuff.

Bug: T358346
Change-Id: I2bc414da8733431d1d11025e954282fc7c73aa80
2024-03-06 21:38:12 +00:00
Dreamy Jazz f4e3f78b7e Add integration test to verify logs are saved in CheckUser
Why:
* In f3c87749b8, the sending of logs
  to CheckUser when using a temporary account was fixed. As part
  of that change, it was suggested to add a test to verify that
  the call to `Hooks::updateCheckUserData` actually causes an
  insert into the relevant CheckUser result table.
* This change adds this test as a follow-up.

What:
* Create a test for the AbuseLogger that verifies that an event is
  sent to CheckUser and is saved into the DB for an abuse filter
  hit. This test is only run if the CheckUser extension is installed.

Bug: T358632
Change-Id: I33ed0810db13e38eacf4e682eb54d4ffcd583084
2024-03-01 16:11:33 +00:00
Derick Alangi e1f78da351
Fix wrong namespacing of integration test using \Unit\
Change-Id: Idcafe1dd97951db41b78c2a1c54d8519ae8802b7
2024-02-23 15:55:47 +03:00
Reedy 66ee91e6c6 Remove usage of writeapi userright
Bug: T294397
Depends-On: Ifad2edc782b36d21c8c67fecde7f011dce02c11b
Change-Id: I9c8d384742450ab19da4ad8b172310b0df928d32
2024-02-15 20:42:57 +00:00
James D. Forrester 607ebb965c build: Upgrade eslint-config-wikimedia from 0.25.1 to 0.26.0
LibUp was getting caught out by the false-positive hit to
es-x/no-resizable-and-growable-arraybuffers, so doing a
manual fix to make progress.

Otherwise just whitespace changes.

Change-Id: Ibf20dd2d88613b0a74813c33239e7d0bac682b17
2024-02-06 09:26:59 -05:00
Dreamy Jazz a5b68cf46d Don't attempt to steal or create the FilterUser in CheckUserHandler
Why:
* When CheckUser asks the AbuseFilter extension for modifications
  to rows inserted into the CheckUser tables, the AbuseFilter
  extension attempts to get the Filter user via User::newSystemUser
* User::newSystemUser can deadlock if multiple requests to create
  the system user are being made at once.
* The CheckUserHander does not need to create the abuse filter system
  and instead only needs to know if a given $user is the equal to
  the FilterUser.
* As such the FilterUser service needs to provide a way to check if
  a given $user is equal without creating the FilterUser.

What:
* Add FilterUser::isUserSameAs which returns a boolean value
  indicating whether the Abuse Filter system user is the equal
  to a given UserIdentity in the same way that UserIdentity::equals
  is implemented.
* Refactor ::getUser to get the username for the filter user in
  a separate method, so that the ::isUserSameAs method can also
  use this method. Name this new method ::getFilterUserName.
* Add a test for the FilterUser service to ensure consistent test
  coverage
* Convert the @covers and @coversDefaultClass annotations to be
  a @covers for the class. This is because PHPUnit recommends this in
  https://docs.phpunit.de/en/9.6/annotations.html#appendixes-annotations-covers-tables-annotations

Bug: T356275
Bug: T346967
Change-Id: I8a101781bb47612deabb0f2a06a398ac13e860e6
2024-01-31 19:32:52 +00:00
gerritbot 71c181219a Remove indirect calls to IDBAccessObject::READ_* constants
We are getting rid of the schema of implementing this interface and
calling self::READ_* constants, it's confusing, inconsistent, prone to
clashes and isn't really useful for non-ORM systems (which we are not)

Bug: T354194
Change-Id: I5d7a2c91a49311a6bdf6e56053c08610d4d6d110
2024-01-26 09:25:35 -05:00
Novem Linguae 0d33825853 Remove $this->tablesUsed from PHPUnit tests
Deprecated in T342301 in v1.41. This is now tracked
automatically. The variable can be safely deleted.

Change-Id: I7f42f3bfc58508421f4758089482fd1ed68c42c2
2024-01-14 04:45:29 -08:00
Taavi Väänänen 80a8764c8d
ActionVariablesIntegrationTest: Support JsonContent using tabs
Bug: T326065
Change-Id: I67c87484ea4ec23f703480c8d423b800c74f6518
2024-01-02 23:42:23 +02:00
Umherirrender bd84a6514c Use namespaced classes
This requires 1.42 for some new names

Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ic1e2c9a0c891382744e4792bba1effece48e53f3
2023-12-10 23:03:12 +01:00
jenkins-bot 22435fe600 Merge "Replace BadMethodCallException with LogicException" 2023-11-19 13:03:56 +00:00
thiemowmde 2def63118e Replace BadMethodCallException with LogicException
The BadMethodCallException is documented as "thrown if a callback
refers to an undefined method or if some arguments are missing".
This is not what happens in these places.

Change-Id: Ic95b67acc2e17eea1dd0fa1d72f9ac94a86bcf17
2023-11-16 19:10:50 +00:00
thiemowmde 71170d6db1 Fix typo "Builer" → "Builder"
This luckily doesn't appear anywhere else:
https://codesearch.wmcloud.org/search/?q=EditBoxBuiler

Change-Id: I8238015b10cc729a2df7b56be7e3eb5140f8a070
2023-11-16 20:00:41 +01:00
Timo Tijhof 09438fd015 phpunit: Avoid hardcoding exact mw-parser-output class attribute
Needed by Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7.

Bug: T341244
Change-Id: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
2023-10-19 19:02:21 -07:00
thiemowmde 8565b8d7c4 Use assertStatusGood and such from MediaWiki core
Turns out the MediaWikiIntegrationTestCase base class comes with a
bunch of convenience methods for this. We can even remove the custom
messages because these methods already print a lot of debug info in
case of a failure.

Change-Id: I61fd86f1560c8e3bcf39a30b09fecdb063424613
2023-09-28 12:24:52 +00:00
jenkins-bot 1f1c5e477b Merge "When testing against a page creation in RC, set page_id to 0 as in the real filtering" 2023-09-11 09:28:33 +00:00
Amir Sarabadani ead29fc0fe Re-enable skipped test
Depends-On: I04c1dcf5129df437589149f0f3e284974d7c98fa
Change-Id: Ib071cd62d21090d28088729d2b2850363b750dae
2023-08-25 17:06:15 +02:00
Amir Sarabadani 2745b58451 Mark FilteredActionsHandlerTest::getFilteredActionsHandler skipped
Temporarily as I rename Status class.

Change-Id: I5f89ecf27ce1471a74f31c6018806461781213c3
2023-08-25 14:59:08 +02:00
Derick Alangi 623b9dbea3
Migrate DeferredUpdatesManager to use DeferredUpdates directly
Reverts part of Id9056528a433faf0, to switch to DeferredUpdates in
CirrusSearch back from DeferredUpdatesManager.

Bug: T265749
Change-Id: I8126cc76440724753c356c48ba4e0fcc9be5b41a
2023-08-21 12:59:28 +01:00
Umherirrender 62127964b7 Use namespaced MediaWiki\User\ActorMigrationBase
Bug: T321681
Change-Id: If3940c982d55643a685e2dedccab0540f86b9ae9
2023-08-20 01:08:09 +02:00
jenkins-bot e23b4bf8ef Merge "Use namespaced Title" 2023-08-19 18:33:50 +00:00
Umherirrender cd7e9d31a7 Use namespaced Title
Bug: T321681
Change-Id: I66fd9b70a5de06ac3c81bdf6a2a5bca64ed094c2
2023-08-19 19:49:36 +02:00
Daimona Eaytoy 85f8f90531 Clean up AbuseFilterConsequencesTest a bit
Most notably, make it not use additional DB tables to test global
filters. Instead, just pretend that the local database is not local (via
config) and "hide" local filters with a simple test-only flag in
FilterLookup.

Change-Id: Ib431dbf6c9d84978ee84e7f0671cfcbf8a54d7a2
2023-08-19 15:31:41 +00:00
Daimona Eaytoy a10765baec Use real user ID in EchoNotifierTest
Echo will at some point try to load the user with the given ID, and will
throw an exception if it doesn't exist. The test is currently passing
just because we're not properly cleaning DB tables, and the user with ID
1 happens to exist at that point, but it will fail with core change
Ie2f1809d.

Change-Id: Ie686f4d5c2842e45a6ed564b311bb5d9b0265091
2023-08-18 01:51:09 +02:00
Umherirrender 8e6d820154 Use HookHandlers for UserMerge hook
Bug: T254306
Depends-On: Ib78dae49854863af1a37a00636737c94694776ae
Change-Id: If2bc517fb612199f4d744efbfa261ee5c556b6a5
2023-08-16 09:44:30 +02:00
Umherirrender aef4466d4b tests: Split long line in importingFilters.js
tests\selenium\specs\importingFilters.js
   81:1  warning  This line has a length of 106. Maximum allowed is 100
max-len

Change-Id: Ic8bee37971afb6fe4ba7102d687f0fa212092f4c
2023-08-10 23:53:17 +02:00
jenkins-bot 4f6ff34a26 Merge "tests: Avoid DB access in non-Database tests" 2023-08-07 13:13:27 +00:00
jenkins-bot e566cb1327 Merge "Avoid TestUser in non-database tests" 2023-08-07 13:13:25 +00:00
Daimona Eaytoy dcef8cebc6 tests: Avoid DB access in non-Database tests
These tests were accessing the Database, for mainly 3 reasons:
- User::newSystemUser
- Static methods in ChangeTags
- Echo's Event class

There isn't much we can do about them, so add tests to the Database
group where needed. In some cases, there are already comments that these
tests should be made unit tests once possible.

Bug: T155147
Change-Id: I8a0d52e0a4cae8a4059b62867853a73e60c878a1
2023-08-06 22:19:03 +00:00
Daimona Eaytoy 2a6b7edecb Avoid TestUser in non-database tests
TestUser requires a DB connection, so avoid using it in database-less
tests. Add to the Database group tests that are making DB writes (e.g.,
for log entries).

Change-Id: I211cb60296e5c2446128fcdf2caaadc728a8c272
2023-08-06 22:18:49 +00:00
Amir Sarabadani 049e602b07 BlockedDomains: Move filtering logic to a dedicated class
I'm planning to add support for bypass and regex-based blocking which
means it'll grow a bit. So let's give it a dedicated class.

Bug: T337431
Change-Id: I5a6fe2fd2f1efdebd8cada0ba6c481341f830e27
2023-08-06 16:27:23 +02:00
jenkins-bot a3ffaba341 Merge "Replace userNameUtils with UserIdentityUtils" 2023-08-06 10:00:04 +00:00
gerritbot 806ac5285d Migrate ILB::getConnectionRef() calls to ILB::getConnection()
Deprecated since 1.39 (I6e7544763bd)

Bug: T343277
Change-Id: I1d6d8d8bee8b39a5d364d8bb65f5f9a85194114d
2023-08-03 22:28:51 +00:00
Umherirrender c72b6a20f0 Pass ParserFactory to LazyVariableComputer
Make the init of Parser lazy

Bug: T343070
Change-Id: If0f0ca3c4aa2136c85903289f7f80b95dc5132c8
2023-07-29 14:20:07 +02:00
AnaïsGueyte 2efd6d9ac9 Replace userNameUtils with UserIdentityUtils
Where UserIdentity is available and where it's necessary to check ::isNamed

Bug: T342741
Change-Id: I5b52686f1c072282e76874f3863962345ca8097e
2023-07-27 10:29:31 -03:00
jenkins-bot 78c7334d6a Merge "Split VariableGenerator::addEditVars" 2023-07-17 23:26:53 +00:00
Daimona Eaytoy 2a89b3fb6d Skip CheckUserHandlerTest if CheckUser is not installed
The handler class uses hook interfaces from the CheckUser extension, so
it can't run if CheckUser is not installed.

Change-Id: I5f40366f27cc885e95e1bb93ec421b09c7caa9a6
2023-07-15 22:04:42 +02:00
Amir Sarabadani 85639c857a Re-enable skipped tests with fixes
Depends-On: Ia55cb6cbdb28484e820f9cf3d6aacac00a86ffab
Bug: T341828
Change-Id: Id0aad8aeb7b5380f4d934d9133abf0e12dee29fe
2023-07-13 23:01:22 +02:00
Amir Sarabadani 4eab548a02 Temporarily skip tests being broken in READ NEW of externallinks
Bug: T341828
Change-Id: I2d4ef8fc3bffa43bc611af3eab0494f4900df557
2023-07-13 22:42:47 +02:00
Matěj Suchánek 49edc86a78 Split VariableGenerator::addEditVars
This method actually consists of two: add derived vars, and initialize
content vars. The former part depends on no parameters of this method.
On the other hand, the latter part combines multiple implementations
for some of the content variables using branching.

The branching is a dirty workaround and inferior to the GRASP principle:
"When related alternatives or behaviors vary by type, assign
responsibility for the behavior to the types for which the behavior
varies."
In other words, the callers (extensions) should be responsible for
choosing the initialization strategy themselves, instead of letting
VariableGenerator figure it out.

As the first step, split the former part to a separate method.
For now, it will be implicitly called by ::addEditVars.

Change-Id: I5ff00dbdbf29ec54eabfd95c44a4fd7f713969f5
2023-07-05 14:58:32 +00:00
Abijeet b1e404fc79 ConsequencesFactory: Avoid creating Session object during service wiring
Service wiring should only depend on config, not on request state.

Creating a session object during service wiring causes issues with entry
points such as opensearch_desc.php that disable the session.

Bug: T340113
Change-Id: I2450b0b6821ff0b097e283ff660a0b8aeea9590a
2023-06-27 20:11:38 +05:30
thiemowmde 24888bea15 Mark protected stuff in classes with no subclasses as private
Protected effectively means "public to subclasses" and should be
avoided for the same reasons as marking everything as public should
be avoided.

Change-Id: Iba674b486ce53fd1f94f70163d47824e969abb77
2023-06-23 12:28:06 +02:00
Timo Tijhof 203d54be11 BlockedExternalDomains: Optimize host extraction by using parse_url
Unlike what the 20-year old source comments in UrlUtils.php would
have you believe, parse_url() works fine nowadays, including for
protocol-relative URLs and indeed lots of prod code uses it directly.

The class still has some convenience value for case where you need to
expand or manipulate URLs, but for the common case of extracting a part
of it, you really don't need it.

Test plan:
$ php phpunit.php ../../extensions/AbuseFilter/tests/phpunit/integration/FilteredActionsHandlerTest.php

Bug: T337431
Change-Id: I1e76d2f5aef65365743214530faba656325b965a
2023-06-19 13:36:27 +00:00
jenkins-bot a2524dd966 Merge "Make some non-static providers static" 2023-06-16 19:57:17 +00:00
Matěj Suchánek 1bcc28891f Make some non-static providers static
Or at least one step forward to better isolation.
Some providers were replaced with individual test cases.

Bug: T337144
Change-Id: I5cd8c5e79993260f18c3a17c40b8501a4da3c17f
2023-06-16 20:54:33 +02:00
Amir Sarabadani 8b67de5bc1 blocked domains: Make sure users can't bypass the list by using uppercase
Added tests too

Bug: T337431
Change-Id: Ie3406d0b3c7d82ba44c11865e493375453555664
2023-06-16 01:22:48 +02:00
jenkins-bot 596a36866b Merge "Add missing AbuseFilterServices::getHookRunner()" 2023-06-15 18:06:28 +00:00
thiemowmde 7e6132d4d7 Remove bits of unused code across the codebase
Mostly found with the code inspection tools in PHPStorm.

Change-Id: I7f59dddca0aaab0ddd1093d52c07ec12efd20d6d
2023-06-14 19:41:00 +00:00
Lucas Werkmeister 9bb4b1e5db Add missing AbuseFilterServices::getHookRunner()
And register AbuseFilterRunnerFactory as a service name that’s allowed
to not have a getRunnerFactory() method without the test complaining
(the service was renamed, getFilterRunnerFactory() exists).

Change-Id: Idedb87e64a6df02b0edae8d9e7dbf441752dc480
Needed-By: If5af88e7f70b83d53f66b9617a5ef37daf81830f
2023-06-14 17:35:43 +02:00
Matěj Suchánek 8fb53edfbb Retrieve external links from PreparedUpdate
When forFilter is true and PreparedUpdate is available
(most save operations), retrieve all_links from
PreparedUpdate::getParserOutputForMetaData. Otherwise
do what was done before.

Note that this change probably leaves some dead code. It will be dealt
with later.

NOTE: this changes code potentially executed on every save operation.

Bug: T65632
Bug: T264104
Change-Id: I3628a56e5277846c1b90444fb55983870eb54c1e
2023-06-13 14:30:06 +02:00
Matěj Suchánek d82a716ad0 Make old_links retrieval cleaner
The method for old_links retrieval depends on the "forFilter"
value, which we know in advance. If it's true, old_links should
be retrieved from the database. Make a case in the switch
that does nothing but retrieves links from the database,
and direct the evaluation to it.

This change was split from I3628a56e5 to make its review easier.

NOTE: this changes code potentially executed on every save operation.

Change-Id: I33b688f6be3c58beec403f7bf26407a42e7c18ab
2023-06-13 14:03:21 +02:00
jenkins-bot 54b9cbd6da Merge "BlockedDomains: Use cleaner array building and add tests" 2023-06-12 18:06:38 +00:00
Amir Sarabadani 60cbc3b464 BlockedDomains: Use cleaner array building and add tests
Regarding array building: Instead of adding to array with
$array[] = 'foo' and then doing array_flip(), simply do
$array['foo'] = true;

Regarding tests: I originally wanted to create a unit test but I ended
up mocking so many things that it wasn't worth it and the config variable
is globaly which first we need to clean up after deployment is done.

Bug: T337431
Change-Id: Iac8dca7078668ee3441d19b6aafe499c1aa0d732
2023-06-12 17:46:55 +00:00
thiemowmde 84058c3d96 Make use of the ??= operator and such where it makes sense
We can avoid a bit of code duplication and move code closer together
when it belongs together.

Change-Id: Iffca7e4abfbf03d4663ee909220057bcbd54da75
2023-06-12 10:27:03 +02:00