aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiOptions.php
Commit message (Collapse)AuthorAgeFilesLines
* api: Use type declaration on undocumented private functionsUmherirrender2025-04-041-1/+1
| | | | Change-Id: I2998ad3ccc5a54eccfe36ad09fe509e83dfb719c
* api: Use type-declaration for string arg in ApiBase::__constructUmherirrender2024-10-171-7/+1
| | | | | | | Also for all sub-classes Remove simple doc-blocks without further information Change-Id: I981934efe32d44f52e5ab865a9b887be5bd0f41e
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-2/+2
| | | | | | | | | | | 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
* Add namespace to includes/api classesJames D. Forrester2024-09-251-0/+5
| | | | | Bug: T353458 Change-Id: I3ea6b08c5018ba03ba45c5766e1f46e12f6b8597
* user: Add "global" parameter to ApiOptionsTim Starling2024-06-131-1/+36
| | | | | | | | | Add a "global" parameter to ApiOptions which allows it to update or override global preferences. Bug: T323076 Depends-On: I686c0091768ed330683fff89201fae4f93b8a1c4 Change-Id: Ieb2d0c0d0da5c51b2a47ed8a967a47b4e7ad4577
* user: Split a base class out of ApiOptionsTim Starling2024-06-121-210/+8
| | | | | | | | | | | 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
* user: Move "reset kinds" concept to PreferencesFactoryTim Starling2024-06-111-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Move user options related classes into its own namespaceMartin Urbanec2023-11-291-1/+1
| | | | | | | | | | | | | 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
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-191-0/+1
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* Use real type hints for services etc. in api/ except ApiQuery*.phpBartosz Dziewoński2023-08-291-5/+2
| | | | | | | | | | | | | | | 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
* Make ApiOptions unavailable to temporary userscsimiyu2023-03-281-1/+1
| | | | | Bug: T332414 Change-Id: I7646f8a80309b739e647558a971725b9e59f3b06
* ApiOptions: Give warning if the value is too longFunc2023-01-201-0/+8
| | | | | | | | | | | | 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
* api: Fix minor PHP 8.1 incompatibility in ApiOptionsthiemowmde2022-11-081-2/+2
| | | | | | | | The value can apparently be null. String functions don't accept null any more in PHP 8.1. Bug: T289926 Change-Id: I32d558b8c710c55d08cb3496d70a489004407be0
* api: Replace numerous deprecated constantsReedy2022-06-061-6/+7
| | | | Change-Id: I34ffcb70efbfa257da8dab6e0790aa0d697caf5b
* Re-apply "preferences: Use a faster and simpler form descriptor when validating"Func2022-03-101-1/+2
| | | | | | | | | | | | | | | | | | | Previously attempted in 07b4daf85db7a88b57a91cfaba75f63348f65f69, reverted in 8763d8e91197b65583ea0473caa9a7724c79d75b. 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
* Revert "preferences: Use a faster and simpler form descriptor when validating"Krinkle2022-03-011-2/+1
| | | | | | | | | | | | This reverts commit 07b4daf85db7a88b57a91cfaba75f63348f65f69. 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
* preferences: Use a faster and simpler form descriptor when validatingFunc2022-02-241-1/+2
| | | | | | | | | | | | 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
* Load fields for validation of user options in one goFunc2022-01-311-6/+3
| | | | | | 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
* api: Replace deprecated User::getOptionKinds/resetOptions in ApiOptionsUmherirrender2021-07-021-3/+3
| | | | | Bug: T277600 Change-Id: I66320d906f735fa3edadfa29a14d6699d159d400
* api: Inject PreferencesFactory into ApiOptionsUmherirrender2021-07-021-4/+11
| | | | Change-Id: I6242f5018075e1500d87c8375c971b383aba41f6
* api: Change User::isAnon to User::isRegisteredUmherirrender2021-06-291-1/+1
| | | | | | User::isRegistered is also usable with UserIdentity Change-Id: I49ee864e9b080d324b11eb8cbbcc9aa5f6ca0470
* Hard deprecate User::listOptionKinds()ZabeMath2021-06-221-2/+2
| | | | | | | deprecated since 1.35 and unused. Bug: T274211 Change-Id: I139ef1de149c94148ad07c62a8c024e4cb0ee053
* Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variablesJames D. Forrester2021-05-141-1/+1
| | | | | | | This is just a start. Bug: T254646 Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
* Hard deprecate User ::isIP, ::getOptionsvladshapik2021-04-261-1/+23
| | | | | Bug: T275602 Change-Id: Id4be13751ca0a900e51214c1855a4624077a5a62
* Improve docs in api related classesUmherirrender2020-11-131-1/+1
| | | | Change-Id: I78338d48530f098fa5d36fe84cfd45c0d160f444
* ApiOptions: fix substr call in loggingdaniel2020-09-231-2/+2
| | | | | Bug: T259073 Change-Id: I48558d2dd1aea78d7bc8d25e5807b5ebf25dc988
* ApiOptions: log when userjs-* option changesdaniel2020-09-151-0/+15
| | | | | Bug: T259073 Change-Id: I99b9f224d3c0c21ef22a0ffa98ad2f72bf300943
* Remove PreferencesFactory::setUser()Sam Wilson2020-06-081-2/+0
| | | | | | | | | | | 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
* Hooks::run() call site migrationTim Starling2020-05-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Add PreferencesFactory::setUser()Sam Wilson2020-05-061-0/+2
| | | | | | | | | | 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
* New hook ApiOptionsMax Semenik2018-10-171-3/+11
| | | | | | | | We need it to inform API clients they're changing globally overridden preferences. Bug: T198913 Change-Id: I692a1fb42b73d72814f31bfe9bd400c65f59d83c
* ApiOptions: fix resetting some preferences to defaultMax Semenik2018-10-011-5/+11
| | | | | | | | | | 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
* Refactor ApiOptions for reusabilityMax Semenik2018-06-261-15/+56
| | | | | | | | | 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
* Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenientBartosz Dziewoński2018-05-301-2/+2
| | | | | | | | | | | | | | 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
* Remove "Created on" from file header commentsUmherirrender2018-01-261-4/+0
| | | | | | | | | 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
* Fix called function case in a bunch of placesMax Semenik2018-01-221-1/+1
| | | | Change-Id: If1e392290a5bab3bce389f7da692e53a748b8aff
* Convert Preferences class into PreferencesFactory serviceSam Wilson2018-01-031-1/+4
| | | | | | | | | | | 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
* API: Account for PHP 7.2 changeBrad Jorsch2017-12-041-1/+1
| | | | | | | | | | 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
* Make API documentation links language awareBaha2017-04-051-1/+1
| | | | | | | | | | | | | | 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
* API: i18n for warnings and errorsBrad Jorsch2016-12-061-11/+15
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* ApiOptions: set form field parent earlierGergő Tisza2016-05-041-2/+1
| | | | | Bug: T134351 Change-Id: I44b9bbd1663c876cf0c6160f10badfd8f380656b
* Use single quotes in API where possibleSiebrand Mazeland2016-03-081-5/+5
| | | | Change-Id: I972e296f4820f78f5dfcecc27bc4912ca84a3178
* Convert all array() syntax to []Kunal Mehta2016-02-171-15/+15
| | | | | | | | | | 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
* Avoid "CAS updated failed" errors on Special:Preferences double postAaron Schulz2015-12-151-12/+6
| | | | | | | | | | | * 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
* Avoid CAS errors on double post to ApiOptionsAaron Schulz2015-09-241-1/+1
| | | | | Bug: T95839 Change-Id: I62f8eea31164be1ab0eacf31c494f0b296b367f2
* Load User via READ_LATEST in ApiOptions to avoid CAS errorsAaron Schulz2015-08-261-0/+8
| | | | | Bug: T95839 Change-Id: I3c4cf4347af24f3313e709a996618b755da22dd2
* API: Set HTMLForm when validating field in ApiOptionsBrad Jorsch2015-04-201-0/+6
| | | | | Bug: T96583 Change-Id: I09507990827581b587c14b0f7283cdf0dc21436a
* API: Fix access on getExamplesMessagesBrad Jorsch2014-10-291-1/+1
| | | | | | | ApiBase declares it protected, but for some reason I had made it public in all subclasses. Change-Id: I8a50d4f47e66c7f09137968d3941dc5cdc1d28e4
* API: Internationalize all remaining core API modulesBrad Jorsch2014-10-201-29/+8
| | | | | | | | | 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
* API: Overhaul token handlingBrad Jorsch2014-08-261-10/+1
| | | | | | | | | | | | | | | | | | | | 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