Commit graph

219 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
984076f98e Add namespace to includes/api classes
Bug: T353458
Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
2024-09-25 19:31:14 +00:00
Umherirrender
07db7102cc Replace deprecated LogFormatter::newFromRow/newFromEntry
Change-Id: I453ce3148a46fcb9cc5c685cee92274e0cb4f98a
2024-07-29 22:26:41 +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
Ebrahim Byagowi
03dc841a08 Add namespace and deprecation alias to WatchedItem
This patch introduces a namespace declaration for the
MediaWiki\Watchlist to WatchedItem and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Id2a582b624f21867240def2541c98ce5b1bd12b4
2024-05-17 13:26:36 +03:30
Taavi Väänänen
3f4cb7969d
api: Fix PSR2.Classes.PropertyDeclaration.Multiple errors
Change-Id: I7859191740d66d00595c4bdeea12b227ac25bcc5
2024-04-21 23:05:59 +03: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
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Daimona Eaytoy
7acfa6a0a5 Replace more instances of unchecked MWException
Most (all?) of the remaining usages are caught somewhere and will be
migrated later.

Bug: T328220
Change-Id: I5c36693a5361dd75b4f1e7a0bab5ad48626ed75c
2024-01-23 16:20:53 +00: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
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00: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
Bartosz Dziewoński
6ba47296d9 Fix Phan suppressions related to Title::castFrom*() and friends
There is no way to express that Title::castFromPageIdentity(),
Title::castFromPageReference() and Title::castFromLinkTarget()
can only return null when the parameter is null. We need to add
Phan suppressions or explicit types almost everywhere that these
methods are used with parameters that are known to not be null.

Instead, introduce new methods Title::newFromPageIdentity() and
Title::newFromPageReference() (Title::newFromLinkTarget() already
exists), without the null-coalescing behavior, and use them when
the parameter is not null. This lets static analysis tools, and
humans, easily understand where nulls can't appear.

Do the same with the corresponding TitleFactory methods.

Change the obvious uses of castFrom*() to newFrom*() (if there is
a Phan suppression, a type check, or a method call on the result).

Change-Id: Ida4da75953cf3bca372a40dc88022443109ca0cb
2023-04-22 16:45:09 +02: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
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
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
Umherirrender
20c3cc6ef1 Remove unused variable from unpacking arrays
Change-Id: Iac27cb4aa936cb494b3e491ce22c88c7fad375a1
2022-11-22 23:21:08 +00: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
910f8b526a Remove references to removed 'watchlist' query group
The 'watchlist' query group no longer exists in WMF production since
T263127, and it's not included in the list of supported query groups
in docs/database.md.

Change-Id: I6ea5c65921891ac6a705a6ff7e79b08fa5a9bf42
2022-08-16 20:33:43 +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
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
Umherirrender
555f50e13d api: Inject services into ApiQueryWatchlistRaw/ApiQueryWatchlist
Bug: T259960
Change-Id: I0c93fe4436be1d1703107bb049771ec6e0dc1b23
2021-07-03 21:59:08 +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
Petr Pchelko
0dfa846653 Use null coalecing operators everywhere consistenctly.
Auto-generated with rector.

Change-Id: I4f27e10cf029bb067b7bc57d82f7a64e21ea8d42
2021-06-03 21:42:06 -07:00
Tim Starling
fd01c53778 Stop using legacy ActorMigration field "rc_user"
Bug: T278917
Change-Id: I4d6c175c637a2cb26c63e0b2b27d5ea8ce6b1e0d
2021-04-28 16:29:04 +10:00
DannyS712
523342c781 Inject CommentStore service into api query modules
- ApiQueryBlocks
- ApiQueryDeletedrevs
- ApiQueryFilearchive
- ApiQueryLogEvents
- ApiQueryProtectedTitles
- ApiQueryRecentChanges
- ApiQueryUserContribs
- ApiQueryWatchlist

Bug: T259960
Change-Id: Ib7ee815fcea3e72523124eb6a2eaf20ad9565cfe
2021-04-23 15:09:48 +00:00
Cindy Cicalese
a78184782f Convert WatchedItem et al to PageIdentity
Change-Id: Iddcd109b7f78efdbcb0e4016e81fd2c8d4666b46
2021-03-26 15:51:19 -04:00
DannyS712
49748b461d ApiQueryWatchlist: Include log entry action text
Bug: T260227
Change-Id: Idced9e0e1271597cc1891b1b88e2c4b509a2ad52
2020-11-22 01:50:52 +00:00
DannyS712
9fefe2eac0 ApiQueryWatchlist: Allow requesting expiry
Add the `expiry` wlprop to get the timestamp with the
TS_ISO_8601 format. If the item doesn't expire, the
value is set to false.

Bug: T263796
Change-Id: I73f378f11662934255da4a41af9d1bc3d7b45030
2020-11-20 06:24:51 +00:00
Thiemo Kreuz
08cf4c49df Add PHPDoc documentation to all API query module constructors
Change-Id: I2bc140576efc891bb9b6e50e44041d5bb022ac8f
2020-10-27 19:16:41 +00:00
jenkins-bot
cf29d50e0d Merge "ApiQueryWatchlist: set anon flag as false when relevant instead of omitting" 2020-08-07 19:56:49 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Tim Starling
a06e3d06b1 Fix some PHPStorm inspection warnings in includes/api
Notably:
* In ApiManageTags, I used a switch instead of a dynamic function name,
  so that the call graph will be correct.
* In ApiImageRotate, checkTitleUserPermissions() has always returned
  void, this was an error introduced in 4e6810e4a2

Change-Id: Iea22616b8e7e2e0cc804619a54f8690898b2cb82
2020-02-18 14:17:37 -05:00
Brad Jorsch
c2b1525908 API: Use ParamValidator library
This brings significant modularization to the Action API's parameter
validation, and allows the Action API and MW REST API to share
validation code.

Note there are several changes in this patch that may affect other code;
see the entries in RELEASE-NOTES-1.35 for details.

Bug: T142080
Bug: T232672
Bug: T21195
Bug: T34675
Bug: T154774
Change-Id: I1462edc1701278760fa695308007006868b249fc
Depends-On: I10011be060fe6d27c7527312ad41218786b3f40d
2020-02-04 13:36:14 -05:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
DannyS712
34bb5c3cf2 ApiQueryWatchlist: set anon flag as false when relevant instead of omitting
Bug: T239883
Change-Id: Ie88b95c4a62fb4a036d0efd6878ada12a6482d45
2019-12-05 02:08:33 +00:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Umherirrender
731d9f748e Run GenderCache for api query modules using ApiQueryBase::addTitleInfo
When converting a Title object into a string for user or user talk
namespace the gender information are needed.

This patch set improves performance on wikis with gender distinction
like dewiki or ruwiki by combining the fetch of the information into one
query and avoids a query per unique user name.
It also avoids false results for request with apihighlimit, because the
apihighlimit with 5000 is higher than the query max limit of the
GenderCache with 1000

Bug: T200238
Change-Id: Ibe0561b210dbeb654117dad777e839640f51b4e4
2019-11-02 22:23:23 +01:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Max Semenik
e6818e6c64 Fix unused vars/pointless assignments
Change-Id: If475c738b4af7208024c866594d4c0048af053dd
2019-03-29 16:52:48 -07:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
Brad Jorsch
dff469a408 Re-namespace RevisionStore and RevisionRecord classes
During development a lot of classes were placed in MediaWiki\Storage\.
The precedent set would mean that every class relating to something
stored in a database table, plus all related value classes and such,
would go into that namespace.

Let's put them into MediaWiki\Revision\ instead. Then future classes
related to the 'page' table can go into MediaWiki\Page\, future classes
related to the 'user' table can go into MediaWiki\User\, and so on.

Note I didn't move DerivedPageDataUpdater, PageUpdateException,
PageUpdater, or RevisionSlotsUpdate in this patch. If these are kept
long-term, they probably belong in MediaWiki\Page\ or MediaWiki\Edit\
instead.

Bug: T204158
Change-Id: I16bea8927566a3c73c07e4f4afb3537e05aa04a5
2018-10-09 10:22:48 -04:00
Brad Jorsch
07842be379 API: Update query modules for MCR
MCR deprecated the Revision class in favor of the broadly similar
RevisionRecord, and more interestingly added the concept of multiple
content "slots" to revisions.

Thus, prop=revisions, prop=deletedrevisions, and so on gain a parameter
to specify which slots are wanted. When this new parameter is not
specified (and any content-related props are specified), a warning about
the legacy format will be issued.

The rest of the modules just needed to call methods or use constants on
RevisionRecord instead of Revision. ApiQueryDeletedrevs wasn't touched,
since it has been deprecated since 1.25 anyway.

This also updates a few non-query modules that don't depend on details
of editing, diffing, or viewing MCR revisions that haven't been figured
out yet.

Bug: T200568
Change-Id: I1327d1784f5cedb006cd74df834cf9a560a77a5d
2018-07-27 23:33:45 +00:00
Amir Sarabadani
00a4f0939c Replace rc_patrolled values with contants, part I
This constants has been recently introduced and it's good to use them

Change-Id: I8ce56dc95de3e49610dca71c00965ca1ac74bcf0
2018-04-11 22:35:31 +02:00
Amir Sarabadani
728321e113 Make autopatrol third option in rc_patrolled and use it in API
Bug: T184791
Change-Id: If64ba8b845b122a87f20646dddf72ef257b793cb
2018-04-03 18:44:37 +02:00
addshore
e5879da149 Pass $key into CommentStore methods and use MediawikiServices
This allows CommentStore to be added to MediaWikiServices
without the need of an aditional Factory.

This change includes a compatability layer to allow the behaviour
from 1.30 to continue to be used while deprecated.

CommentStore::newKey has been deprecated.
Keys are now passed into the public methods of CommentStore
where needed.
The following CommentStore methods have had their signatures changed
to introduced a $key parameter, but when used in conjunction with
CommentStore::newKey behaviour will remain unchanged:
  * CommentStore::getFields
  * CommentStore::getJoin
  * CommentStore::getComment
  * CommentStore::getCommentLegacy
  * CommentStore::insert
  * CommentStore::insertWithTemplate

Change-Id: I3abb62a5cfb0dcd456da9f4eb35583476ae41cfb
2018-02-05 15:34:12 +00:00