Commit graph

549 commits

Author SHA1 Message Date
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
Svantje Lilienthal 066c663864 Add parameter search to sidebar of VE TemplateDialog
Bug: T272481
Change-Id: If044e5d134f1b24f939c4786949e6ca34fb79e1e
2021-07-16 09:48:29 +00: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
Thiemo Kreuz ff9f8a9e2d Focus template editor elements on click in the new sidebar
Clicks on the left side now focus elements on the right
side.

This patch also simplifies the …ContainerWidget constructor.
The config parameter should only be used for "OOUI things"
that are needed by subclasses and mixins. But the parameters
we have here are not "UI things".

Passing them as config passes them to classes where we don't
know what they do with it. What probably happens is that
some class keeps a reference to the entire config object,
which doesn't have a benefit and possibly blocks garbage
collection.

Bug: T274544
Change-Id: I0c0e4a1ba59dcb43141338ffe939c9c6783e000d
2021-07-15 08:40:28 +00:00
Thiemo Kreuz 198c5dba77 Make button to add undocumented template parameter work
Thanks to the widget now being an actual ButtonElement.

Bug: T274544
Change-Id: I1b0ef28b0aa115a027a07f3ae53c583598483e96
2021-07-15 08:40:20 +00:00
Thiemo Kreuz eb1f1e28a3 Make new template editor sidebar items actual ButtonElements
Actually reusing this OOUI mixin gives us a lot of well
developed functionality we need anyway. Most notably proper
event management, e.g. click events.

The number of CSS properties we need to override is managable,
I would argue. Let's see:
* Our buttons are not inline-elements, but should use the full
  width.
* No focus-border left and right for the same reason.
* We want much more inner padding.
* We want a stronger hover effect.
* We need to fine-tune the position of the icon. This is
  because of the inner padding.
* Need to get rid of a negative margin that's only relevant
  for inline-buttons.

I currently feel like the benefits are worth living with
slightly more brittle code. Note that we can undo this change
any time because all this is well encapsulated in this new
class.

Bug: T274544
Change-Id: I33f275a958964d49e803e56bf74a6fa961093da1
2021-07-14 13:31:40 +02:00
Thiemo Kreuz 170ca9d58a Reuse generic button widget for elements in the new sidebar
This introduces another generic "button-like" class that can
be reused in multiple places in the new sidebar. The main
change in this patch is the "add more information" button
which is now an instance of this new class as well.

This patch also simplifies over-complicated setup code in
related widgets.

Bug: T274544
Change-Id: I0cfe7675d02fdd5c5dc8d9198bb3f4aec9abf397
2021-07-13 17:23:27 +00:00
Thiemo Kreuz 31904688df Update new sidebar when moving template parts up/down
The new sidebar now updates accordingly when elements are
moved around.

Bug: T274544
Change-Id: Ic6bc3484c54523aa4edc6b48a843c47059569061
2021-07-13 10:18:20 +02:00
Thiemo Kreuz 226e2657ef More robust debug container for new template editor sitebar
Before, the new sidebar was hacked in a place where it confused
the BookletLayout logic. This became visible when using the
up/down buttons to move elements in the sidebar.

This new container wraps the new and the old sidebar. It also
uses a temporary color to make it easier to see where one ends
and the other starts.

Bug: T274544
Change-Id: I4e5b40b1d1556886fc85cff9e926a02e4888f032
2021-07-13 09:11:57 +02:00
jenkins-bot 5bd9eff8ea Merge "Full add/delete support for all 3 types in template sidebar" 2021-07-12 14:04:32 +00:00
jenkins-bot f92d85604c Merge "Add template outline widgets for all content types" 2021-07-12 10:52:19 +00:00
Thiemo Kreuz 5edf7dac18 Full add/delete support for all 3 types in template sidebar
From now on you can remove and add all 3 types of content from
the new sidebar.

Bug: T274544
Change-Id: If1e04ff503d72cbe9ea07c8036c9e3a0547cc0d0
2021-07-12 10:15:14 +00:00
jenkins-bot af8c144091 Merge "Move template outline item header into the base class" 2021-07-12 09:24:38 +00:00
Thiemo Kreuz a1384f34f3 Add template outline widgets for all content types
The two new widgets are pretty trivial now, thanks to the base
class.

Note there is still no code to delete the widgets. That's also
why you will always see a placeholder widget at the top. This
will be fixed with the next patches.

This patch also renames most of the "…TemplateOutline…" classes
to "…TransclusionOutline…" The reason is that these widgets are
not for a single template, but part of the container widget for
a more complex transclusion (i.e. a sequence of multiple
templates and wikitext snippets).

Bug: T274544
Change-Id: If4219b0b8ad4d1969ab1ec5ec4db0728811bab35
2021-07-12 09:19:06 +02:00
Thiemo Kreuz 2854be165e Move template outline item header into the base class
The icon and the name of the template are now created by the
base class. This is meant to be reused for other elements
that are not templates.

Bug: T274544
Change-Id: I76bbc0e8c0420e9c6357d093d5f5e1651a0c2719
2021-07-12 09:17:30 +02: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 1569ab0a28 Merge "Remove empty container widgets that don't do anything" 2021-07-09 16:14:25 +00:00
jenkins-bot 0f1bef39b4 Merge "Abstract base class for top-level items in template editor" 2021-07-09 16:09:42 +00:00
jenkins-bot 48f711cd5c Merge "Rename CSS classes in new template dialog sidebar code" 2021-07-09 16:09:40 +00:00
Thiemo Kreuz 4018439348 Remove empty container widgets that don't do anything
This code doesn't do anything but adding an empty <div> to
something that is already a <div>. It doesn't even have a
class name, i.e. it's not referenced from anywhere. We can
add such containers back any time when it turns out we
actually need them.

Bug: T274544
Change-Id: I62546cc7939364db31f37b9de0c035974554544b
2021-07-09 15:57:11 +02:00
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 12dca65912 Delete last template search result, not a random one
Because the API uses a generator, the search results are ordered
alphabetically. The actual search result ranking is in a .index
field. This code accidentially deleted the alphabetically lowest
template instead of the least relevant one.

Change-Id: I79de024feb569e9f06bedab908a6509a4d4fa99b
2021-07-08 15:33:42 +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 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
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 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
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 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 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 db531ddba5 Add missing search result limitation to template search
Bug: T274903
Change-Id: If57d28f7796d69825a25fa9b67bcd5c127c9e3b7
2021-07-01 09:33:52 +02:00
jenkins-bot f9cb2e3519 Merge "Don't create a checkbox for ve.ui.MWParameterPlaceholderPage" 2021-06-30 14:31:59 +00:00
jenkins-bot 0e3bf54e3f Merge "Add documentation to ve.ui.MWTemplateOutlineTemplateWidget" 2021-06-30 14:31:57 +00:00
jenkins-bot 217793ebd1 Merge "Use the parameter's label in the sidebar" 2021-06-30 14:31:55 +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
Andrew Kostka 0c141e2581 Add documentation to ve.ui.MWTemplateOutlineTemplateWidget
Change-Id: Ibc0b39fd417fa7eef5cf1cd52b9769c6514ce85d
2021-06-29 21:50:41 +02:00
Andrew Kostka 30917c8ba3 Don't create a checkbox for ve.ui.MWParameterPlaceholderPage
Change-Id: Ia02e86e026e618a4ace31306fe50f003c49080ae
2021-06-29 21:21:19 +02:00
Andrew Kostka 526a49672e Use the parameter's label in the sidebar
Change-Id: Ic2c00f51088d67453bb50ff0fa15f22c9fbd8e56
2021-06-29 20:44:17 +02:00
jenkins-bot 802be178e3 Merge "Extract MWTemplateTitleInputWidget.addExactMatch into a method" 2021-06-29 13:47:03 +00:00
Thiemo Kreuz (WMDE) e6d3828429 Revert "Extract "show all" to placeholder class"
This reverts commit 950a5300dc.

Reason for revert: This broke several workflows. The reason is
that MWParameterPlaceholderPage & MWParameterSearchWidget both
hold references to the MWTemplateModel. This model is not
always the same. The dialog might be the same when a template
is edited multiple times. But the model might be a new one.
From this point on the MWParameterSearchWidget pulls data from
an outdated model.

Bug: T284636
Bug: T285571
Change-Id: I7b9ea8cab8f17705ec8020f07e3732da6ba0e73c
2021-06-28 14:04:12 +02:00
Thiemo Kreuz b3bede3ba0 Extract MWTemplateTitleInputWidget.addExactMatch into a method
Same as in TemplateWizard, see I128bc00.

Bug: T274903
Change-Id: I8693b85625a8640e44c213300d7c6862430bec47
2021-06-25 17:07:32 +02:00
jenkins-bot ec2c42932d Merge "Label for each template in sidebar" 2021-06-24 12:34:52 +00:00
jenkins-bot acc41f5ed6 Merge "Wiring for adding and removing parameters" 2021-06-24 10:55:46 +00:00