Commit graph

74 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
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +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
Tim Starling
b4591f1960 user: Add "global" parameter to ApiOptions
Add a "global" parameter to ApiOptions which allows it to update or
override global preferences.

Bug: T323076
Depends-On: I686c0091768ed330683fff89201fae4f93b8a1c4
Change-Id: Ieb2d0c0d0da5c51b2a47ed8a967a47b4e7ad4577
2024-06-13 15:22:47 +00:00
Tim Starling
ca615f369a user: Split a base class out of ApiOptions
This gives us the flexibility to add features to core without
affecting GlobalPreferences.

Split getUserForUpdates() into asserting and non-asserting variants
since most things are using it without checking for a null return.

Bug: T323076
Change-Id: I53e5c409a650397fde03a8578b0182f0b97927a9
2024-06-12 02:08:49 +00:00
Tim Starling
94151fcde9 user: Move "reset kinds" concept to PreferencesFactory
Fix the dependency loop between PreferencesFactory and
UserOptionsManager by moving the concept of "reset kinds" or "option
kinds" to PreferencesFactory.

Note that this is a half-baked feature from 2013 (I5f9ba5b0dfe7c2ea)
that is not really used for anything. Apparently only the "all" and
"unused" kinds are used.

The strong dependencies on PreferencesFactory internal details show that
this feature belongs in PreferencesFactory. But UserOptionsManager can
reset "all" preferences without help from PreferencesFactory, so add a
helper for that.

The rationale for putting it in UserOptionsManager was that eventually
all preference definition information should move to UserOptionsManager
(T250822). I don't agree with that. UserOptionsManager is the key/value
store which backs PreferencesFactory. I need to refactor it further for
T323076 and it will help to have these concepts be separate.

Hard-deprecate UserOptionsManager methods resetOptions, listOptionKinds
and getOptionKinds. Add convenience methods to replace calls to
resetOptions().

I couldn't understand the logic in resetOptions(). Why was it copying
old values instead of just omitting them? Why was it assigning null but
only for "all"? setOption() had a documented method for resetting an
option to the default, so I just used that.

Bug: T323076
Depends-On: I1ed0a1a9f6492fb50254104fa4bc9f2130218323
Change-Id: I900fd4a48c96d91491eae54824e7bf02a004843d
2024-06-11 23:50:21 +00:00
Martin Urbanec
29af4dd074 Move user options related classes into its own namespace
There are a couple of user options related classes already,
and the T321527 work on dynamic defaults is going to add
even more. Let's move them into a separate namespace
to make core a bit more organized.

Old name is kept as an alias for compatibility purposes.

Bug: T321527
Bug: T352284
Change-Id: I9822eb1553870b876d0b8a927e4e86c27d83bd52
2023-11-29 13:27:13 +01:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00
Bartosz Dziewoński
365a588238 Use real type hints for services etc. in api/ except 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: I6ec7587607df4f1a4f448a096c3e44c4e5270b70
2023-08-29 01:04:26 +00:00
csimiyu
d3b508c2b0 Make ApiOptions unavailable to temporary users
Bug: T332414
Change-Id: I7646f8a80309b739e647558a971725b9e59f3b06
2023-03-28 16:45:19 +03:00
Func
ce41bdd521 ApiOptions: Give warning if the value is too long
I was thinking add validations to HTMLApiField and other field types
if any, but then I found one field type that hard to implement proper
length validation, which is used for the `email-blacklist` preference.

The API will not save options that exceed the limit after this patch,
as if the validation is done by respective html fields.

Bug: T326696
Change-Id: Ib6b04db33bc6a806a49a16a1797c191faf5fb59d
2023-01-20 14:35:25 +08:00
thiemowmde
007c4ac9ba api: Fix minor PHP 8.1 incompatibility in ApiOptions
The value can apparently be null. String functions don't accept null
any more in PHP 8.1.

Bug: T289926
Change-Id: I32d558b8c710c55d08cb3496d70a489004407be0
2022-11-08 12:25:05 +01:00
Reedy
0b5084f868 api: Replace numerous deprecated constants
Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
2022-06-06 00:18:50 +01:00
Func
ab3ff34c47 Re-apply "preferences: Use a faster and simpler form descriptor when validating"
Previously attempted in 07b4daf85d,
reverted in 8763d8e911.

Message parsing used to be the biggest part of loads during
DefaultPreferencesFactory::loadPreferenceValues(), since it need to
load form fields to validate existing user preferences.

Message names in form descriptor can be unset as much as possible,
but special cases should be carefully handled.

The attempt of loading value for info fields is skipped to avoid
issues described in T302643.

Bug: T58633
Bug: T302643
Change-Id: I05dcfd60d4103b447dea71851b8e4db9a5d0e1e6
2022-03-10 23:00:53 +00:00
Krinkle
8763d8e911 Revert "preferences: Use a faster and simpler form descriptor when validating"
This reverts commit 07b4daf85d.

Due to the new method being used in both the API, and in the
loadPreferenceValues method (which is used by the main pref UI), this
change is not easy to reason about and is much wider in impact than
I had thought. More research and understanding is needed.

Bug: T302643
Change-Id: Ic420bc16ac5de8ce90343926e9c73815f3ff7479
2022-03-01 19:33:30 +00:00
Func
07b4daf85d preferences: Use a faster and simpler form descriptor when validating
Message parsing used to be the biggest part of loads during
DefaultPreferencesFactory::loadPreferenceValues(), since it need to
load form fields to validate existing user preferences.

Message names in form descriptor can be unset as much as possible,
but special cases should be carefully handled.

Bug: T58633
Change-Id: I1b5c2331e6d5a63f296b4147a91aecb39abf3530
2022-02-24 18:16:43 +00:00
Func
970518abf9 Load fields for validation of user options in one go
There will be some checks for the existence of fields referred by cond-state, fields in the same descriptor should be loaded in one go.

Change-Id: Ie3c4c1b35fc33d738dea8ca168ab8f07063f7a59
2022-01-31 16:19:03 +00:00
Umherirrender
44a2f83f37 api: Replace deprecated User::getOptionKinds/resetOptions in ApiOptions
Bug: T277600
Change-Id: I66320d906f735fa3edadfa29a14d6699d159d400
2021-07-02 16:17:07 +02:00
Umherirrender
c7e223e08d api: Inject PreferencesFactory into ApiOptions
Change-Id: I6242f5018075e1500d87c8375c971b383aba41f6
2021-07-02 14:21:50 +02:00
Umherirrender
191d68b11e api: Change User::isAnon to User::isRegistered
User::isRegistered is also usable with UserIdentity

Change-Id: I49ee864e9b080d324b11eb8cbbcc9aa5f6ca0470
2021-06-29 17:18:41 +02:00
ZabeMath
4020306bf7 Hard deprecate User::listOptionKinds()
deprecated since 1.35 and unused.

Bug: T274211
Change-Id: I139ef1de149c94148ad07c62a8c024e4cb0ee053
2021-06-22 15:56:25 +02:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
vladshapik
9cc797695b Hard deprecate User ::isIP, ::getOptions
Bug: T275602
Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
2021-04-26 16:10:24 +00:00
Umherirrender
083a0e57cb Improve docs in api related classes
Change-Id: I78338d48530f098fa5d36fe84cfd45c0d160f444
2020-11-13 23:11:06 +01:00
daniel
dca38b386e ApiOptions: fix substr call in logging
Bug: T259073
Change-Id: I48558d2dd1aea78d7bc8d25e5807b5ebf25dc988
2020-09-23 11:54:19 +02:00
daniel
36127ffd9d ApiOptions: log when userjs-* option changes
Bug: T259073
Change-Id: I99b9f224d3c0c21ef22a0ffa98ad2f72bf300943
2020-09-15 16:50:03 +02:00
Sam Wilson
5e0fd6d664 Remove PreferencesFactory::setUser()
This method was recently added and was to result in the deprecation
of a few places where User objects were being passed to the factory.
This has now been reconsidered and this patch reverts to the
previous behaviour. It is largely a revert of Ie1bed9e9537cabc836992ccfa7fb127885ea3e11

Bug: T238466
Depends-On: Idc9f33fd5ab55bde88cc306ca63adead286380a8
Change-Id: I3653559704ccfd9bca0946f5a865be93bdf5ceb6
2020-06-08 00:27:04 +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
Sam Wilson
36defc20eb Add PreferencesFactory::setUser()
Add a new setUser() method to PreferencesFactory so that a User
object doesn't have to be passed around so much. This is how
GlobalPreferencesFactory has done it, and so after this change
that code can be removed from GlobalPreferences.

Bug: T238466
Change-Id: Ie1bed9e9537cabc836992ccfa7fb127885ea3e11
2020-05-06 09:04:08 +08:00
Max Semenik
0ae317bcc7 New hook ApiOptions
We need it to inform API clients they're changing globally overridden
preferences.

Bug: T198913
Change-Id: I692a1fb42b73d72814f31bfe9bd400c65f59d83c
2018-10-17 18:02:20 -07:00
Max Semenik
3ea7bba4d4 ApiOptions: fix resetting some preferences to default
For preferences like 'skin' that have a limited number of values, null
is not a valid value, thus attempts to reset them fail with
"Validation error for \"skin\": This value is required."

Bug: T65080

Change-Id: I86554a6d30c8ab970740d8682fb2261476de0677
2018-10-01 15:48:19 -07:00
Max Semenik
3840b8a17e Refactor ApiOptions for reusability
Because GlobalPreferences needs an API and that API needs to behave like
this one, it makes sense to make them share code. Move some functionality
into separate functions to make this possible.

Bug: T62856
Change-Id: Ic64934e7f7226a309d71c22626119ea233e2caeb
2018-06-26 15:46:40 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Umherirrender
c9d303d39e Remove "Created on" from file header comments
It is the job of git and svn to provide this information/metadata.
The form was different, some with short, some with long month name
some with leading zero at the day, some without.
The year is also present in the Copyright clause

Change-Id: If006907b82b9e45f13cfa2e45d41107a95570e1a
2018-01-26 23:12:40 +00:00
Max Semenik
36e6ab15da Fix called function case in a bunch of places
Change-Id: If1e392290a5bab3bce389f7da692e53a748b8aff
2018-01-22 09:10:09 -08:00
Sam Wilson
2e248f0bb2 Convert Preferences class into PreferencesFactory service
This deprecates the Preferences class and replaces it with
a PreferencesFactory service. Basically, all code from Preferences
is moved into DefaultPreferencesFactory. All Prefereces methods
are now either shims calling DefaultPreferencesFactory or just
throw exceptions.

Bug: T178449
Change-Id: Id0b2db0c2de0890f6e1609a9a0dca207c4600f99
2018-01-03 09:48:25 +08:00
Brad Jorsch
9f86261000 API: Account for PHP 7.2 change
PHP 7.2 broke existing functionality in making count( null ) raise a
warning. So add tests for null all over the place, or change tests where
we know the value is null or an array (but not false, empty-string, or
0) to just cast to boolean.

Bug: T182004
Change-Id: Idfe23a07daa9f60eee72f2daf04304be87057a29
2017-12-04 13:46:33 -05:00
Baha
036b9c4167 Make API documentation links language aware
Links generated by the API are now aware of the user's preferred
language and will show documents in that language if available.

To test, log in to mediawiki.org and set your language preference to 'es',
then on an MediaWiki installation with this patch view the generated
expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`.
Each link to documentation on mediawiki.org should take you to its
translated /es subpage, if one exists.

Bug: T104518
Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
2017-04-05 11:08:25 -04:00
Brad Jorsch
4e6810e4a2 API: i18n for warnings and errors
API warnings and error messages are currently hard-coded English
strings. This patch changes that.

With a few exceptions, this patch should be compatible with non-updated
extensions:
* The change to ApiBase::$messageMap will blow up anything trying to
  mess with it.
* The changes to the 'ApiCheckCanExecute' hook will cause a wrong
  (probably unparsed) error message to be emitted for extensions not
  already using an ApiMessage. Unless they're currently broken like
  Wikibase.

Bug: T37074
Bug: T47843
Depends-On: Ia2b66b57cd4eaddc30b3ffdd7b97d6ca3e02d898
Depends-On: I2e1bb975bb0045476c03ebe6cdec00259bae22ec
Depends-On: I53987bf87c48f6c00deec17a8e957d24fcc3eaa6
Depends-On: Ibf93a459eb62d30f7c70d20e91ec9faeb80d10ed
Depends-On: I3cf889811f44a15935e454dd42f081164d4a098c
Depends-On: Ieae527de86735ddcba34724730e8730fb277b99b
Depends-On: I535344c29d51521147c2a26c341dae38cec3e931
Change-Id: Iae0e2ce3bd42dd4776a9779664086119ac188412
2016-12-06 10:20:48 -05:00
Gergő Tisza
93c5cc236a ApiOptions: set form field parent earlier
Bug: T134351
Change-Id: I44b9bbd1663c876cf0c6160f10badfd8f380656b
2016-05-04 17:09:18 +02:00
Siebrand Mazeland
bc0ae710e3 Use single quotes in API where possible
Change-Id: I972e296f4820f78f5dfcecc27bc4912ca84a3178
2016-03-08 17:27:00 +01:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Aaron Schulz
b046b93d93 Avoid "CAS updated failed" errors on Special:Preferences double post
* This does the same thing ApiOptions does to avoid these errors.
  A new getInstanceForUpdate() method is now in the User class to
  simplify this pattern.
* Avoid overriding $user in ApiOptions for code readability.
* Fixed IDEA errors around Preferences::getFormObject() return type.

Bug: T95839
Change-Id: If2385b7486c043bd70d7031ff35e37dfb079a4d2
2015-12-15 02:50:16 +00:00
Aaron Schulz
ece85dd20f Avoid CAS errors on double post to ApiOptions
Bug: T95839
Change-Id: I62f8eea31164be1ab0eacf31c494f0b296b367f2
2015-09-24 23:19:06 -07:00
Aaron Schulz
129586e1d9 Load User via READ_LATEST in ApiOptions to avoid CAS errors
Bug: T95839
Change-Id: I3c4cf4347af24f3313e709a996618b755da22dd2
2015-08-26 13:48:49 -07:00
Brad Jorsch
d2631d1740 API: Set HTMLForm when validating field in ApiOptions
Bug: T96583
Change-Id: I09507990827581b587c14b0f7283cdf0dc21436a
2015-04-20 15:57:42 -04:00
Brad Jorsch
f62bc7536e API: Fix access on getExamplesMessages
ApiBase declares it protected, but for some reason I had made it public
in all subclasses.

Change-Id: I8a50d4f47e66c7f09137968d3941dc5cdc1d28e4
2014-10-29 11:15:27 -04:00
Brad Jorsch
ad225f501c API: Internationalize all remaining core API modules
This also adds some new ApiBase::PARAM_* constants to generate more
helpful help, and a method to override the default description message
for the use of ApiDisabled and ApiQueryDisabled.

Bug: 71638
Change-Id: Ic0c3d232e0498d58a043037e2e0c6f0b1c3edad3
2014-10-20 16:56:35 -04:00
Brad Jorsch
fdddf94570 API: Overhaul token handling
The current token handling is a mess. This simplifies things greatly:
* *All* tokens are obtained from action=query&meta=tokens, rather than
  being spread over action=tokens, action=query&prop=info,
  action=query&prop=revisions, action=query&prop=recentchanges, and
  action=query&prop=users. All these old methods are deprecated.
* Similarly, there is only one hook to register new token types. All old
  hooks are deprecated.
* All tokens are cacheable.
* Most token types are dropped in favor of a 'csrf' token. They already
  were returning the same token anyway.
* All token-using modules will document the required token type in a
  standard manner in action=help and are documented in machine-readable
  fashion in action=paraminfo.

Note this will require updates to all extensions using tokens.

Change-Id: I2793a3f2dd64a4bebb0b4d065e09af1e9f63fb89
2014-08-26 14:53:45 -04:00
Brad Jorsch
f0a6435f3b API: Remove action=paraminfo 'props' and 'errors' result properties
The format for 'props' was never specified and the list for 'errors' is
impossible to keep updated when considering that many errors come from
MediaWiki backend code and extension hook functions. And since there
doesn't seem to be any real use case for either of these, let's just
kill both of them instead of wasting effort on trying to fix them.

Note that neither getResultProperties nor getPossibleErrors are called
from any extensions in gerrit, and none of the other deprecated methods
are called outside of the implementations of those two methods. Removing
the obsolete methods is left to the maintainers of the extensions, as
keeping them hurts nothing and is needed to maintain compatibility with
earlier versions of MediaWiki.

Change-Id: Ie11a401d60c834059fbf1b5625ca8ea093b3337c
2014-08-07 16:51:19 +01:00