Commit graph

276 commits

Author SHA1 Message Date
Umherirrender
0a69e0bc53 tests: Use const for some static data in test files
Change-Id: Id7ccd48e3bf626095e2d3929831b5d87ed0be948
2024-09-01 23:24:11 +02:00
thiemowmde
ba36bf46a1 tests: Make use of ??= and ?? operators in various tests
The main benefit is that this syntax avoids repeating the variable
name. It does the same as before.

Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
2024-08-15 11:44:46 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
STran
311774c033 Filter temporary accounts as anonymous in ApiQueryRecentChanges
Edits from temporary accounts are considered anonymous edits.
ApiQueryRecentChanges doesn't correctly reflect this and needs to be
updated to correctly return temporary account edits as anonymous (and
similarly, not to return them when requesting !anon)

- Update the anon|!anon query to accomodate temporary accounts

Bug: T370803
Change-Id: Ica5225422ea53d2aa3a84b86d9c2f14832a34ed4
2024-07-29 11:00:22 +01:00
Bartosz Dziewoński
252bacff34 RecentChange: Replace use of legacy error arrays
Replace uses of soon-to-be-deprecated methods:
* ApiBase::errorArrayToStatus
* PermissionStatus::toLegacyErrorArray

Deprecate and replace uses of:
* RecentChange::doMarkPatrolled

Change-Id: I2311d1fa3772ba6be378ad6f497ed4c0df9b7aa8
2024-07-09 21:48:34 +00:00
Kosta Harlan
638117c424
ApiQueryWatchlistIntegrationTest: Disable temp account in anon edit
Why:

- The test class does anonymous edits, but did not first disable temp
  user creation

What:

- Disable temp user creation before attempting an anonymous edit
- Enable temp account feature when calling doTempPageEdit
  - Remove call to enableAutoCreateTempUser in testShowAnonParamsTemp, as
    it's no longer needed

Bug: T365669
Change-Id: I2ce83d5703ecc75fe680d7ddb44aa406c26c4df5
2024-06-26 13:13:54 +02:00
Kosta Harlan
c7c1404d27 ApiQueryUserContribsTest: Disable temp account feature
Why:

- This test exercises code that checks for IP edits

What:

- Disable temp user feature for this test class

Bug: T365669
Change-Id: If385b71b76c16f9276c3973a02ca0c888b47d3a3
2024-06-26 10:55:32 +00:00
Kosta Harlan
059d155dd3 ApiQueryRecentChangesIntegrationTest: Fixes for temp accounts
Why:

- This test does not pass when temp accounts are enabled

What:

- Set disableAutoCreateTempUser when doing an anon page edit
- Set a valid pattern for the temp user name

This patch does not fix testUserPropParameter but does solve the other
failures for this class.

Bug: T365669
Change-Id: I24b3ff10c6275a9c13c3f07d97ea14581f975067
2024-06-26 10:55:32 +00:00
Wandji69
c257e2276c Replace db with getDb for Tests
Bug: T316841
Change-Id: I29e535e8ee9b5641a4546d53b98cd5060d39681d
2024-06-23 23:47:56 +01:00
jenkins-bot
52e66c8aa8 Merge "api: Rewrite adrto/from/prefix handling to use expression builder" 2024-06-18 14:16:23 +00:00
Umherirrender
883b3f08fb api: Rewrite adrto/from/prefix handling to use expression builder
For a deduplication the raw sql is used as string key in an array.
Now only the search term is part of the key, build the sql a bit later,
as objects not usable in array keys.

The deduplication is needed when namespaces have different first letter
configs as happen with $wgCapitalLinks = false for all namespaces except
the hard coded like user and mediawiki with talk.
Searching for lower case titles splits the query

Bug: T361023
Change-Id: Ia4e29d1d4d816f354318ef443ae19c954fd52274
2024-06-17 22:36:10 +02:00
Kosta Harlan
2ed2467a7a
ApiQuerySiteinfo: Use TempUserConfig class
Why:

- Using TempUserConfig is more flexible as it doesn't require us to know
  about the internal details of the AutoCreateTempUser config object

What:

- Use TempUserConfig service instead of loading the AutoCreateTempUser
  object
- Remove properties from ApiQuerySiteInfo that don't already have
  getters. If someone has a need for more this information to be exposed
  in ApiQuerySiteInfo, they can be added in a separate patch
  - This seems compatible with the goals of T335532 which was about
    making it possible to discover via the API if an action would result
    in a temp account
- Implement __toString for Pattern, so that it can be used in
  ApiQuerySiteInfo

Bug: T335532
Change-Id: Ica84b3e9b9865b8b83a9e9e513c99cd2e47661c9
2024-06-13 22:11:27 +02:00
Kosta Harlan
cef704c72a
TempUserTestTrait: Use an array for config overrides when disabling
Why:

- Consistency with the enableAutoCreateTempUser method
- Allows for overriding config properties (e.g. 'known')

What:

- Use an array as the parameter for `disableAutoCreateTempUser` instead
  of a string

Change-Id: I1a495cc83effcf92364fa489f779c5f4bf2d29b9
2024-06-13 21:42:35 +02:00
Ebrahim Byagowi
1e4f59b724 Add namespace and deprecation alias to WatchedItemQueryService
This patch introduces a namespace declaration for the
MediaWiki\Watchlist to WatchedItemQueryService and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ib1b5c19c89087940987730939e84c8cd35cd3760
2024-05-18 01:50:29 +03:30
jenkins-bot
37d2a081ba Merge "block: Deprecate and stop using $wgBlockTargetMigrationStage" 2024-05-11 00:47:21 +00:00
Tim Starling
a5372218b7 block: Deprecate and stop using $wgBlockTargetMigrationStage
* Deprecate and stop using $wgBlockTargetMigrationStage. Remove
  block_target migration code.
* Make the $schema parameters to DatabaseBlockStore methods default to
  SCHEMA_BLOCK. Avoid passing these parameters where possible.
* Remove cleanupBlocks.php
* Deprecate DatabaseBlock static methods which try to present the old
  schema for b/c.

Bug: T362133
Change-Id: I845bad8cc09a4528fef46a6f9d490ebdec881d99
2024-05-10 15:54:17 +10:00
DannyS712
ee75e1c6f9 Tests: remove a bunch of DummyServicesTrait-related comments
Not sure why I added these, it should be clear from the method names

Change-Id: Ie49881e6f31fad52bb65b0d2ac3e9379dbb7bfc5
2024-05-10 04:07:59 +00:00
Timo Tijhof
c02513c97e phpunit: Fix tests relying on implicit wgScript/wgArticlePath
A number of tests have hardcoded expections that pass only in WMF CI
where Quibble has LocalSettings.php with $wgScript and $wgArticlePath
set a certain way.

We could fix these by adding setMwGlobals() in their tests, as we
often do, but these are so often forgotten that I'd rather we just
add them to TestSetup.php so that it is simply impossible to write a
test that that passes locally for you (if you have the same config)
but not for someone else.

There is a larger project in there somewhere about expanding this
slowly such that we basically only pluck DB-settings and extension
enablement from LocalSettings and otherwise run the tests with the
default settings in PHPUnit. Pretty much by definition, any (other)
setting you have in LocalSettings is irrelevant because it either:
1. has no effect on the test (majority, harmless either way),
2. has a custom default via TestSetup.php (which has precedence over
   LocalSettings.php),
3. is relevant to the code being tested and the test case correctly
   calls setMwGlobals() to ensure a consistent value during test.
4. is relevant to the tested code but has no override, thus only
   passes if you happen to have the "right" value set for it
   (undesirable).

Case 4 is already categorically impossible for the most common config
settings that influence random code because we give them a value
in TestSetup.php. This patch expands that to include $wgScript
and $wgArticlePath. Perhaps in the future we can think about a way
to do this automatically by either re-applying MainConfigSchema
(sans db settings) or by only selectively applying LocalSettings.php
in the first place.

This patch follows-up I072ddf89562fe, which added a test case in
WikitextContentHandlerIntegrationTest.php that assumed "/index.php"
as the value of $wgScript. This passes in WMF CI since Quibble uses
that value, but the tests failed in most local development installs
since those tend to use "/w" instead.

Rather than one-off fixing that one test with overrideConfigValues(),
switch to a more general fixture, since the precise values don't
matter for this test.

Bug: T349087
Bug: T277470
Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
2024-05-05 00:00:01 +00:00
bpirkle
98684f72a9 Minor comment cleanup in ApiQueryTestBase.php
Change-Id: I36cb706acc745a082b6fd90a55b859f24ed35eb9
2024-05-03 17:01:20 -05:00
Amir Sarabadani
cf77897613 Run pagelinks migration for third parties too
Production is read new almost everywhere, mediawiki core should reflect
that as well.

Bug: T299947
Change-Id: I8f05c4d7026394205bfc54b68dc725392852ae2a
2024-04-27 16:57:37 -04:00
Kosta Harlan
6efd008f33 TempAccounts: Rate limit acquisition of temp account names
Why:

- We don't want to allow unlimited acquisition of temp account names.
  These should be rate limited in similar way to how we limit the
  creation of temp accounts

What:

- Provide a TempAccountNameAcquisitionThrottle, and use it in the
  acquireName() method
- Set a default that is 10 times the limit of
  TempAccountNameCreationThrottle

Depends-On: If660aad1d0f04f366414084aff3f88484a19d416
Bug: T343101
Change-Id: I99d5973498a89ac227847de5837c0a8e895c28fb
2024-04-23 13:33:57 +00:00
Taavi Väänänen
ed7e787f32
Ignore/fix MediaWiki.Commenting.PropertyDocumentation.WrongStyle
Fix the real issues found by this sniff, and convert the remaining
false positive ignores to per-line ignores so that any more real issues
won't be added.

Change-Id: I18e75d59df327e2d93a3a487c115e92b9f268722
2024-04-22 18:26:14 +03:00
Umherirrender
a89a00ffb8 tests: Migrate to IDatabase::newInsertQueryBuilder
Changed some inserts to use multi-row insert for small performance
benefit where possible and not already used.
InsertQueryBuilder does not return a value, deprecated since 1.33

Bug: T353219
Change-Id: I2380ebc8ec8db178dd790247aefbdd798b6d62ff
2024-04-14 21:56:07 +02:00
Dreamy Jazz
eabb13833f Define ApiQuery::isWriteMode
Why:
* ApiQueryBase subclasses may define a ::isWriteMode override, as
  the API call may need to write to the DB.
** This is the case for the CheckUser extension, where the
   'checkuser' API creates a log entry that allows users to audit
   usage of the API.
* ApiQuery currently does not define a implementation of
  ::isWriteMode, which means that the definitions by any class
  that extends ApiQueryBase currently do nothing.
* ApiQuery::isWriteMode should be defined and work in a similar
  way to ApiQuery::isReadMode, so that subclasses of ApiQueryBase
  can have their definitions of ::isWriteMode respected.

What:
* Define ApiQuery::isWriteMode in a similar way to how ApiQuery
  ::isReadMode is written, but also inspecting the modules that
  are used through the 'list' and 'prop' params.
* Add tests for ApiQuery::isWriteMode.

Bug: T361951
Change-Id: Idf1c8f95df58a861404e0c89507c885ec4554793
2024-04-05 16:56:04 +01:00
Dreamy Jazz
102424bfb3 Update wgAutoCreateTempUser config defaults
Why:
* The default value of wgAutoCreateTempUser has not changed since
  the decision to use a different prefix for temporary accounts
  (T332805).
* The default needs to be updated to reduce the number of overrides
  in operations/mediawiki-config and also to make the development
  experience more consistent with what is happening on WMF
  production.

What:
* Update the wgAutoCreateTempUser default in the following ways:
** Set expireAfterDays as 365
** Set notifyBeforeExpirationDays as 10
** Set genPattern and reservedPattern to '~$1'
** Set matchPattern to null, which will mean that the genPattern
   is used as the value.
* Update RealTempUserConfig::getPlaceholderName to add the year to
  the placeholder name so that if the match pattern includes the
  first digit of the year, then the placeholder name still is
  considered a valid temporary account username.
* Replace modifications of the wgAutoCreateTempUser config in
  integration tests with a use of the TempUserTestTrait to make
  the code cleaner and make it easier to find tests that relies on
  the values in wgAutoCreateTempUser.
* Update multiple tests to handle the new defaults for the config.

Bug: T359335
Change-Id: Ifa5a0123cd915bdb7c87e473c51fb93321622f12
2024-04-03 16:25:47 +00:00
Tim Starling
768fd92fc0 block: Clarify function of HideUserUtils aliases and use them consistently
* Add a comment explaining why we need table aliases in HideUserUtils
  subqueries.
* Use the table aliases consistently in inner field references. While
  this does not appear to be strictly necessary, since unprefixed fields
  refer to the inner query by default, it helps to improve the clarity
  of the code.

Change-Id: Id68684ea12060a259dc87e66edd63b925da2c3b1
2024-03-19 11:31:03 +11:00
Tim Starling
8606c00b52 block: Use a scalar subquery in HideUserUtils::getExpression
On en.wikipedia.org, MariaDB chooses to materialize the subquery,
copying about 810,000 rows to a temporary table.

So, use a dependent scalar subquery, which is not eligible for this
"optimisation".

Bug: T360163
Change-Id: I7819a6870871687ea96f92dfd3f8fe581b54cc24
2024-03-15 13:47:48 +11:00
Thalia
0b7a4b049a Group temporary users with IP users in ApiQueryWatchlist filters
Why

* ApiQueryWatchList allows filtering anon users or not-anon users.
  It is not obvious wether temporary users should be considered
  anon for these purposes.
* The equivalent filters in recent changes group temporary users
  with anonymous users (T343322).
* Since ApiQueryWatchlist queries the recentchanges table, and
  shares many filters with recent changes, it makes sense to
  filter the same way in both, and therefore to group temporary
  users with anonymous users.

What

* Update queries in WatchedItemQueryService to group temporary
  users with anonymous users for FILTER_ANON and FILTER_NOT_ANON.
* Don't change the 'anon' flag, because the other APIs flag
  temporary users with anon=false.
* Instead add a 'temp' flag for temporary users.

Bug: T358693
Change-Id: I4cd3a4d0c5f4f488933cf3f06dee62a9beb85440
2024-03-03 06:26:03 +00:00
Dreamy Jazz
2e3bd68bec Add 'temp' flag to ApiQueryUserInfo API
Why:
* The ApiQueryUserInfo API returns 'anon' as true when the user
  making the request is an IP user.
* This API should return 'temp' if the user making the request is
  a temporary account, as described by T358683.

What:
* Return 'temp' with the value true from the ApiQueryUserInfo API
  when the user making the API request is a temporary user.
* Test that the temp user flag is added when the user making the
  request is a temporary user and that the flag is not added when
  the user is logged-out.

Bug: T358683
Change-Id: I5f165576a12a2218d89ab3623d7df45e2c9049fa
2024-02-28 17:21:30 +00:00
Reedy
75640200fb tests: Namespace api tests
Bug: T357823
Change-Id: I0d7cc2c9b166d5e5b913c1305f7cee017fe377af
2024-02-18 15:47:04 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
jenkins-bot
ba409888a1 Merge "Clean up tests" 2024-02-16 07:58:38 +00:00
jenkins-bot
51cc850272 Merge "Add tests for temp user flag" 2024-02-14 14:17:07 +00:00
STran
1a9f6da570 Add tests for temp user flag
- test for temp users in ApiQueryLogEvents
- test for temp users in ApiQueryRevisionsTest

Bug: T353355
Change-Id: I8c1ae26e5566dd8fc2d2817fd3acaa04478d686c
2024-02-14 05:50:08 -08:00
Matěj Suchánek
45390a52eb Clean up tests
Replace strpos with str_contains, str_starts_with, etc.
Fix spelling of "cannot" and other typos.

Change-Id: Ie52900b323f46d1978a9dd9ea3b17619b8942160
2024-02-12 09:25:25 +01:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Umherirrender
da3301cb08 tests: Remove unneeded return from closures
Change-Id: Icdfdf8e1db69f5294349536590269b3490ef87b7
2024-01-27 00:07:36 +01:00
Reedy
627ad6956d ApiSiteInfo: Add siprop=autopromoteonce
Bug: T196059
Change-Id: Ia41b55a1da13e14f633cb32ee8efcc2b4ff88cee
2024-01-24 20:31:48 +00:00
星耀晨曦
9ca8844902 ApiSiteInfo: Add siprop=autopromote to return $wgAutopromote data
Bug: T196059
Co-Authored-by: Reedy <reedy@wikimedia.org>
Change-Id: I92236cea845c10ef1725891a49d48a04d5d3bfad
2024-01-24 20:14:05 +00:00
Umherirrender
16a436ce6c tests: Remove cleanup of blocks, done by ChangedTablesTracker
In DatabaseBlockTest changed from addDBDataOnce() to addDBData() as
ChangedTablesTracker cannot reset tables changed by addDBDataOnce()
between each test run.

Remove also User::clearInstanceCache done together with the deletion as
the TestUser class is calling this already between tests.

Change-Id: Ibd5e544138a2a9b554abc2dea54a5db38f9a828f
2024-01-20 11:41:15 +01:00
jenkins-bot
73dd6f532a Merge "Replace a few array_key_exists with the ??= syntax" 2024-01-16 21:26:28 +00:00
Reedy
72df6cb8da libs/composer: Namespace under Wikimedia\Composer
Change-Id: I5ffedacf31e60fb0f38e308f8dcf010e577f919e
2024-01-13 20:10:25 +00:00
jenkins-bot
50c37120ee Merge "modify getMutableTestUser() and use it in api query all users test" 2024-01-09 07:12:37 +00:00
thiemowmde
9b0f6b568d Replace a few array_key_exists with the ??= syntax
Or just remove it. It's not needed when the structure is already an
array. PHP will happily initialize multi-dimentional arrays when
needed.

Change-Id: I93845e8d6f870d147bd55cfe3827bc94b375d0ba
2024-01-08 10:12:10 +01:00
Ariel T. Glenn
b0c82d3784 modify getMutableTestUser() and use it in api query all users test
Change-Id: I237f0aac25435514711ad529a273a69ea91a5b30
2024-01-05 11:14:30 +02:00
Umherirrender
c99e804f0b tests: Remove unused variable after ConvertibleTimestamp::setFakeTime
ConvertibleTimestamp::setFakeTime does not return a ScopedCallback,
which would need a local variable, it returns the old value.
The reset is part of MediaWikiTestCaseTrait.

Change-Id: Ic479ec810f3f75cbdd393f2d91afb7a311d798a0
2023-12-27 16:36:14 +01:00
Umherirrender
0e6113845e tests: Fix name of class property in ApiQueryImageInfoTest
Creation of dynamic property ApiQueryImageInfoTest::$tempUser is
deprecated in php8.2

Follow-Up: I7986dea5ccd0dc942bf133040c4ac715487f29b9
Change-Id: Ifa2b1fc46a30edb12266d46b71d8916c53397cc0
2023-12-13 20:01:39 +01:00
jenkins-bot
c5c1856f07 Merge "Add temp flags to api calls" 2023-12-13 17:32:39 +00:00