Commit graph

8186 commits

Author SHA1 Message Date
Thiemo Kreuz cfe2dadc93 Abstract base class for top-level items in template editor
This base class will be used to style the 3 types of top-level
items in the sidebar the same way, without the need to
duplicate code or styles.

Bug: T274544
Change-Id: I1a62ff610728d7150dea1717316ef20f6882783a
2021-07-09 15:48:08 +02:00
Thiemo Kreuz 1849924eff Rename CSS classes in new template dialog sidebar code
This matches the existing naming scheme better. I also plan to
re-use this class for other types that are not templates.
That's why the name is the more generic "transclusion" now.

This patch also removes a `padding: 2px` that's not that
helpful. We will need paddings later, but need to choose them
much more carfully.

Bug: T274544
Change-Id: I6f0f630da2230b023b3fb065e5ad86d8211bb7b3
2021-07-09 15:29:29 +02:00
Thiemo Kreuz ba1718ea11 Always add 1 prefixsearch match when searching for templates
We do this additional prefixsearch anyway. What we did before
was ignoring the result when it was not a 100% exact match.
Instead we can always add this 1 prefixsearch result when it
was not already part of the CirrusSearch result set.

This won't happen often. Usually the 1st prefixsearch result
was already part of the CirrusSearch result set anyway. But
if it wasn't, that's a serious issue for expert users that
expect the search to behave similar to the suggester at the
top of the MediaWiki interface (which is also a prefixsearch).

Change-Id: I959d2b058a3d64596a8cfbe5476ab351e40f8760
2021-07-08 11:15:34 +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
jenkins-bot 5c738aa74f Merge "Fixes and updates to template related JSDoc tags" 2021-07-08 08:24:44 +00:00
jenkins-bot c0b7783fc3 Merge "Change style for adding an "Unknown field" in the parameter search" 2021-07-08 08:20:59 +00:00
jenkins-bot 06f63bdc10 Merge "Remove unnecessary code from template related classes" 2021-07-08 07:39:14 +00:00
jenkins-bot 275fb5a2d6 Merge "Remove duplicate code from ve.ui.MWParameterSearchWidget" 2021-07-08 07:39:05 +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 d68e110e67 Fixes and updates to template related JSDoc tags
Some details:
* The config is not optional in these cases.
* This patch continues to remove some comments that don't add
  any information but just repeat what the code already says.

Change-Id: I5c27cd01ad80709bb583256821d65c6b65b74b05
2021-07-08 06:36:56 +00: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 5160c4d520 Merge "Allow text selection on the "More"/"Less" button fade effect" 2021-07-07 09:47:45 +00:00
Thiemo Kreuz 1c98f4cce0 Remove unnecessary code from template related classes
For example, checking if a parameter is required works just fine
for unknown parameters. They are never required. Since I16708b0
we don't need to guard the spec related methods any more.

Change-Id: Id90e4cb810dc9faca3b26f122a534f276ee31709
2021-07-07 10:18:41 +02:00
Thiemo Kreuz f6e5866deb Allow text selection on the "More"/"Less" button fade effect
It's good practice to make transparent elements transparent
for mouse clicks as well, i.e. make it possible to select text
behind the fade effect.

Bug: T283943
Bug: T286235
Change-Id: Ib5022a74c70e4b7cb5e2a0faad20bd9abcc0da36
2021-07-07 07:48:28 +00:00
Thiemo Kreuz f04feb043f Remove duplicate code from ve.ui.MWParameterSearchWidget
Introduced in 2 separate patches by the same author. This
patch removes the line that was introduced last.

Change-Id: I77575f7afe0f9276c7b54ee44d828e7ccb87c978
2021-07-07 09:34:50 +02:00
Thiemo Kreuz 137be4438f Remove unused .getWikitext() methods from transclusion classes
These methods are special in so far that they create *minimal*
wikitext where optional whitespace is not preserved. I tried
to rename the methods to reflect this, but could not find a
caller. What's used instead are the .serialize() methods.

Bug: T284895
Change-Id: Iedaa5b7efa9675151cc0553854d8aef3f9a46cbb
2021-07-06 10:58:11 +02:00
jenkins-bot 9e6387176b Merge "Add @private/@protected documentation to template dialog code" 2021-07-06 08:41:55 +00: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
jenkins-bot 8504fd9545 Merge "Minor code cleanups to the MWTemplateSpecModel class" 2021-07-05 10:01:46 +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
Thiemo Kreuz 16ca60009b Minor code cleanups to the MWTemplateSpecModel class
Bug: T285483
Change-Id: I22005907effe855ab5e830c94d2bc32c640b5aa5
2021-07-05 09:16:23 +00:00
jenkins-bot 6acdb3bc8e Merge "Add missing JSDoc documentation to template related classes" 2021-07-05 09:09:40 +00:00
jenkins-bot 7cd766becf Merge "Avoid calling own getters in template model class" 2021-07-05 09:09:38 +00:00
jenkins-bot a19bc2960f Merge "Keep undocumented parameters in the sidebar when unchecked" 2021-07-05 09:06:32 +00:00
jenkins-bot 8718ac8ece Merge "Fix parameter ordering when using aliases" 2021-07-05 08:33:01 +00:00
Andrew Kostka a867469b7b Keep undocumented parameters in the sidebar when unchecked
Bug: T274550
Change-Id: I010006cdbe5ce5cb79cc4248840d74cb992ff834
2021-07-05 10:17:55 +02: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 b849131e74 Add missing JSDoc documentation to template related classes
This also removes a few lines of text that don't explain
anything that would not be obvious from the code or @return
tag anyway.

Change-Id: I2f8f02dd61c50d9990d72c0e8ea79d679c9b11f2
2021-07-05 09:32:22 +02: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 34cbf1ebbf Avoid calling own getters in template model class
This is just not necessary. It removes a level of indirection
that possibly makes it harder to understand the code. It makes
it easier to possibly get rid of unused methods.

Change-Id: Iaf8b213a5e1ae64a24b5bcdf2a0b200d5d3cbf46
2021-07-02 17:30:54 +02: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
Thiemo Kreuz bc1885c36f Store TemplateData JSON as is instead of copying values
Just store the JSON blob from the TemplateData API as is.

This comes with a bunch of nice consequences:
* Less code.
* Less class properties that don't do anything but copy what's
  in the TemplateData blob.
* Easier to understand what's going on. The `this.templateData`
  property is now a reference to the *actual* TemplateData
  documentation.
* No need to cache the documentedParamOrder. Just do it when
  needed.

This also removes an unused feature from the `extend()` method
that didn't made sense anyway. Before it was possible to merge
conflicting documentations. But this is not only unused, it's
impossible to have multiple documentations for the same
template.

The method acts as a straight setter now. The next patch will
rename it accordingly.

Bug: T285483
Change-Id: I3ffc202577e9a20fc7491234601ccd981113f866
2021-07-02 11:25:47 +00:00
Thiemo Kreuz 0d9cb6f1bb Track seen parameter names in separate data structure
Instead of faking entries in this.params, let's use a separate
tiny data structure to keep track of parameters we have seen so
far, and in which order.

This finally allows to easily distinguish between documented and
undocumented parameters.

Bug: T285483
Change-Id: Idf62b0661178a3bbef7e817edf016dbd572d415b
2021-07-02 13:24:43 +02: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
jenkins-bot 7afb7981d1 Merge "Rewrite MWTemplateDialog.setApplicableStatus for readability" 2021-07-01 11:56:30 +00:00
jenkins-bot 5028f4eaf3 Merge "Remove unused "insert" action from MWTemplateDialog" 2021-07-01 11:52:21 +00:00
jenkins-bot 50f293019c Merge "Rewrite MWTransclusionNode.isSingleTemplate for readability" 2021-07-01 11:21:44 +00:00
jenkins-bot 3709dfbee2 Merge "Update documentation for all getWikitext()/serialize() methods" 2021-07-01 11:18:08 +00:00
Thiemo Kreuz f1a66c17e4 Rewrite MWTemplateDialog.setApplicableStatus for readability
I rearranged this piece of code like a dozen times before I
finally understood what it actually does. This should be much
more obvious now.

The idea is:
* If no edit was made the button is always disabled.
* You can save pretty much everything, except when the
  transclusion still starts with a placeholder.
* You can also click the done button when the dialog is empty.
  This feels a bit odd, but was like this before. I think this
  codepath is unreachable. But it probably doesn't hurt to
  keep it.

Bug: T284895
Change-Id: Ic483201b64fd64f414c5b1ec4c44198b8eadb9f2
2021-07-01 11:20:50 +02: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
Thiemo Kreuz 55a49195ba Add @private/@protected documentation to template dialog code
These tags don't do much, if anything. But they provide a hint
in which scope a method might be used.

Bug: T284895
Change-Id: I0b4bdd416ee89d26961c4ded4d8bbace8c57da76
2021-07-01 09:36:00 +02:00
Thiemo Kreuz db531ddba5 Add missing search result limitation to template search
Bug: T274903
Change-Id: If57d28f7796d69825a25fa9b67bcd5c127c9e3b7
2021-07-01 09:33:52 +02:00