Commit graph

241 commits

Author SHA1 Message Date
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
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
STran
c668caa5ce Add temp flags to api calls
Temporary accounts are now distinct from users or anonymous.
Add a flag to reflect that to:
  - ApiQueryImageInfo
  - ApiQueryLogEvents
  - ApiQueryRecentChanges
  - ApiQueryRevisionsBase

Bug: T351636
Change-Id: I7986dea5ccd0dc942bf133040c4ac715487f29b9
2023-12-12 00:32:01 -08:00
Tim Starling
9c02258a04 Use thousands separators in selected integer literals
For readability. Allowed since PHP 7.4.

I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.

Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
2023-12-12 09:22:45 +11:00
jenkins-bot
760fb41b2b Merge "use getUserPermissions in query allusers api calls to get user rights" 2023-12-11 20:59:59 +00:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Ariel T. Glenn
286ad233a2 use getUserPermissions in query allusers api calls to get user rights
This means that e.g. global rights will now show up.

Bug: T205992
Change-Id: I290ec18a1aa08b8aa11c4e101ae05657e7963829
2023-12-11 14:04:36 +02:00
Tim Starling
60911137ef Special:BlockList: Improve display of hidden users
With multiblocks the user might be hidden even if bl_deleted=0 in the
block row being formatted.

So:
* Add a subquery with a second block_target/block table which determines
  whether the user is deleted.
* When formatting each row, redact the name if it is deleted and the
  authority does not have permission to see it.
* Add a parameter to show which block is the one responsible for
  deleting the user.
* Similarly add a subquery in ApiQueryBlocks.

Change-Id: Id9900397618e1f626802ada6fe4ee4ad10f32495
2023-12-05 13:25:54 -05:00
Tim Starling
d6727856fd Support new block schema
Support migration stages when reading and writing blocks.

I tried to set it up for an easy next stage, in which support for the
old schema is removed. I tried to avoid factoring out of shared code
between the two schemas, so that the old schema cases can simply be
deleted without the need to revert unnecessary abstractions.

However, I added HideUserUtils to factor out ipb_deleted queries. Code
review showed that this was already quite complex, with multiple
approaches to the problem, so it benefits from refactoring even without
the schema abstraction.

HideUserUtils is a service rather than a standalone class to support
unit tests, since unit tests do not allow global config access. When
the migration stage config is removed, it will be a service with no
constructor parameters -- an unnecessary abstraction which should
ideally be resolved at that time.

When interpreting result rows, it is possible to share code by using
field aliases. But when constructing WHERE conditions, the actual field
names need to be used, so the migration is more intrusive in
ApiQueryBlocks and SpecialBlockList, where complex conditions are used.

Bug: T346293
Bug: T51504
Bug: T349883
Change-Id: I408acf7a57b0100fe18c455fc13141277a598925
2023-11-29 13:31:42 +11:00
James D. Forrester
4ed5ca48b1 Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessary
Bug: T342301
Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
2023-11-21 09:02:48 -05:00
Martin Urbanec
c9908da103 IP Masking: Expire temporary accounts in 1 year
Why:
Temporary accounts (introduced as part of IP Masking)
are supposed to expire 1 year after their registration.
Automatic account expiration can be done via a maintenance
script, which would be periodically executed via cron / systemd.

Make it possible for extensions to provide their own logic
for generating a list of temporary accounts to invalidate.
This is used in CentralAuth to base registration timestamp
on the global registration timestamp.

The default behavior is "temporary accounts do not expire",
given the feature requires a maintenance script to run
periodically, which will not be the case on third party
instances.

What:
* Add `expireAfterDays` to $wgAutoCreateTempUser, controlling
  how many days temporary accounts have.
* Add UserSelectQueryBuilder::whereRegisteredTimestamp(),
  filtering accounts based on user_registration.
* Add ExpireTemporaryAccounts maintenance script, which is
  @stable to extend.

Bug: T344695
Change-Id: If17bf84ee6620c8eb784b7d835682ad5e7afdfcc
2023-11-09 15:11:48 +01:00
Tim Starling
990acd88be Stop using nonexistent DatabaseBlock constructor options
Remove the 'user' option from the documentation and defaults. It has
been ignored since a3b4881f6f (2021, 1.37).

Fix tests which pass unknown constructor options. I found these by
temporarily patching the constructor to throw when an unknown option is
given.

Change-Id: I95cb2a38a5688d83c90ad501786f6d6bb02765ba
2023-11-06 12:03:51 +11:00
zoranzoki21
a14076932e MessagesSr: Use aliases in Serbian Latin script as well
Based on the content of the MessagesSh.php file.

Bug: T185421
Bug: T349093
Change-Id: I91fcbe77e5d2fcc27398f116003f48f496f25dfb
2023-10-28 14:22:57 +00:00
Aaron Schulz
b231e75809 api: make APIQueryAllUsers handle implicit/*/user rights for aurights
Bug: T347633
Change-Id: I48ac655ea5dd6cdced7894425f37f040affbb0ce
2023-10-24 08:17:30 -07:00
Tim Starling
09ffad6ce3 Improve the readability of test code by making the BlockActionInfo::ACTION_* constants public+internal
Also don't use @var for constants, that breaks Doxygen.

Change-Id: Ifb92406c3c5ad6f5bd0b35d07c8106cfa18a99e4
2023-10-12 10:17:19 +11:00
Amir Sarabadani
f5abfb8d58 Bump codesniffer to 42.0.0
Most noisily, this enables MediaWiki.Arrays.OneSpaceInlineArray.

Change-Id: I8ab11399c67ce7e3ab1b6249b591452774393428
2023-09-27 15:06:32 -04:00
Amir Sarabadani
cd2e19c050 tests: Use $this->getDb() instead of wfGetDB() in integration tests
Deprecated long time ago.

Bug: T330641
Change-Id: Ia57f12d350c3346029aafae25534c9ed262a7e98
2023-09-25 21:08:09 +02:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
Derick Alangi
ff0bd2c434 Widen @covers annotations in tests ApiQueryInfoTest
> We lose useful coverage and spend valuable time keeping these tags
> accurate through refactors (or worse, forget to do so).
>
> I've audited each test to confirm it is a general test of the
> subject class, where adding any called methods would be an accepted
> change, thus widening it is merely a no-op that clarifies intent
> and reduces maintenance. I am not disabling the "only track coverage
> of specified subject" benefits, nor am I claiming coverage in
> in classes outside the subject under test.
>
> Tracking tiny details per-method wastes time in keeping references
> in sync during refactors, time to realize (and fix) when people
> inevitably don't keep them in sync, time lost in finding uncovered
> code to write tests for only to realize it was already covered but
> not yet claimed, etc.

@note: Motivated by patches like these from Krinkle from time to time,
see: I133c7b707aab7ceb4f2ecd3be38bd4bd1b194143 for example.

Change-Id: Icff4b5a2e9ce2108c1653052624c76004048cc31
2023-09-03 00:24:40 +00:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
Daimona Eaytoy
1cb036c392 Avoid DB access in more non-Database tests
Bug: T155147
Change-Id: Iae2512c66c32b209ea8579beecb3de94a744da14
2023-08-06 16:07:27 +00:00
jenkins-bot
59386e31a6 Merge "tests: api: Use NS_ constants instead of hard coded values" 2023-07-30 14:21:22 +00:00
jenkins-bot
7a9f3b4d9f Merge "tests: api: Replace some static function with services" 2023-07-30 14:20:38 +00:00
Daimona Eaytoy
2a0de02aab phpunit: Avoid TestUser in non-database tests
TestUser creates the user and therefore needs the database. Avoid using
it in non-database tests.

Add ApiQueryBlockInfoTraitTest to the Database group because it needs
the database.

Add DeleteUserEmailTest to the Database group because since 3bedffa8
the default user is not created any more in non-database tests

Change-Id: Iff438964dde47a47a2fa4a314d55010bd8c7fee5
2023-07-29 14:26:50 +00:00
Umherirrender
8f273a9dfa tests: api: Replace some static function with services
Replace User::, Title:: ContentHandler:: calls
to the corresponding services

Change-Id: I57e47221a00eafac9f171215019cf25e19e1808e
2023-07-29 11:58:54 +02:00
Umherirrender
d3fb83de20 tests: api: Use NS_ constants instead of hard coded values
Avoid some "magic" numbers

Change-Id: I52ec97434751cfe4136d504a3f8107c6bc63e7ab
2023-07-29 11:02:26 +02:00
Daimona Eaytoy
4c72c161d8 Deprecate MediaWikiIntegrationTestCase::$users
This property shouldn't be needed in modern code, where most things can
use Authority. So much so because TestUser adds a dependency on the
database, but many tests that use TestUser don't even need the database.
ApiTestCase, in particular, sets this property in setUp, thus adding a
database dependency to all API tests, including those that don't need
users or the database at all.

Deprecate the property and replace existing usages in core. The one in
ApiTestCase is much harder to migrate, but this patch replaces the array
with an anonymous ArrayAccess class to allow lazy initialization and
remove DB dependencies.

Bug: T155147
Change-Id: I59c4ed1f6a7572d3a92387b15b8e56625bc376a2
2023-07-25 12:12:43 +00:00
thiemowmde
8a9dd67139 Avoid calling overrideConfigValue() multiple times
Same as I7a82951.

overrideConfigValue() and overrideConfigValues() both call
setMwGlobals(), which calls resetServices(). This is surprisingly
expensive. It's much better to call it once with an array.

Change-Id: I4ff2f6b902b1a1e0b554ce6fc76f3b612f703fae
2023-07-20 14:59:42 +02:00
Umherirrender
160411d4cf Simplify WHERE conditions with field = '' OR IS NULL
Syntax supported since 26235c73

Change-Id: I397c76d4aba753a1629383559b95df86514f19ff
2023-07-01 22:17:42 +02:00
jenkins-bot
b692451063 Merge "api tests: Call editPage() with WikiPage when used for same page" 2023-06-25 10:47:11 +00:00
Umherirrender
ddfcebc584 api tests: Call editPage() with WikiPage when used for same page
When calling editPage() with a string it converts it to a WikiPage each
time it is called. When edit a page only once that is okay,
but when adding more revision to the same page it is better to pass a
WikiPage instead to allow reuse of internal states of WikiPage to speed
up the tests

Bug: T225730
Change-Id: I7a0e7e3e75ade5d6abe8e62a03a029190f3b6da8
2023-06-24 18:07:34 +00:00
James D. Forrester
357f408c13 tests: Replace deprecated calls to wfExpandUrl with hard-coded url
Bug: T319340
Change-Id: Iae13352f0cc902f74eb4c918dbb1a451472b0985
2023-06-23 17:23:18 +00:00
Umherirrender
792981fea5 tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Iddefe62c3d85281642f17e60cbc27aff47b85a67
2023-06-19 21:54:57 +02:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Umherirrender
d36073cdcf tests: Make some PHPUnit data providers static
Initally used a new sniff with autofix (T333745),
but some provide are defined non-static in TestBase class
and need more work to make them static in a compatible way

Bug: T332865
Change-Id: I889d33424f0c01fb26f2d86f8d4fc3de3e568843
2023-05-20 01:05:27 +02:00
Bartosz Dziewoński
77927cc2fa Expose automatic temporary user info in the API
action=query&prop=info&intestactions=...:
  Add &intestactionsautocreate=1 to also check whether the actions
  would result in a creation of a temporary user account.

action=query&meta=siteinfo:
  Add &siprop=autocreatetempuser to output the configuration
  of temporary user accounts.

Bug: T335532
Change-Id: I62b4bb630decac92cbb8c7ddf00307df0dadb516
2023-04-28 01:42:59 +02:00