Commit graph

732 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 18a18bc825 Merge "Fix incomplete template dialog event handling in new sidebar" 2021-07-16 13:07:03 +00:00
jenkins-bot 4ab5fd5c6b Merge "Add a message next to undocumented parameters" 2021-07-16 12:05:29 +00:00
Thiemo Kreuz 434c11f6de Fix incomplete template dialog event handling in new sidebar
Notably:
* Don't require the model in the new sidebar via dependency
  injection, but connect the event handlers later. This is
  relevant because we currently create the new sidebar in the
  wrong spot. Removing the hard dependency allows us to split
  the code and utilize initialize() and getSetupProcess()
  correctly. This will be done in a following patch.
* The change event now includes the new position. This makes
  it very easy to add this missing feature to the new sidebar.

Also:
* Stop triggering change events when nothing changed. These
  events are expensive. They bubble all the way up to the
  TransclusionModel, and to all linked
  onTransclusionModelChange() handlers.
* Update event documentation to make this more visible.

Bug: T274544
Change-Id: Iafe29f18a6fed14d9c3124c9756aa840886afbbc
2021-07-16 11:29:26 +00:00
Thiemo Kreuz 1164f67f40 Tweaks and cleanups to template parameter search
Notably:
* Include parameter aliases, labels and descriptions in the
  search.
* Don't use a possibly outdated search index, but live data.
* Clear filter when a new checkbox is added.

Bug: T272481
Change-Id: Ie90a803af6178a8bb6de370a0f8e079800d9f8a2
2021-07-16 12:11:13 +02:00
Andrew Kostka f02c48ea52 Add a message next to undocumented parameters
Bug: T274550
Change-Id: I1af71150239ebc9966cc22e7d28883fbac99fdf1
2021-07-15 14:47:21 +02:00
Thiemo Kreuz 766b220f5a Finishing touches to new template editor sidebar
In detail:
* Allow clicks on all elements in the new sidebar. This should
  focus the corresponding element on the right.
* Make all elements in the new sidebar tabbable.
* Fix MWTransclusionOutlineTemplateWidget.createCheckbox() to
  not need a temporary param object any more.
* Rewrite more code in MWTransclusionOutlineTemplateWidget to
  be shorter and easier to read.
* Fix MWTemplateModel.addParameter() to not do way to much
  stuff when a parameter already exists.
* Update code documentation.
* Use more specific, less ambiguous variable and method names.

Bug: T274544
Change-Id: Iaf6f7d1b0f7bf0e9b03eb86d01f3eceadece6fe4
2021-07-15 08:40:35 +00:00
jenkins-bot 240a405dfa Merge "Remove unused parameters from MWTransclusionModel methods" 2021-07-12 09:05:51 +00:00
Thiemo Kreuz fae6118071 Document and use mw.Api parameter defaults
Reasoning:
* format=json must be the default. Nothing else makes sense in
  the context of this code. This should not be a surprise.
* formatversion=2 is only a default when the custom
  getContentApi() is used, but not when mw.Api is used. One
  might argue that it's safer to always specify formatversion=2.
  However, this is not done in other places in this codebase.
  It should never be done or always.
* I find it confusing when the action=… is missing. Let's not
  rely on this default.

Change-Id: I6ca29f76bffc0849103c5bcff4aaf28fcaaa4c52
2021-07-12 09:13:59 +02:00
jenkins-bot c2bc8c7e26 Merge "Move code that belongs to the template specification" 2021-07-08 08:46:40 +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 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 e3d3fd9eaf Remove unused parameters from MWTransclusionModel methods
Change-Id: Icdeddb92a498e0dd1182b19de1c4effdb1741fef
2021-07-06 15:47:32 +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
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 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
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
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 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 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
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
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
jenkins-bot f442bbfd55 Merge "Remove unused MWTransclusionModel.specCache property" 2021-06-29 21:47:14 +00:00
jenkins-bot 82821f6889 Merge "Rename ambiguous "lang" to languageCode in spec class" 2021-06-29 09:46:51 +00:00
jenkins-bot 297cb53e33 Merge "Remove spec documentation that literally repeats the code" 2021-06-29 09:46:49 +00:00
jenkins-bot d588a736c2 Merge "Fix all spec methods to not crash on unknown parameters" 2021-06-29 09:41:07 +00:00
jenkins-bot c84dd3d44f Merge "Use separate data structure to store aliases in spec" 2021-06-29 09:41:05 +00:00
Thiemo Kreuz 121bf88f48 Remove unused MWTransclusionModel.specCache property
This property is a reference to a static variable with the
same name, initialized at the very top of the file. All
instances of the class use the same cache. They all use the
shared specCache directly, not the reference.

Depends-On: I0084410b7eab29048451ad67c18d6c2180c4f1b1
Change-Id: I9fd79ce3abd533dbb48a210e596802ea9e692855
2021-06-29 08:20:21 +02:00
jenkins-bot 9fcba8bac8 Merge "Minor documentation updates in template related classes" 2021-06-28 14:46:11 +00:00
Thiemo Kreuz 4b62bc5bf1 Rewrite MWTransclusionNode.isSingleTemplate for readability
* Introduce variable names that explain better what's going on.
* Add comments.

Bug: T284895
Change-Id: Id5e8be9e52342ce049bdceec71f0f7cd01a6e2e9
2021-06-25 16:51:53 +02:00
Thiemo Kreuz 26b0322ff0 Minor documentation updates in template related classes
Bug: T285483
Change-Id: I1cf17d7bfb01326b93bc781b2501a492d50f0aab
2021-06-25 16:46:59 +02:00
Thiemo Kreuz 6f2d98ee68 Rename ambiguous "lang" to languageCode in spec class
Change-Id: I1382a453cd3dda2b584ae8b0993fb3e4ac963ce0
2021-06-25 08:40:16 +02:00
Thiemo Kreuz fb14183f3c Remove spec documentation that literally repeats the code
These comments don't add any knowledge. The text is either
duplicated, or the method signatur says it already. Having
to read these comments just to realize that they don't give
any additional information is not helpful, even error-prone.

Change-Id: I014028b1e9311b831a22c37859b2130aed2e9539
2021-06-25 06:38:37 +00:00