This pulls the dependency out of __construct() up into the static
newFromJSON() method.
I'm also replacing the "ContentLanguage" service, which is a Language
object, with the plain language code. Features from the Language
class are never needed.
Change-Id: Ic4892cd22d83ff557af37e36e62e2af14bc58a99
Changes to the use statements done automatically via script
Addition of missing use statements done manually
Change-Id: I8e049e495a0d0f3a0e1ee02a8252354b12604bf9
This is not really anything new. Most code already followed these
sniffs. This patch just fixes the remaining exceptions. Also:
* Remove PHPDoc blocks that don't add anything but just repeat the
strict types.
* Remove @file comments in favor of class-level comments.
* Add strict types where possible, most notably some `void`.
Change-Id: Iff6872dff68170b0fc4e82ac2ba3cad385e8773e
This makes it possible to use these steps independent from each
other. For example, a future patch can get rid of the re-validation
that's done over and over again when the API is called.
A significant change is that this gets rid of an expensive deep
clone. It was necessary before exactly because validation and
normalization was intertwined. Normalized properties would mess with
the later inheritance.
Strictly splitting validation and normalization (and executing them
in this order) solved this. The only downside of this is that
inherited properties are validated twice. But this is much less of a
problem, compared to the deep clone, I would like to argue.
This was always covered by tests. You can still see the tests fail
when you flip the execution order of inheritance and parameter
validation.
Bug: T301337
Change-Id: Ie5728094f9ed813f53b709d8b5283c4b99dc7d63
This method is not used anywhere else:
https://codesearch.wmcloud.org/search/?q=getRawParams
I tried to make the code a bit more readable. Notable:
* Make use of the return value we get from the preg_… function.
* {{3,} means "the character '{' 3 or more times". {{{+ does the
same. Note the { doesn't need to be escaped when it's not
followed by a number.
* At the end, it doesn't make any difference when we scan for
optional closing brackets. The moment we find at least 3 we are
done.
The test is intentionally not moved. This is something for a later
patch.
Bug: T301337
Change-Id: I55e31ceecea2ae7c35bcfbc2d641b35f751820db
One method is only public to be able to test it. Others look like
they have been made "protected by default", which is not needed
anywhere.
Change-Id: Ib2231f0b2a879323aa53f8d40a175527c5b131d8
Effectively a no-op. This patch doesn't change what the code does.
Tests are in place to prove this.
As before, the tests are intentionally not moved but left in place.
This is for later patches to clean up.
Change-Id: If130e0d006a36d8c755288f8a4e4e9a4c42a6295
The word "param" is not really that ambiguous in this context. The
only other meaning it could have is "parameter name". Such places
already use $paramName.
This makes the following patches easier to review.
Change-Id: I1e6210d1ca7d58726a0fc3b3396d75e0e28c16d8
No functional change was made to the code. It was only moved from one
place to another. Note there are a lot of tests that cover this code.
The tests haven't been touched on purpose. Splitting these as well
is something for a later patch.
Bug: T260980
Change-Id: I9fa0fa87768f2560b83a1b5f3d39211ea9d6cfad
Parameter names in a template can be numeric. While it makes a lot of
sense to force a specific format in the TemplateData JSON (i.e. only
strings), it's inconvenient and confusing if numbers are rejected for
being "invalid".
Effects of this patch:
* The incoming JSON is allowed to contain numbers in the aliases
array.
* However, the API normalizes these and forces all aliases to be
strings, as it was always documented.
* The editor component accepts anything in the aliases array, but
forces all aliases to be strings. Again, as documented.
* Note that it was never possible to use numeric keys in the `params`
list. This patch is only about aliases.
At the moment this is a somewhat "hidden" feature. We might or might
not update the documentation to officially allow numeric aliases.
Bug: T298795
Change-Id: I32ea296b4520e7f21b03a1f6390db4f43b613bdd
This is not new. This was always documented to not accept anything
but strings.
Let's apply the same fix to aliases while we are here.
Bug: T297386
Change-Id: I57e18779f28802816d5adb66cc4067df4e58b26e
The $this->data property stores whatever json_decode() returned,
which could be anything. The validation happens later.
Change-Id: I0d04831b8253005734c1c6c97b48061be35e5d88
"Almost" because I found at least one that appears to be
unreachable (the very first check for null). But changing this
code is out of scope of this patch.
This also updates some of the error messages to explain the
location of the error better. It appears like the incomplete
paths are copy-paste mistakes.
I also found one duplicate test case and removed it.
Change-Id: Ic0ee9d04f5cd1060ade385ef308e70d221dd2f18
At the moment, when the user clicks the "Status" column to
sort by status, the statuses are ordered alphabetically,
which gives widely varying results depending on the language.
But there is an inherent order for these, even hard-coded in
the code: When a parameter is deprecated, nothing else matters.
Otherwise it's required → suggested → optional. Doesn't it
make much more sense to order the column this way? Especially
because there are never more than these 4 hard-coded values.
This is one of the (few remaining) issues mentioned on
https://de.wikipedia.org/wiki/Vorlage:TemplateData#Vorlagendokumentationsseite_verbessern_%E2%80%93_MediaWiki_ungen%C3%BCgend
This patch also makes it so that a CSS class name is always
added to all status fields, not only to the required ones.
This allows for per-wiki or per-user styling.
Change-Id: Id3f1ffafe09a3817972a4ee4bd4a3ded7be6f039
Parameters may include a `suggestedvalues` property, which is rendered
in the UI for some parameter types.
TemplateData editor UI elements are implemented behind the
TemplateDataSuggestedValuesEditor feature flag.
Bug: T271897
Change-Id: I14012c79b3fa0d48c58fd8999584cc03ec03575e
Example:
On
https://en.wikipedia.beta.wmflabs.org/wiki/Template:Anschutz
the two parameters "state" and "capitalization_test" don't have
a label in the <templatedata> JSON structure. Instead the
internal parameter name is shown. But it's capitalized for an
unknown reason. I guess this is done to make the table look
"nice". But it causes confusion – see the ticket.
This capitalization is there since the very first commits from
2013, see I16d3f9e.
Compare with VisualEditor: Edit the template on
https://en.wikipedia.beta.wmflabs.org/wiki/Conflict-title-0.8542952978413387-I%C3%B1t%C3%ABrn%C3%A2ti%C3%B4n%C3%A0liz%C3%A6ti%C3%B8n
or use the old wikitext editor and TemplateWizard to insert
the template. In both cases the parameter names are not
capitalized.
Another argument why this capitalization is misplaced: When
there is no <templatedata> JSON blob, the TemplateData editor
auto-detects the parameters and semi-automatically creates a
minimal JSON blob. This is the moment where labels should be
created and stored so the user can edit them. But this doesn't
happen (for good reasons).
The user can't do anything about the current capitalization.
The only way to change it is to add a label that does nothing
but repeat the parameter name, just to undo the capitalization.
That should not be the way this works, I would like to argue.
Bug: T174771
Change-Id: Ia8133d3f0d6b79fe89c63bb0392a334c0a185a65
This fixes a series of issues:
* The JS implementation had a trim() in one place that was
missing in PHP.
* The actual parameter name in the paramNames/$params array was
trimmed, but the "normalized" name (this is only for duplicate
detection) was not trimmed.
* It was possible for an empty parameter to show up.
This resulted in very strange behavior, e.g. {{{ 1}}}{{{1 }}}
was detected as "1" and "10" (?), i.e. it would try to renumber
the duplicate in a strange way (string "1" plus a counter that
starts with 0).
Change-Id: I0a6371f3633b03b5b21809ecd06ea4c72d7d914d
These are not really variables. They are never modified, and not
meant to be modified. Using "static" was a common workaround
when we had no private constants in PHP.
Change-Id: Ie1234ce8833986431be95f8537282fa174978063
Html::open/closeElement are hard to read and possibly error
prone. We can easily avoid it in this case here.
Change-Id: I2251cb63e58bc132ced0bb684e3f0e3be35ab1aa
No subclass is directly using these. They don't need to be
protected. There are getters, if needed.
Change-Id: I27dcb8bee37b9559242451774c52240b490a18af
In detail:
* Callers don't need to know that the return value can be a
TemplateDataCompressedBlob. All relevant stuff is declared in
the base class.
* It's not relevant which internal method returned the status.
It's just the status of the object after it was constructed.
* "stdClass" is more specific. "object" includes more stuff
which can't be returned here.
* Avoid duplication and use @inheritDoc instead.
Change-Id: I68878a5b26ecd566fbea88b513ee697b45769659
In detail:
* Mark both as protected and make them call each other.
* Avoid duplication.
* Remove unused "null" default value.
Change-Id: I272a68bb3cc0c544ef306b16c2998458c2eb1a2d
Notes:
* In PHP, when a function parameter does have a strict type,
all it does is forcefully casting the value to this type. It
doesn't cause warnings.
* Violating a strict return type causes a warning.
* I'm intentionally not touching places where the result from
json_decode() is passed through. In theory this could be
anything. Let's update these later, after more refactoring
is done.
Change-Id: I9a203356f70cf9edd434f7dc4ca130c2b7605ab4