Commit graph

674 commits

Author SHA1 Message Date
Thiemo Kreuz (WMDE) 8d9b4526c6 Revert "Hide deprecated parameters if they don't have a value"
This reverts commit 0d4dee341b.

Reason for revert: This made it entirely impossible to add a
deprecated parameter, even if done intentionally. Needs more tests.

Bug: T274551
Change-Id: I7389bad0845cd1ce78f9d7ef71592cb1ce2a063e
2021-08-03 08:24:24 +00:00
Andrew Kostka 0d4dee341b Hide deprecated parameters if they don't have a value
Bug: T274551
Change-Id: I6bfceae2579a5bcedae9da7eb5326fe8f60ea7c0
2021-07-22 12:24:57 +02:00
jenkins-bot c2bc8c7e26 Merge "Move code that belongs to the template specification" 2021-07-08 08:46:40 +00:00
jenkins-bot e70ca5bd42 Merge "Add missing test case with template parameter placeholder" 2021-07-08 08:33:15 +00:00
Svantje Lilienthal ee98622076 Change style for adding an "Unknown field" in the parameter search
Bug: T286236
Change-Id: Ibb3df034c9b423dd4130d8242bd7bf0dc742ee2f
2021-07-08 09:20:25 +02:00
Thiemo Kreuz 3cd91100a9 Move code that belongs to the template specification
Separation of concerns:
* The template model knows which parameters are currently used,
  but doesn't know what's documented.
* The spec knows what's documented, but doesn't know what's
  currently used.

Change-Id: I97cac00d6775a17a07059d0e8a7a116adc6080b3
2021-07-07 16:45:35 +02:00
Thiemo Kreuz 9624f61701 Add missing test case with template parameter placeholder
There are some methods that behave different when a parameter
placeholder (where the parameter name is "") is present. Some
skip placeholders, some don't. This is critical to cover
before we make further changes to this class.

What I also do in this patch:
* Use shorter variable names to make the code easier to read.
* Don't reuse the `transclusionData` variable but use a copy
  of the expected value. This makes the assertions much
  easier to understand.
* Bring every test in the same "setup" → "execute" → "assert"
  order.

Change-Id: I41a691c56bc509b132dc719ff820ae1ade4ccc3a
2021-07-07 15:53:40 +02:00
jenkins-bot de71ebc9de Merge "Simplify ve.dm.MWTemplateModel.hasParameter() a lot" 2021-07-06 08:23:15 +00:00
jenkins-bot 4a5f811c82 Merge "Keep template parameter position when resolving aliases" 2021-07-05 11:44:19 +00:00
Thiemo Kreuz fbb7d211d0 Simplify ve.dm.MWTemplateModel.hasParameter() a lot
A lot of the checks are redundant. The first check still is
redundant because the later two cover everything as well. But
I left it for performance reasons.

Additionally:
* There was no test for the method.
* This patch also updates a few pieces of documentation in the
  same class.

Change-Id: I10f2944a844cc070bdc08dec6719929b383e34fa
2021-07-05 11:58:42 +02:00
jenkins-bot 8718ac8ece Merge "Fix parameter ordering when using aliases" 2021-07-05 08:33:01 +00:00
Andrew Kostka 6af13f0d42 Fix parameter ordering when using aliases
If a known parameter is present using one of it's aliases, then
only the aliased name should be shown to the user. This patch,
therefore, resolves the issue of the same parameter being added
to the sidebar twice.

When adding a parameter that is aliased, it will receive the same
position as the non-aliased parameter it is replacing.

Bug: T274545
Change-Id: If4e58c941fd0f0e690d3603935f5a5d3f9938163
2021-07-05 08:14:42 +00:00
Thiemo Kreuz 6757a1bfa9 Character = is not allowed in template parameter names
It's allowed in values, but not in parameter names. The moment
a parameter name contains an `=` the parameter name will be cut
off at this point, and what's behind the `=` will become part
of the value.

You can test this on any live wiki. Open VisualEditor. Edit any
template. Add a parameter with a name like `a=` and some value.
Switch to wikitext mode and back. Edit the template. The `=` is
now part of the value.

Bug: T98065
Change-Id: I5e00e8fac987471243605816b041d3638927ac3b
2021-07-04 14:03:21 +02:00
Thiemo Kreuz 8d0a623f40 Keep template parameter position when resolving aliases
This fixes a minor issue in the spec class. In the first step,
parameters from the template are added to the list of known
parameters. Later, aliases are resolved. The original behavior
was that such a parameter moved to the end of the list. This
is rather unexpected.

This dosn't have much of an impact. The pretty much only place
where the parameter order from the spec can be seen is in the
parameter search widget. Still I believe it's worth fixing.

Bug: T285483
Change-Id: I455818451811e92bba3e9320c2d41e1db8d563f2
2021-07-03 20:14:06 +02:00
Thiemo Kreuz 280ba23e2c Add missing fail-safe to MWTemplateSpecModel.extend()
I don't want this code to crash when the TemplateData API
returns an unexpected result.

Bug: T285483
Change-Id: I237cbfbb85892a53a08d9e7e34cf4974775d627a
2021-07-02 17:52:43 +02:00
jenkins-bot 8c4989c1be Merge "Fix parameter search being to relaxed on unknown params" 2021-07-02 15:47:11 +00:00
Thiemo Kreuz 07344fce0f Rename misleading "extend" method in template spec class
This doesn't "extend". It was never used like this. What it
actually does is to link between a (cached) TemplateData blob
and the spec class that want's to use it.

Is this the best possible name?
* fillFromTemplateData( … )?
* propagateTemplateDocumentation( … )?
* readDocumentationFrom( templateData )?
* …?

Do we want to rename the "spec" class as well?
* MWTemplateDocumentation?
* MWTemplateMetadata?
* MWTemplateDataAccessor?
* …?

Bug: T285483
Change-Id: I6c52ef42d411c2f47fc0080768d36ebda4dd2a55
2021-07-02 11:26:04 +00:00
jenkins-bot 2e4ac455f0 Merge "Add more edge-case test cases for template spec class" 2021-07-01 18:57:51 +00:00
Thiemo Kreuz fecded9f70 Fix parameter search being to relaxed on unknown params
When what you type is a partial match, you can't add it as an
unknown parameter, even if that would be the correct action. The
reason for this unexpected edge-case is a mistake in the code
where a variable called "exactMatch" is set when a *partial*
"nameMatch" was found.

Bug: T285940
Change-Id: I6d12e2d7251a19d7d5f8be544c3c32a3ac14fcf0
2021-07-01 20:09:51 +02:00
Thiemo Kreuz 99523b855c Use and document the term "known parameter" in template code
The so called "spec" class keeps track of parameters that have
been used before, no matter if documented via TemplateData or
not. Removed parameters are still "known" (i.e. have been seen
before).

This feature allows to easily find previously used parameters
names when an undocumented parameter was removed and the user
tries to add it again.

Bug: T285483
Change-Id: Ia1555eea87cd99e7a3f386f4279ec5a80fb98a79
2021-07-01 12:03:38 +00:00
Thiemo Kreuz d8f4da199d Add more edge-case test cases for template spec class
Bug: T285483
Change-Id: I0a9bf7fe51242161dbc57c9301f360c9e8f35b93
2021-07-01 10:13:00 +02:00
jenkins-bot 127ea9ea27 Merge "Avoid the term "canonical order" in template related docs" 2021-06-30 11:35:27 +00:00
jenkins-bot 5943b5a25e Merge "Fix spec.fillFromTemplate() not skipping aliases any more" 2021-06-30 11:11:24 +00:00
jenkins-bot 6aaec0c88b Merge "Rename temporary "x" variable in spec class tests" 2021-06-30 11:09:54 +00:00
Thiemo Kreuz 84329a40c8 Rename temporary "x" variable in spec class tests
I forgot to give this variable a proper name. The "x" was not
meant to stay.

Bug: T285483
Change-Id: I482b9282676082f44d5f98a574e5ada05dfb6318
2021-06-30 12:16:50 +02:00
Thiemo Kreuz 466e428a81 Fix spec.fillFromTemplate() not skipping aliases any more
In I04b8a14fbec7be5a1c4defabf92e94f694c1e638 we sepearted params from
aliases. There we missed that re-filling the parameters from the 
template could re-add the aliases.

Bug: T285483
Bug: T285843
Change-Id: I1928b443a5f708bc8c57efa5ad0a86b5915b159c
2021-06-30 10:14:43 +00:00
Thiemo Kreuz bc4aeed86e Avoid the term "canonical order" in template related docs
While the term "canonical" is not wrong, I find it still
somewhat ambiguous.

1. "Canonical" could mean different things. E.g. is the order
of parameters as they appear in the article's wikitext the
"canonical" one? It's possible to argue like this, esp. if a
template doesn't have TemplateData documentation. In this case
the only order known is the one from the wikitext.

2. "Canonical" sounds like the parameters must be reordered.
But this should never happen. Not having dirty diffs is more
important than having the parameters in a specific order.

Bug: T285483
Change-Id: I23658d37fea50b727667677ac6a49066673b2135
2021-06-30 09:38:28 +02:00
Thiemo Kreuz 8dca99d38c Fix broken template serialization test setup
This was not really testing anything before. Introduced in
I76c6fe8.

Bug: T285382
Change-Id: I5f8343c9805b9a1adc2efdd13a103a7f1196e15b
2021-06-29 16:29:11 +02:00
Thiemo Kreuz b7d88c541b Fix all spec methods to not crash on unknown parameters
Change-Id: I16708b048a785f0712084bd2d087e4aab77fb72b
2021-06-25 08:36:23 +02:00
Thiemo Kreuz b8382513fc Use separate data structure to store aliases in spec
Wait, what's going on here? This patch looks like it changes the
behavior of this code. But it doesn't. Here is what happened
before:
* Let's say a template contains 2 parameters, A and B.
* We don't know yet if these names are aliases.
* getParameterNames() returns [ "A", "B" ].
* extend() is called. The TemplateData documentation contains
  the parameters "B" and "C". "C" does have an alias "A".
* extend() can't find "C" and adds it to the end, as if it's a
  new parameter.
* extend() also iterates the aliases. For each alias it creates
  a reference to the specification object. In this case a
  reference from "A" to "C" is created.
* But "A" already exists. The position of "A" doesn't change,
  but the specification now says it's an alias.
* getParameterNames() skips aliases. It skips "A" and instead
  returns the new "C" from the end of the list.

This was the behavior before. It's unchanged, proven by the tests.

Change-Id: I04b8a14fbec7be5a1c4defabf92e94f694c1e638
2021-06-25 08:29:48 +02:00
Thiemo Kreuz 8f6098c03b Simplify spec code dealing with default values
The idea is to not actually store all these default values, but
fall back to the default only when needed.

Some more details:
* The only remaining property is ….name. The only reason to
  have this property is to distinguish between aliases and
  primary parameter names. This will be reworked in a later
  patch.
* The description falls back to null because this is the
  documented fallback, not undefined.
* The default value falls back to "", same as the auto-value.
  Why not null you might ask. This is intentional. Both the
  auto- and default value are effectively wikitext snippets,
  while the example is a label in the VE UI.

Bug: T285483
Change-Id: I1be3cca18f9ad6fc1c16362b24633f7613f02539
2021-06-24 18:13:41 +02:00
Thiemo Kreuz bab08440ea Fix getDescription/Sets possibly returning undefined
This is done for two reasons:

1. It fixes the behavior of two methods in rare edge-case
situations. They aren't documented to return undefined.

2. It reduces the amount of stuff this class stores when it's
nothing but a default value anyway. Note this patch does this
for the template-level properties only. Another patch will do
the same for the parameter-level properties.

Bug: T285483
Change-Id: If2e4d56da1fa52e32dc94191f36d7dc6a1487829
2021-06-24 18:07:46 +02:00
Thiemo Kreuz 2529d33f51 Better name for spec.isParameterKnown() method
This reflects much better how this method is meant to behave.

Note I will continue to remove documentation that doesn't
explain anything in addition to what the code already says.

Bug: T285483
Change-Id: I81fa8a5d9d0752f3aeac4015c9a27b50e054d4df
2021-06-24 18:05:14 +02:00
Thiemo Kreuz 30dc85f53b Better name for spec.getParameterName() method
This reflects much better what the method is for.

Bug: T285483
Change-Id: I7c90643421e32946fce4de813c7614b806b261f0
2021-06-24 18:02:52 +02:00
Thiemo Kreuz 3d02c1f364 Add new QUnit test for ve.dm.MWTemplateSpecModel
This patch also marks 2 methods as @private that are not and
should not be used outside of this class.

Bug: T285483
Change-Id: I8a8ffc4868a369b5c47068beb0e83f023872543d
2021-06-24 17:59:38 +02:00
Adam Wight 1909fdff92 Revert "Revert "Fall back from explicit parameter order to TemplateData sort""
This reverts the revert commit d47b95eb4a.

When no `paramOrder` is given, known parameters should appear in the
order returned from the TemplateData API.

Previously, when TemplateData was present but no paramOrder
specified, then the parameters would appear in alphabetical order as
"unknown" parameters.  Now they will appear in the order listed in
TemplateData.  This is similar to the fully-specified behavior when
paramOrder is present.

This will only affect the Visual Editor template dialog, and has no
effect on serialization.

Bug: T274545
Change-Id: If8315781572af688ea1c1b14b3694b828f076b4a
2021-06-23 16:39:13 +02:00
Adam Wight 05bcb89f3f Tests for parameter serialization order
The results show that parameter order always follows the appearance
in the template invocation, regardless of `paramOrder`, whether the
parameters are aliased, or whether there are unknown params.

Bug: T285382
Change-Id: I76c6fe8f0a2482cf0856bbafd9f21ba9fc4919a4
2021-06-23 16:38:30 +02:00
Awight d47b95eb4a Revert "Fall back from explicit parameter order to TemplateData sort"
This reverts commit 12f3ce5ed3.

Reason for revert: Considered undesirable, per T138200

Change-Id: I089a47b41a0bb0405841690ca577035cf95a8016
2021-06-22 17:50:16 +00:00
Adam Wight 12f3ce5ed3 Fall back from explicit parameter order to TemplateData sort
When no `paramOrder` is given, known parameters should appear in the
order returned from the TemplateData API.

Previously, when TemplateData was present but no paramOrder
specified, then the parameters would appear in alphabetical order as
"unknown" parameters.  Now they will appear in the order listed in
TemplateData.  This is similar to the fully-specified behavior when
paramOrder is present.

This will only affect the Visual Editor template dialog.

Bug: T274545
Change-Id: I32538de07641c288081042a41fe39eedfed7d939
2021-06-22 13:24:44 +02:00
Adam Wight 33701872c7 Tests for getAllParametersOrdered
Note that the tests expose a bug, getAllParametersOrdered fails to
list an unused parameter.  Fixed in I32538de07641c.

Also, a minor fix to avoid an impossible template spec: paramOrder
must include all parameters.

Bug: T274545
Change-Id: Icfa7a765773d04ef05a76ecc09467305e311f6cb
2021-06-22 13:23:59 +02:00
WMDE-Fisch c4f59132ae Only add asterisk after word characters in improved template search
This will avoid that the search breaks in edge cases where symbols
are used.

Including a fallback for ES5 browsers. The fallback should cover
almost all cases. Worst case would be not adding the asterisk even
though it might be valid.

Bug: T284554
Change-Id: Ie4aee0b77492b7a73bc251a8723a206dbd641600
2021-06-21 21:07:28 +02:00
WMDE-Fisch 407ff95597 Rename OutlineParameterCheckboxWidget to OutlineParameterCheckboxLayout
This not really just a checkbox widget anymore it inherits from
FieldLayout and became something more in that direction.

Let's use a mixture of these things to make it a bit clearer.

See also comment in Ie81b84be288553343017c4aaf8691c4e266995f5

Change-Id: Iff1746a8e5e94b56eb6c27465405aaf6b74c2310
2021-06-21 09:08:54 +02:00
Adam Wight 9e1c76f0fc Tests for MWTemplateModel parameter ordering
Documents existing logic.

Bug: T274545
Change-Id: Iebcbdb186862060724d29b36112b2d262112c4c8
2021-06-18 13:43:15 +02:00
Adam Wight 988cda65dd Template dialog checkbox list
Introduces new widgets forming the backbone of the experimental
template dialog sidebar.

FIXME: `text-overflow: ellipsis` is not working yet, the container
styles need adjustment.

Bug: T274543
Change-Id: Ie81b84be288553343017c4aaf8691c4e266995f5
2021-06-17 08:47:47 +00:00
Thiemo Kreuz 621bca1df4 Show redirects as part of description in template search
These are the most minimal (and therefor most stable,
hopefully) hacks I could come up with so far.

Bug: T274903
Change-Id: I28ba414dd34aad756e29400eb656f0942291a923
2021-05-27 12:40:51 +02:00
Ed Sanders a71dd4f797 Ensure correct classes are added to surfaces
* Create getSurfaceClasses method.
* Pass surfaceClasses to target widgets.

This ensures that the 'content' class is passed to mobile
target widgets, and the 'mw-body-content' class is added
in a less hacky way.

Change-Id: Ibce6d1a1d0fda63cca354761f1b91f808858e95b
2021-05-23 20:04:28 +01:00
jenkins-bot a4d1863a80 Merge "Use standard search API when searching for templates" 2021-05-03 08:12:35 +00:00
Thiemo Kreuz 6e08a27fc7 Use standard search API when searching for templates
Bug: T274903
Change-Id: I7de8f6cc55ab678ed741ae5ebbaad608b9a9b0db
2021-04-30 12:52:45 +00:00
Thiemo Kreuz 346216c050 Update more test code to use ES6 syntax
This patch is mostly about the arrow syntax.

Some places can not be updated because the arrow syntax also
changes the meaning of `this.…`, but some code relies on that.

Change-Id: Ida3ab0e0950a428fbd1a85f281013778ee879df4
2021-04-30 10:08:45 +00:00
Thiemo Kreuz 2611f907a9 Update all tests in the ve-mw module to use ES6 syntax
Change-Id: I75f8864c66c9b2a78c683d425d54a94515b74f24
2021-04-30 08:07:54 +00:00