aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Settings
Commit message (Collapse)AuthorAgeFilesLines
* Use type declaration on undocumented private functionsUmherirrender2025-04-021-2/+2
| | | | Change-Id: I0d8d2237500ed6f18439410c902d47c42e4119bc
* Replace call_user_func with dynamic function callUmherirrender2025-02-131-1/+1
| | | | | | | | Use modern php syntax to call a callable. Reduce the stack trace to improve performance and better IDE and static analyzer support Change-Id: I9ef131032a662a3b8db69aa7079dbd51f88f575a
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-179-45/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* Remove trivial 1-line PHPDocs that just repeat the codethiemowmde2025-01-164-12/+0
| | | | | | | | | | | | | I assume these are all either auto-generated by an IDE or the language-level type declarations have been added later. In any case the comments don't add any new information to what the code already says. This is just extra clutter that makes the code harder to read, I would argue. There are many, many more comments like this. In this patch I intentionally focus on the most trivial 1-line comments. Change-Id: Ia294bf4ce0d8a77036842fe25884bc175c2b0e7d
* config schema: Improve validation for array typesAmmarpad2025-01-031-1/+19
| | | | | | | | | | | | | | This patch does two things: 1. Be forgiving about associative arrays with numeric keys. This is because lists can unintentially become associative arrays (as a result of side effect) and discarding the keys is not a problem. 2. Correct the spurious error message for truly associative arrays with non-numeric string keys. Bug: T322131 Change-Id: I870218023093305a8f414d4de1a73282b5f53b9a
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-165-7/+7
| | | | | | | | | | | 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
* Remove meaningless @var documentation from constantsthiemowmde2024-10-092-12/+0
| | | | | | | | | A constant is not a variable. The type is hard-coded via the value and can never change. While the extra @var probably doesn't hurt much, it's redundant and error-prone and can't provide any additional information. Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
* Use type declaration for class properties holding type hinted argumentsUmherirrender2024-09-111-1/+1
| | | | | | | Provided arguments already have type declaration on the construtor and it is safe to use the same type on the class property Change-Id: Ia8bbdc4dee59dfb487582dd514486ec8542951be
* Add MediaWiki\Registration namespace to registration classesEbrahim Byagowi2024-08-101-1/+1
| | | | | Bug: T353458 Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
* Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-102-2/+2
| | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* Add "implements Stringable" to every class with "function __toString()"Bartosz Dziewoński2024-06-138-8/+17
| | | | | | | | | | | | | In PHP 8, but not in PHP 7.4, every class with a __toString() function implicitly implements the Stringable interface. Therefore, the behavior of checks like "instanceof Stringable" differs between these PHP versions when such classes are involved. Make every such class implement the interface so that the behavior will be consistent. The PHP 7.4 fallback for the Stringable interface is provided by symfony/polyfill-php80. Change-Id: I3f0330c2555c7d3bf99b654ed3c0b0303e257ea1
* JsonSchemaTrait: Add support for inlined referencesMartin Urbanec2024-04-292-12/+52
| | | | | | | | | | | | | | | | | In I130326e5762e706be4889e308eeec45a6c7683c5 we introduced support for json schema references. In some use cases it may be more suitable to compute the references and inline them in the resulting schema. Introduce an $inlineReferences flag to do so. Possible follow-up: Memorization of already resolved and normalized references could speed up the full schema processing, T363678. Bug: T362098 Co-Authored-by: Sergio Gimeno <sgimeno@wikimedia.org> Change-Id: I570faddca7216a65db2e8e70b12997bf7b5a2933
* JsonSchemaTrait: normalize resolved referencesSergio Gimeno2024-04-262-61/+52
| | | | | | | | | | | | | | | | | | | | | | Why: In I130326e5762e706be4889e308eeec45a6c7683c5 we introduced support for json schema references by traversing and resolving any schema with a $ref property. However the change missed to normalize the resolved references along the process resulting in invalid json schema documents with a $ref property of shape: ["class" => 'SomeClass', 'field' => 'SomeField' ] instead of a json pointer string to the reference in the document: "#defs/SomeClass/SomeField" What: Instead of spinning a separate reference traversal for each $ref'ing schema, compute only the current node reference and recursively call normalizeJsonSchema on the resolved reference (aka definition) Bug: T363111 Change-Id: Ic1b11eddebcdd546412ea9f27f3e037d5c242d64
* JsonSchemaReferenceResolver: Improve styling and docstringMartin Urbanec2024-04-053-3/+14
| | | | | | | Per feedback in I130326e5762e706be4889e308eeec45a6c7683c5. Bug: T357718 Change-Id: Ib1653daa0c374417f8aa4d00b5babb899bff94fa
* ReflectionSchemaSource: Add loadAsSchema()Martin Urbanec2024-04-051-1/+31
| | | | | | | Follow-up to I130326e5762e706be4889e308eeec45a6c7683c5. Bug: T357718 Change-Id: I58590f442850418752493ef78475bb1f034f6d42
* ReflectionSchemaSource: add support for JSON schema $refsSergio Gimeno2024-04-055-6/+172
| | | | | | | | | | | | | | | | | | | | | | | Why: supporting JSON schema $refs is desired for the CommunityConfiguration 2.0 project so configuration schemas can reuse definitions coming from another PHP JsonSchema class. The https://json-schema.org/ specification supports relative and absolute URIs as the content of a $ref. The change aims to support only the former. Meaning that any $ref defined in a schema should point to a class that can be resolved by PHP. What: update schema traversing in JsonSchemaTrait to resolve any reference specified as: [ 'class' => SomeClass:class, 'field' => 'someClassField' ] into an actual json schema compliant $ref, eg: $ref: '#/$defs/SomeDefinitionName'. Also annotate new definitions found in a "$defs" array with the resolved value of the refed class field. Bug: T357718 Change-Id: I130326e5762e706be4889e308eeec45a6c7683c5
* build: Upgrade mediawiki/mediawiki-phan-config from 0.13.0 to 0.14.0 manuallyJames D. Forrester2024-02-101-1/+0
| | | | | | | | | | | * Switch out raw Exceptions, mostly for InvalidArgumentExceptions. * Fake exceptions triggered to give Monolog a backtrace are for some reason "traditionally" RuntimeExceptions, instead, so we continue to use that pattern in remaining locations. * Just entirely give up on PostgresResultWrapper's resource vs. object mess. * Drop now-unneeded false positive hits. Change-Id: Id183ab60994cd9c6dc80401d4ce4de0ddf2b3da0
* Use typed properties in Settings classesDoğu Abaris2024-01-313-10/+4
| | | | | | | | | | | | | | This patch updates several Settings classes within the includes/Settings directory to use typed properties, thus simplifying the codebase by removing explicit docblock annotations for class properties. - DynamicDefaultValues.php: Convert $configSchema property to use typed property syntax. - LocalSettingsLoader.php: Apply typed property syntax to $settingsBuilder and $baseDir. - WikiFarmSettingsLoader.php: Switch $settingsBuilder to typed property. Change-Id: Iec8ee9c91362d13f49dea65f314d5c1113a19306
* Merge "Replace unspecific exceptions with InvalidArgumentException"jenkins-bot2024-01-211-2/+3
|\
| * Replace unspecific exceptions with InvalidArgumentExceptionthiemowmde2024-01-201-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A LogicException is very generic and doesn't mean much. An InvalidArgumentException is also a LogicException, but more specific: A method was called (for whatever reason – bad code, bad user input – we don't know) with an invalid, unsupported argument. This is exactly what's going on in these cases. BadMethodCallException does have a confusing name and is often misused because of this. It's documented as "thrown if a callback refers to an undefined method or if some arguments are missing". That's something else and not what's going on in these cases. Change-Id: Id446227f578ba701e22acd5e530ffb795e76c147
* | Replace a few array_key_exists with the ??= syntaxthiemowmde2024-01-081-3/+1
|/ | | | | | | | 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
* Deprecate $wgCommandLineModeBartosz Dziewoński2024-01-021-1/+1
| | | | | | | | The global variable is now exactly the same as `MW_ENTRY_POINT === 'cli'`. Bug: T313841 Change-Id: I254bf4aa426e4834705be351cc9eb06d18a33f79
* Namespace Config-related classes under \MediaWiki\ConfigJames D. Forrester2023-09-215-7/+7
| | | | | Bug: T166010 Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
* SettingsBuilder: prevent access to the global instance in unit testsDaimona Eaytoy2023-09-121-0/+27
| | | | | | Unit tests must use dependency injection, not global instances. Change-Id: If7e35a67edc2337657bec4e35724d7f6bc034418
* Move array destructuring into foreachUmherirrender2023-07-081-3/+1
| | | | Change-Id: I54c98085b21f1fe48ccf575d1b9dd60d3b855c58
* Settings: `JsonFormat::decode()` expects string not StreamInterfaceDerick Alangi2023-04-051-1/+1
| | | | | | | | | | | JsonFormat::decode() expects the content to decode as a string not a StreamInterface but Response::getBody() will return a StreamInterface. This was caught by phan as a PhanTypeMismatchArgument error. This patch fixes it by calling getContents() which returns the remaining content as a string. Change-Id: I2ca03f06e7b481ccf19e1c39fa0002b4405ef23a
* Just another 80 or so PHPStorm inspection fixes (#4)Tim Starling2023-03-251-1/+1
| | | | | | | | | | | | | * Unnecessary regex modifier. I agree with this inspection which flags /s modifiers on regexes that don't use a dot. * Property declared dynamically. * Unused local variable. But it's acceptable for an unused local variable to take the return value of a method under test, when it is being tested for its side-effects. And it's acceptable for an unused local variable to document unused list expansion elements, or the nature of array keys in a foreach. Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
* Treat $wgHooks as a regular settingdaniel2023-03-091-0/+17
| | | | | | | | | | | | | | | | | | $wgHooks should be treated like a regular setting, which cannot be manipulated after bootstrapping is complete. This will allow us to greatly simplify the logic in HookContainer. Replacing $wgHooks with a fake array after bootstrapping allows us to detect any remaining live access to $wgHooks without breaking functionality. The plan is to have the fake array emit deprecation warnings in the 1.40 release, and make it throw exceptions in later releases. See Iddcb760cf8961316d6527e81b9aa968657d8354c for the deprecation warnings. Bug: T331602 Change-Id: I0ebba9a29f81b0d86ad8fd84d478fb244f9e9c15
* SettingsBuilder: introduce a "registration" stagedaniel2022-12-161-18/+121
| | | | | | | | | | | | | | | | | | Previously, SettingsBuilder would allow configuration to be loaded and modified until it was "finalized", at which point configuration became read only. This patch introduces an intermediate stage where registration dynamic manipulation of config values can be performed, after all extensions have been loaded and all config schemas are known. Motivation: Extension registration callbacks are typically used to dynamically set config variables, often based on other configuration. This should be done using SettingsBuilder rather than global variables. But previously, we could only be sure that all extensions are known after SettingsBuilder was "finalized", at which point it would be impossible to change config values. Change-Id: I6f8f9f3f7252f0024282d7b005671f28a5b3acc3
* Merge "Settings: Introduce SettingsBuilder::getInstance to avoid $wgSettings"jenkins-bot2022-11-171-0/+30
|\
| * Settings: Introduce SettingsBuilder::getInstance to avoid $wgSettingsdaniel2022-11-171-0/+30
| | | | | | | | | | | | | | | | | | While accessing a SettingsBuilder instance via global state should not be encouraged, we still need it sometimes. So use a static getter instead of a global variable. That way, we can emit deprecation warnings when we have proper alternatives available. Change-Id: I0013bdab474710fd521532dd2653b3789e2ede34
* | Address contravariance todosTim Starling2022-11-161-3/+1
|/ | | | | Bug: T278139 Change-Id: If451415b8acbc764b8f2b277dc8635dcfc88ff53
* Use short array destructuring instead of list()Tim Starling2022-10-211-1/+1
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Settings: add support for obsolete configdaniel2022-10-142-2/+46
| | | | | | | | | | | | | | | | | | This allows config variables to be declared obsolete. Obsolete config will be omitted from the schema, defaults, name constants, etc. The purpose of keeping a declaration of obsolete config around is to allow the updater to warn admins that they are using a config variable that no longer has any effect, and provide them with a remedy. The idea is that support for deprecated config can be removed after one release per the stable interface policy, but the declaration of obsolete config should be kept for as long as we support updates, that is, at least two LTS releases. See https://www.mediawiki.org/wiki/Topic:X4bh4nf3pe2ho5jj for discussion. Change-Id: Ia7a00742ea7a5311e820a6a43b11135a3f2a825f
* GlobalVarConfig: Avoid slowness of array_key_exists on $GLOBALS in PHP 8.1+James D. Forrester2022-09-161-1/+5
| | | | | | | | Also make the same change for GlobalConfigBuilder for consistency, though that's not critical path. Bug: T317951 Change-Id: I9b46e7bc25365d01dbc86a9b2288559cb9e2cb8d
* SettingsBuilder: report warningsdaniel2022-07-151-0/+60
| | | | | | | | | | | This adds functionality to SettingsBuilder for collecting warnings to be logged later, when the logging mechanism has been set up. This also adds a validation step to update.php that aborts the update if any warnings have been registered in SettingsBuilder, or the settings fail to validate against the settings schema. Change-Id: I387905289fb93591f79b96bf4c6cb5ec692b2aff
* Settings: Remove unstable markers and mark interfaces appropriatelyDerick Alangi2022-07-115-5/+7
| | | | | | | CachedSource is newable and stable to call while the other interfaces are now stable to implement. Change-Id: Ifcb4865691cb7ec308acac2bd3f367b14424a0e1
* Move dynamic defaults into MainConfigSchemaAryeh Gregor2022-07-079-11/+270
| | | | | | | | | | | | | | | | | | | | | | | | | The goal is to keep the actual default values for settings in the same place as the setting is declared, and applied using the regular means for loading the settings -- not in a separate piece of code that needs to be loaded through some entirely different mechanism. SetupDynamicConfig.php now contains a few categories of things: * Post-processing of configuration settings, where already-set settings are altered. This could be moved to MainConfigSchema too as a separate set of methods. * Processing of old aliases of settings (blacklist, slave) that are not registered as settings anymore and therefore are not available to MainConfigSchema. This could perhaps be moved to LocalSettings processing somehow? * Setting $wgUseEnotif, which is also not registered as a setting. Easiest would be just to declare it as a setting and have it set unconditionally. * Setting the actual timezone to $wgLocaltimezone. This is not related to configuration and should just be in Setup.php. Bug: T305093 Change-Id: Ia5c23b52dbbfcb3d07ffcf5d3b7f2d7befba2a26
* Remove 'ignoreKeys' from config schemaLucas Werkmeister2022-07-061-7/+0
| | | | | | | Unused since change I88754b52c2 (commit 9e95539fc9) – this was only used for SessionProviders, which is now a map/object instead. Change-Id: I8da686e6379eb33a63799874fb44f9b0030ab5ba
* Merge "Support etcd as a source for SettingsLoader"jenkins-bot2022-06-301-0/+286
|\
| * Support etcd as a source for SettingsLoaderDan Duvall2022-06-211-0/+286
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Added a EtcdSource to handle loading of settings from etcd. The implementation is based on EtcdConfig but is much simpler due to the reliance on the existing source caching layer. GuzzleHttp\Client is used over MultiHttpClient as the latter depends on MediaWikiServices and therefore should not be used during early initialization. A naive cache key is based on the etcd request URL, effectively representing the etcd API version and settings directory, and uses either the DNS SRV entry as the host name or the host name itself if discovery is disabled. The cache TTL is set to 10 seconds. The combination of this low TTL and the naive key should replicate the current caching pattern of EtcdConfig. Stale results are allowed for failover in case of temporary unavailability. At this time, the expiry weight was not changed from the suggested 1.0. However, verification of this as a suitable early expiration coefficient should be performed in a production like environment. Bug: T296771 Change-Id: I782f4ee567a986fd23df1a84aec629e648a29066
* | Add support for nested property schemas in MainConfigSchema.daniel2022-06-295-140/+171
|/ | | | | | | | | | | | This adds support for JSONSchema style property declarations with nested schemas. This is a step towards using more nested structured for configuration, rather than adding to the over 700 keys already defined in the main config schema. Defaults from property schemas are aggregated into a default value in the top level schema. Descriptions are however not yet aggregated. Change-Id: Iaf46a9ecc83bee3566098c56137a1be66bff2ab9
* Docs: remove references to DefaultSettings.phpdaniel2022-05-301-2/+2
| | | | | Bug: T300129 Change-Id: I1e83a0dde6235bed91d28d7d43691c6a5d979f2f
* Merge "Settings: Add remaining schema info to config-schema.php"jenkins-bot2022-05-181-17/+42
|\
| * Settings: Add remaining schema info to config-schema.phpdaniel2022-05-171-17/+42
| | | | | | | | | | | | | | | | | | | | | | | | By optimizing the structure of config-schema.php for fast loading, some information needed for schema validation was lost. This patch ensures that all schema information is retained in config-schema.php. The code for consuming this field already existed, as written for what we already output to the generated config.schema.yaml file. Bug: T307769 Change-Id: I8adcdfd2b8fb5f5b96308eea74c07d8cc7a4d6ba
* | Turn DefaultSettings.php into a deprecated stubdaniel2022-05-173-4/+87
|/ | | | | | | | | | | DefaultSettings.php has been replaced by MainConfigSchema. Loading DefaultSettings.php is deprecated. Code that needs to have access to configuration defaults should use the ConfigSchema service object. Bug: T300129 Change-Id: I7b2c0ca95a78990be1cdb9dd9ace92f6dcf1af15
* Merge "Config builder optimisations (combined)"jenkins-bot2022-05-097-32/+155
|\
| * Config builder optimisations (combined)Tim Starling2022-05-067-32/+155
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a modified rebase of a patch by Tim, see I75f405930a7b14561389c59d147640e870146bec. Some benchmark results (from my laptop): Loading defaults from config-schema.php: - Master: 115/sec ( 8.7ms) - I75f4059: (Tim): 575/sec ( 1.7ms) - Id9dd0bf: (Daniel): 1120/sec ( 0.9ms) - This (Tim+Daniel): 1420/sec ( 0.7ms) Loading defaults and merging settings (worst case): - Master: 80/sec (12.4ms) - I75f4059: (Tim): 93/sec (10.8ms) - Id9dd0bf: (Daniel): 200/sec ( 4.9ms) - This (Tim+Daniel): 682/sec ( 1.5ms) Original commit message by Tim: * Explicitly import function array_key_exists to activate the special opcode * Batch creation of MergeStrategy objects * Batch default assignment to ArrayConfigBuilder The batches mostly help by allowing more inlining, eliminating some function calls. Reduced time for apply/finalize benchmark from 540µs to 170µs. Co-Authored-By: Tim Starling <tstarling@wikimedia.org> Change-Id: I3d4dd685eaaa4351801b3bac6ce1592eea925c5f
* | Merge "Add tests for ConfigBuilderBase"jenkins-bot2022-05-091-1/+1
|\ \ | |/ |/|
| * Add tests for ConfigBuilderBasedaniel2022-05-051-1/+1
| | | | | | | | | | | | | | | | This adds tests for the abstract base class, to make sure the generic implementation matches the contracts. Tests for existing subclasses may not be using the generic code, and new subclasses may run into trouble. Change-Id: I2c652c3028862ad52dbd0edaa454bec953e94506