Commit graph

84 commits

Author SHA1 Message Date
Umherirrender
1145328459 api: Use type-declaration for string arg in ApiBase::__construct
Also for all sub-classes
Remove simple doc-blocks without further information

Change-Id: I981934efe32d44f52e5ab865a9b887be5bd0f41e
2024-10-17 20:09:15 +02:00
James D. Forrester
e7db78e8d6 Replace uses of deprecated ChangeTags static methods
Bug: T360664
Change-Id: I3363a225e54bb2cae01ba066d432a8b7b21933d2
2024-10-16 13:30:12 -04:00
James D. Forrester
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
Umherirrender
9a107e6b03 Use expression builder instead of raw sql
Bug: T361023
Change-Id: Ibf1c93ddbf8f680e8fb9442816f6fed94a069c0a
2024-07-23 23:30:45 +02:00
jenkins-bot
2d116a3355 Merge "Use expression builder to avoid raw sql via BETWEEN operator" 2024-04-23 07:22:55 +00:00
Taavi Väänänen
3f4cb7969d
api: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I7859191740d66d00595c4bdeea12b227ac25bcc5
2024-04-21 23:05:59 +03:00
Umherirrender
fea5c2f687 Use expression builder to avoid raw sql via BETWEEN operator
Replace BETWEEN with >= and <= operator

Change-Id: Ic21b6f4cc11c773c967d9d4c5f20e762c2ff9629
2024-04-21 14:24:21 +02:00
Matěj Suchánek
7f6385e851 Use explicit value checks where "0" is valid input
User "0", page "0" and edit summary "0" are all valid.
Treating them as empty may cause subtle inconsistencies.

Change-Id: I90a92bfb972cca840e5d8060dac3f116a22990db
2024-02-22 09:59:32 +01:00
Thalia
beff37ce18 Add 'temp' to allowed user types in various APIs
Why:

* Before this task, when an API parameter specifies allowed user
  types, temporary users and permanent users are in the same
  category: 'name'.
* However, it is useful to separate them out, and sometimes
  allow a permanent user but not a temporary user (e.g.
  ApiResetPassword, since temporary users don't have passwords).
* We therefore re-defined the 'name' type only to refer to
  permanent (named) users, and add a new 'temp' type.
* This fixes params that currently intend to allow temp users,
  and that use 'name' to do so, by adding 'temp'.

What:

* Based on a search for `UserDef::PARAM_ALLOWED_USER_TYPES`,
  add the 'temp' type where necessary.
* The following were not updated, because they shouldn't apply
  to temporary users:
  - owners for includes/api/ApiQueryWatchlist.php,
    includes/api/ApiQueryWatchlistRaw.php
  - users for includes/api/ApiResetPassword.php,
    includes/api/ApiUserrights.php,
    includes/api/ApiValidatePassword.php

Bug: T350701
Change-Id: If5ccf1d469327791acff74d013343307e411cca9
2023-11-30 14:19:40 +00:00
James D. Forrester
3851805f64 Namespace remaining User-related classes under \MediaWiki\User
Bug: T166010
Change-Id: Ibda1e8be0f23c6262a32b607f8260cad36f188fc
2023-09-20 09:12:08 +01:00
Amir Sarabadani
049b34b41c Introduce RevisionSelectQueryBuilder
Deprecating RevisionStore::getQueryInfo() and cleaning up a lot of code

Also removing a brittle test that wasn't really testing anything.

Bug: T344971
Change-Id: Ifd690dc8f030f86e3567a717eaeb830cb6dc703b
2023-09-06 12:30:38 +02:00
Bartosz Dziewoński
c03cb71796 Use real type hints for services etc. in api/ApiQuery*.php
Mostly used find-and-replace:

Find:
/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|)
Replace with:
\3 \1 \4

Followed by some manual review to make sure I'm not changing too much,
omitting some changes that looked too complicated and anything that
caused test failures, and some whitespace fixes.

Change-Id: Ie78be1c614985d7c2964156e454cc9266515dc18
2023-08-29 01:02:40 +00:00
Umherirrender
7c3613951f i18n: Split apihelp for standard dir parameter
Easier to translate
There is no visible change for example on
Special:ApiHelp/query+watchlist

Bug: T285545
Change-Id: I536fa3e07a951f3ff98870678ffdbc294a3c7bc0
2023-08-05 15:06:52 +02:00
Umherirrender
6e0065ad20 Simplify WHERE conditions with field IS NULL
Reduce raw sql fragments on simple compares

Change-Id: I3f2340dfdbf5197cc22546911e6c5653dc5a6269
2023-07-24 19:22:36 +02:00
Umherirrender
d0ccacee4d api: Replace deprecated User::newFromName in usercontribs
The other closures assigned to $userIter already returning UserIdentity

Change-Id: I85aa96927304a0dcd565bed081266cdbe42f2c47
2023-06-16 19:04:16 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Timo Tijhof
7cbb74133e Remove obsolete Rdbms query groups from getConnection calls
The currently supported groups are documented in database.md.

While at it, prefer the string form of the $groups parameter where
possible, since the complexity of an array is never utilized, as the
groups either can't overlap, or are decided on by the caller instead.

This also helps with the simpler LBFactory::getConnection() proposed
in T326274.

Bug: T263127
Bug: T326274
Change-Id: I7a31a07a8c3f1e265ac43ab59f23326590b407c3
2023-02-15 17:10:26 +00:00
Alexander Vorwerk
f6bd18d6c2 Split a base class out of CommentStore
so that extensions (i.e. CheckUser) can implement their own comment
store without having a lot of code duplication

basically the comment store version of I3a6486532f2ef36

Bug: T233004
Change-Id: Ib40f99e00a514d41776ce521baf113e46d37e9cd
2023-01-01 22:34:36 +00:00
Amir Sarabadani
cb18d1007e Reorg: Move ActorMigration and ActorMigrationBase to user/
This may seem a bit weird but anything else related to actor is already
under user/ including ActorCache, ActorNormalization, ActorStore and
ActorStoreFactory.

Bug: T321882
Change-Id: I7072b374bba7a0cd9d905e399c822bf30bd5c0d8
2022-12-16 13:44:33 +01:00
Umherirrender
07697bb57c api: Replace deprecated Linker::formatComment
Bug: T324906
Change-Id: I1fcb7bd9d84754793c07ac9e39e50c38b364e4c1
2022-12-11 00:56:46 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
jenkins-bot
3a1d6f66ba Merge "api: Validate timestamp in continue parameter" 2022-11-03 13:38:47 +00:00
Bartosz Dziewoński
0aca618a2f ApiQueryUserContribs: Remove unused continuation modes
When using the 'userids' or 'user' parameters, $this->orderBy would
previously be set to (respectively) 'id' or 'name'.

This was confusing, because:

* If more than 1 user ID/name was requested, it was immediately
  overwritten to 'actor' by the code below.

* If only 1 user ID/name was requested, it was not used for building
  either the continuation string or the database query.

Set it to 'actor', and remove code generating and parsing the unused
continuation modes (note that 'name' is still used with other
parameters). Also rename a variable called `$fromName` that actually
always contained an actor ID and not a user name (resolving a FIXME).

Follow-up to c29909e59f, which removed
the code paths that used 'id' or 'name' continuation modes for paging
by user_id and user_name.

Change-Id: I9570292beaa7dca0dbc165ab319b9eef42712efa
2022-11-03 02:47:12 +01:00
Umherirrender
75ec894af0 api: Validate timestamp in continue parameter
Bug: T321265
Change-Id: Ib46bc3e643938f56e0c58a3c5f5e093327e00964
2022-11-01 22:40:10 +01:00
Bartosz Dziewoński
52f143da49 Use buildComparison() instead of raw SQL in API list=usercontribs
Bug: T321422
Change-Id: I51354e6dc71c02be7242d8d7baec83054e18a7fe
2022-10-22 01:39:32 +02:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Bartosz Dziewoński
a8c9e98661 Deduplicate code for parsing API 'continue' parameters
30+ API modules had nearly identical code to split and validate
the value of the 'continue' parameter.

Introduce the ApiBase::parseContinueParamOrDie() method and use it to
replace most usages of ApiBase::dieContinueUsageIf(). A few remain in
modules with more complex continuation handling.

Inline most single-use variables that remained after validation was
moved into the new method.

Change-Id: I66bd59ecd4ad16e2039e90f7d66cfa276e6c1c2a
2022-09-29 16:05:31 +00:00
Bartosz Dziewoński
00b74a0e4b Use buildComparison() instead of raw SQL in more API modules (easy cases)
See ec79aa3943 about the new method.

These changes all follow the same simple patterns. More complex cases
are handled in I6231b6beae13474d4986929367a9adc6bb76b0db.

This commit was created by running the following terrible Ruby script
I devised: https://phabricator.wikimedia.org/P34833, then manually
reviewing the results: checking that the output makes sense in general,
that the affected variables are not used elsewhere in the file, and
that no comparison conditions have been lost. A few incorrect changes
were undone or corrected.

Change-Id: I8ed363bd6b80a9481d44434a526f078cce20220f
2022-09-29 16:04:23 +00:00
Umherirrender
eb159d8f5a Remove unneeded initalize of local variables
The variables are set conditional later, but all condition branches set
it or the variable is not used outside that scope

Change-Id: Ic9612915db507028ad4733a061d3ce9be3babfb6
2022-09-21 21:29:21 +02:00
Umherirrender
51045dc46b api: Force actor index on list=usercontribs
Do the same forcing as already done in Special:Contribs
(from bac54c2 and 9c09511)

The default query for list=usercontribs&ucuser=*&ucnamespace=* for a
namespace with a small number of edits shows filesorting under EXPLAIN

Bug: T307815
Change-Id: I2c8577b0711f6cd19fd062dd19c7263338ab923d
2022-09-06 19:24:23 +02:00
Umherirrender
0f49ae2759 Use MainConfigNames constant to refer configs
Change-Id: Iddef589423d1e3f609b3cfbf6cc7437c6ad830b0
2022-08-17 21:27:48 +02:00
Derick Alangi
3d03c6a1ff api: Migrate IDatabase::select() to SelectQueryBuilder interface
Bug: T311866
Change-Id: I5d79fce9d48b0d366ee2a918d3133186a5b65eb7
2022-08-08 15:52:34 +01:00
Umherirrender
a5abaeba10 Call IContextSource::getAuthority instead of IContextSource::getUser
Change to use Authority object where possible
to use the interface instead of implementation

Change-Id: Ia7e9ce2a2f05ef2ae1cf981bf96faf48b04cf58d
2022-06-29 22:22:44 +02:00
Reedy
f45fefec0e api: Replace numerous more deprecated constants
Change-Id: I498a315b8b4b56d5e2f939e797adbe0487cd7d07
2022-06-06 02:24:41 +01:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Umherirrender
2f7c0d6166 api: Remove deprecated class alias ApiQueryContributions
Deprecated since 1.32

Change-Id: Ia4d2d01272175972f29a724c06c249bfeb522cfe
2022-05-29 06:15:38 +00:00
lziad
f54940b412 API: Add IP range support to list=usercontribs
This works by using the ip_changes table.
`iprange` parameter is introduced in order to restrict input to only one range.
Result is sorted by name, timestamp similar to `userprefix` parameter,
and T180153 (sort by timestamp first) is not addressed.

Related messages and test cases are added.

Bug: T177150
Change-Id: I3b8a917aaa76e18decf85b621dc77799698e4a77
2022-05-25 00:03:08 +00:00
Amir Sarabadani
24115a8f4c Start clean up of revision_actor_temp table
It is being dropped in production

Bug: T215466
Change-Id: I66b2cb8653252e720c897351065978119f040ba7
2022-05-23 15:37:42 +00:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
Aryeh Gregor
666ca1bdf3 Use MainConfigNames instead of string literals, #2
This covers all occurrences of /onfig->.*get( '/ in includes/.
Undoubtedly there are still plenty more to go.

Change-Id: I33196c4153437778496f40436bcde399638ac361
2022-04-13 18:55:46 +03:00
Umherirrender
6caf78c2c8 phan: Remove PhanPossiblyUndeclaredVariable suppression
Make phan stricter about conditional variable declaration
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T259172
Change-Id: I1f200ac37df7448453688bf464a8250c97313e5d
2022-03-30 19:47:15 +00:00
Amir Sarabadani
627c1c2c30 Allow setting max execution time to several special pages
These special pages and their counter-part APIs are:
 - Special:RecentChanges
 - Special:Watchlist
 - Special:Log
 - Special:Contributions

This also changes the way MAX_EXECUTION_TIME works from taking the value
as milliseconds, it takes seconds which is more intuitive for users.

Bug: T297708
Depends-On: I126e7181422d8da1a63afc3717faa4f72a687dd9
Change-Id: I3ff78751c3df3b6342f1865d35c2075f4415185d
2021-12-15 22:59:06 +01:00
Alexander Vorwerk
e73e07e85b Use inject Config in api modules and special pages
Replacing the usage of global vars with the usage of the injected
Config instance.

Change-Id: I90612b4dde9b76afb1bac4855274c03dcaf23044
2021-12-01 13:01:02 +00:00
Reedy
6c62b2164c s/necesssary/necessary/
Change-Id: I38e5ff8b5b84b0d96b9bbc3e168efe416016184b
2021-10-06 01:08:37 +01:00
Umherirrender
227e2432e1 Pass int[] to RevisionStore::getRevisionSizes
The database result is always a string, cast to int before passing to
getRevisionSizes, which is documented to take int[]

Change-Id: Iead5787a596e0264b769a97f1c79c1abe5c482f4
2021-09-28 23:25:58 +02:00
TChin
97716b4432 Rename where* methods in UserSelectQueryBuilder
Bug: T278254
Change-Id: I3f6d120b4426d8729b8db0336ce6db2b35163f71
2021-08-04 16:32:03 -04:00
Tim Starling
d3d8dc9965 Schema migration for revison_actor_temp table removal
Introduce a new schema migration stage in which rev_actor is used
directly and the revision_actor_temp table is no longer needed. This
becomes the new "new" stage whereas the previous situation is now
termed SCHEMA_COMPAT_TEMP.

Introduce migrateRevisionActorTemp which copies data from
revision_actor_temp to rev_actor. The code is similar to
migrateImageCommentTemp.php except that it doesn't delete from the old
table.

Partial revert of c29909e59f. That change removed direct
references to $wgActorTableSchemaMigrationStage and made queries
involving revision_actor_temp be unconditional. Such changes need to be
reverted to make the use of revision_actor_temp be conditional again.

In ActorMigrationTest, I compacted provideGetJoin() and
provideGetWhere(), removing most of the duplication between expected
values. I gave all the stages a short name, and mostly used the name in
providers.

Bug: T275246
Change-Id: I7498107dd6433ab7de5bf2e7b3fe2aa5e10e345d
2021-07-14 08:29:04 +10:00
Umherirrender
39cba91f57 api: Inject services into ApiQueryUserContribs
Bug: T259960
Change-Id: I8b49ad1b79f7764a59bf1aaa1e2416fb0e6d4af3
2021-07-04 00:19:13 +02:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
Vlad.shapik
9763c48d17 Reapply "Hard Deprecate User ::getCanonicalName, ::isUsableName, ::isCreatableName""
This reverts commit ecf826a2ee.

Reason for revert: need to edit the patch and then it will be GTG in order to finish hard deprecating of User ::getCanonicalName, ::isUsableName, ::isCreatableName

Change-Id: I2f57f56728fcbeada96dc2228f07dc8bcaa5d4f6
2021-05-31 16:01:36 +03:00