aboutsummaryrefslogtreecommitdiffstats
path: root/includes/Settings/Source
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-174-24/+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-161-3/+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
* Use explicit nullable type on parameter argumentsUmherirrender2024-10-161-1/+1
| | | | | | | | | | | 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
* 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 "implements Stringable" to every class with "function __toString()"Bartosz Dziewoński2024-06-137-7/+15
| | | | | | | | | | | | | 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
* 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
* 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
* 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-141-1/+8
| | | | | | | | | | | | | | | | | | 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
* Settings: Remove unstable markers and mark interfaces appropriatelyDerick Alangi2022-07-113-3/+3
| | | | | | | 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-071-0/+65
| | | | | | | | | | | | | | | | | | | | | | | | | 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
* 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-293-138/+162
|/ | | | | | | | | | | | 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
* Merge "Make MainConfigSchema more readable."jenkins-bot2022-04-072-4/+143
|\
| * Make MainConfigSchema more readable.daniel2022-04-072-4/+143
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This allows for PHPDoc-style types to be used in MainConfigSchema, and adds aliases for the 'object' and 'array' types, to avoid confusion. The type 'map' can now be used for associative arrays, it will be represented as 'object' in JSON Schema. Similarly, 'list' can be used to refer to sequential arrays, it will be represented as 'array' in JSON schema. In addition, the basic PHP types are mapped to their JSON counterparts, including support for nullable types. For example: "?map" will become [ "object", "null" ]; "float|false" will become [ "number", "boolean" ]; Change-Id: I89617d06afd1e97ee1bc9bc49b6c77bed7bd50d9
* | Update @since tags of config schema codeAlexander Vorwerk2022-04-021-1/+1
|/ | | | | | | Did not make it into 1.38 Follow-Up: I663c08b8a200644cbe7e5f65c20f1592a4f3974d Change-Id: Ib981b4511384a4102a3128de866ddca6ff3fe14b
* phan: Disable scalar_implicit_cast settingUmherirrender2022-03-181-0/+1
| | | | | | | | | Make phan stricter about scalar types by setting scalar_implicit_cast to false (the default in mediawiki-phan-config) Bug: T242536 Bug: T301991 Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
* Use class constants to define config schema, rather than config-schema.yamldaniel2022-03-171-0/+97
| | | | | | | | | | | | | | | | Instead of maintaining the config schema as a yaml file, we maintain it as a set of constants in a class. From the information in these constants, we can generate a JSON schema (yaml) file, and an php file containing optimized arrays for fast loading. Advantages: - PHP doc available to IDEs. The generated markdown file is no longer needed. - Can use PHP constants when defining default values. NOTE: needs backport to 1.38 Change-Id: I663c08b8a200644cbe7e5f65c20f1592a4f3974d
* Support stale cached settings for failoverDan Duvall2022-01-211-0/+11
| | | | | | | | | | | | | | | | | | | | | | | Require a `CacheableSource` implementation to signal whether stale settings may be served from the cache by implementing an `allowsStaleLoad()` method. This will be useful for sources (e.g. etcd) that expect some degree of unavailability and failover during unavailability is desired. In order to support stale results, `CachedSource` sets cache items with an indefinite TTL but uses the computed expiry timestamp in the envelope to consider whether the item is considered expired as opposed to a true miss where the item is malformed or not present in the cache store. If a `SettingsBuilderException` is thrown during the source's `load()` method but the cache check was not a real miss, the stale cached results are returned. Note there is currently no pruning of cache items so it is advised that `CacheableSource` implementations for which stale loads are allowed also implement an immutable `getHashKey()` based on constructor arguments. Bug: T296771 Change-Id: Ida0698a237dc0939230799700b6f54956f033d50
* SettingsBuilder: load settings recursivelydaniel2022-01-184-2/+82
| | | | | | Allows settings files to include other settings files. Change-Id: Ieab7def1ada8b255e60c58927850a58e18309f6e
* Settings: Introduce PhpSettingsSource for provisioning settingsDerick Alangi2021-12-091-0/+85
| | | | | | | | This is an intermediate step before converting the merge strategies or other configs/config schemas to YAML. Bug: T297320 Change-Id: I91cd04d14f0ff86125fc8870984dab045c2098b5
* Refactor cache TTL for SettingsBuilder sourcesDan Duvall2021-12-021-1/+17
| | | | | | | | | | | | | | Move cache TTL from `CachedSource` into the `CacheableSource` interface, allowing each source to define a TTL most appropriate to its own settings loading implementation. Fix bug where `generation` time was computed incorrectly by `CachedSource`. Include tests to exercise all `CachedSource` interactions with `CacheInterface` and `CacheableSource`. Bug: T296771 Change-Id: I97c42cf6ca716516c32104de25245aa21ec110e4
* Cache loading of SettingsBuilder sourcesDan Duvall2021-11-292-2/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The `SettingsBuilder` now accepts a PSR-16 cache interface with which to store and query settings before attempting to load from each source. By default, no cache is used, but any object that implements the `Psr\SimpleCache\CacheInterface` may be provided to the constructor. An explicit dependency on "psr/simple-cache" has been added to `composer.json`. Note that this dependency already existed in vendor albeit it as a transitive one. An APCu based `SharedMemoryCache` adapter is provided as a canonical PSR-16 compliant interface for production use. Sources are now queued by the `SettingsBuilder` when calling `load()`. If a cache interface has been provided, and the source is considered cacheable (implements `CacheableSource`), then it is wrapped as a `CachedSource` which will query the cache first before loading from the wrapped source. Cache stampedes are mitigated using probabilistic early expiry. The implementation for this was partially based on symfony/cache-contract source code but also from the Wikipedia article and paper referenced therein. See https://en.wikipedia.org/wiki/Cache_stampede#Probabilistic_early_expiration Bug: T294748 Change-Id: I52ab3899731546876ee58265bd4a1927886746dc
* SettingsBuilder: Add YAML file format.Petr Pchelko2021-11-294-41/+153
| | | | | | | | | | | | | If php-yaml extension in installed, use that. Otherwise we fallback to symfony Yaml parser. php-yaml is about 20 times faster then symfony, for default-settings.yaml it will take PHP-yaml 6ms to load it vs 100ms for symfony. But given that the result will be cached, it's better not to bring in a required native dependency. Bug: T294751 Change-Id: I3ffde926c3f264cacf39810ff7bd338c9f78823d
* Introduced settings sources and formatsDan Duvall2021-11-155-0/+303
A `SettingsSource` is meant to represent any kind of local or remote store from which settings can be read, be this a local file, remote URL, database, etc. It is concerned with reading in (and possibly decoding) settings data, and computing a consistent hash key that may be used in caching. A `SettingsFormat` is meant to detect supported file types and/or decode source contents into settings arrays. As of now, JSON is the only supported format but others may be implemented. `FileSource` is the first source implementation, with its default format being JSON, meant to read settings from local JSON files. `ArraySource` is mostly useful for testing using array literals. Refactored `SettingsBuilder` methods to use the new source abstractions. Bug: T295499 Change-Id: If7869609c4ad1ccd0894d5ba358f885007168972