Commit graph

13 commits

Author SHA1 Message Date
jenkins-bot
18875c2c0f Merge "Generate DefaultSettings.php from schema" 2022-03-18 11:02:51 +00:00
daniel
1ee8fde16b Generate DefaultSettings.php from schema
Avoid having to maintain defaults twice.

Change-Id: I7a883fe3c952cc653d43b7e399631ec3beab0bc3
2022-03-18 10:25:52 +01:00
jenkins-bot
29e0cf9c9d Merge "Use class constants to define config schema, rather than config-schema.yaml" 2022-03-18 07:44:45 +00:00
daniel
2fe23d6860 Use class constants to define config schema, rather than config-schema.yaml
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
2022-03-17 21:20:03 +01:00
daniel
e239b02a5e Add convenience methods for asserting status.
This ensures that assertions work in a uniform way,
and provides meaningful messages in cause of failure.

Change-Id: Ic01715b9a55444d3df6b5d4097e78cb8ac082b3e
2022-03-16 22:44:25 +01:00
daniel
404f4a8512 Fix edge cases in schema validation.
Since PHP arrays make no clear distinction between lists (JSON arrays)
and maps (JSON objects), some edge case handling is needed to make
validation work reliably when we declare types for all arrays:

1) Allow array keys to be ignored, so an associative PHP array validates
as a JSON array. This is needed for the SessionProviders setting.

2) Allow associative arrays with numeric keys to validate as JSON
objects. This is done by ignoring the type validation when numeric keys
are detected. A warning is returned in the status object.

3) Work around validation failing on float values that are expected to
be integers. All numbers come from the yaml parser as floats, and the
"integer" type in JSON schema should accept floats with if the
fractional part is 0. But that doesn't seem to work, we need to cast the
values to integers explicitly.

Also, this fixes some mistakes in the schema: LockManagers is a list,
so it should use the JSON type "array". NamespacesToBeSearchedDefault
is a map (JSON object), even though it uses numeric keys. The Actions
registry is also a map.

Change-Id: I9d0453d740c377b7cce574df743536c39a0ec619
2022-03-08 13:59:19 +01:00
daniel
f31bc32a65 Remove deprecated alias $wgStyleSheetPath
$wgStyleSheetPath has been a deprecated alias for $wgStylePath since 1.3 (2004).
Time to get rid of it.

Change-Id: I78a6394003b9aefab7aa8559b8e2b22bc50154fc
2022-03-04 13:36:56 +01:00
Amir Sarabadani
8bbf64d563 tests: Make the error message of SettingsTest more informative
This would have saved me around an hour if I knew it earlier. Let's make
it not happen for others.

Change-Id: I2e146424fc01677383a15d98071d8cbc2d832d9b
2022-03-03 13:07:24 +01:00
daniel
f9b589f556 config-schema: Define types for all arrays.
This patch ensures that we know which arrays are lists (JsonSchema type
"array") and which are maps (JsonSchema type "object"). We can then
default to array_merge for lists and to array_plus for maps. This seems
clearer than requiring an explicit merge strategy to be declared for all
arrays.

This patch specified a mergeTrategy for some config variables that need
behavior different from the default.

This patch also changes the merging behavior to allow non-array values
to replace arrays and vice versa. It also changes the behavior of
defaults to allow falsy values to override non-falsy defaults.

Bug: T300129
Change-Id: Ia7b0c0250af6a957eac1efb554fb47511f5e093f
2022-02-23 14:09:41 +01:00
Petr Pchelko
ef73bfafd9 Add simple configuration doc generator
This is a first draft of the configuration doc renderer.
The resulting markdown certainly needs some love, but
we can work on improvements incrementally. This gives
us a baseline to reference on doc.wikimedia.org

Bug: T296647
Change-Id: I3c426b9fc37b1cf7ce8423969b2d7589767ee6cc
2022-02-09 07:09:32 -08:00
daniel
f5641f9856 Do not rely on $IP in DefaultSettings.php
In order to allow configuration default to come from JsonSchema,
and dynamic defaults need to be initialized in Setup.php.

This movesd the initialialization of $wgExtensionDirectory and $wgStyleDirectory
to Setup.php

Bug: T294788
Change-Id: I11f5723aa299caa210cf6a1f5b7436f191b1ffc2
2022-02-03 22:05:34 +00:00
Petr Pchelko
d54e3d216c Add pre-generator for config-schema.php
Bug: T300129
Change-Id: Ib2620993114af5a659bda60dc45b6fb3bed657b0
2022-02-03 13:27:47 +00:00
Petr Pchelko
e36a8af70e First pass on creating config-schema.yaml
The config-schema.yaml follows the settings file format.
It's not used in reality yet, but tests were added
to compare the yaml with the result of DefaultSettings.php
importing.

The list of properties not yet included:
 - 'wgVersion' - deprecated alias to MW_VERSION
 - 'wgConf' - instance of SiteConfiguration
 - 'wgStyleSheetPath' - alias to another global
 - 'wgExtensionDirectory', - depends on $IP
 - 'wgStyleDirectory' - depends on $IP
 - 'wgServiceWiringFiles' - depends on __DIR__
 - 'wgHTTPMaxTimeout' - infinity default
 - 'wgHTTPMaxConnectTimeout', - Infinity default

The PHPDoc was copied over as is into description fields,
it will be converted to something more pleasant in a separate
iteration.

The types were parsed out of PHPDoc and fixed up manually.

Default values come from executing DefaultSettings and serializing
the values into YAML.

Change-Id: I9aa9ad9713bdbdac2bd7b528c609772154b5a135
2022-01-19 10:02:51 -08:00