Commit graph

755 commits

Author SHA1 Message Date
jenkins-bot b99ed46e1b Merge "Improve test coverage of template dialog outline" 2022-06-13 12:24:01 +00:00
Ed Sanders 5d060c34cc GalleryImageNode: Handle broken images
Most of this logic copied from MWBlockImageNode.

Change-Id: I92c860c53741c5ee48c8bce216987d97a92bc05f
2022-05-23 15:29:42 +01:00
Ed Sanders fb1ed9e700 MWGalleryImageNode: Avoid converting altText from null to ''
Bug: T308747
Change-Id: Icd811a6baaa2213d8615bdcb3690d26aa35ab302
2022-05-21 04:09:41 +02:00
Thiemo Kreuz 9297428eca Improve test coverage of template dialog outline
This focuses on some scenarios that are
a) complex enough to be worth a test,
b) but simple enough so I don't need to spend hours on comming up
   with a test setup. ;-)

This patch also simplifies the ARIA related code in
MWTransclusionOutlinePartWidget a bit.
* Check 1 of the 3 ARIA configs only. Only having one is already
  helpful and should not be skipped.
* No need for the large conditional. setAriaDescribedBy() works fine
  with undefined.

Bug: T291157
Change-Id: I142782ec9b96147de64497f4f6a373eae05b9c8e
2022-05-04 12:01:58 +02:00
WMDE-Fisch d996288169 Move message about missing parameters to sidebar
Will be removed when parameters are added. Needs different margins
depending on beeing shown in the single transclusion mode without
header or on multiple transclusions.

Bug: T300710
Change-Id: Ieb95d7276aa4d4b0fcbb74f87ab734e4a393dc21
2022-04-29 10:03:23 +02:00
Thiemo Kreuz 8831887e3c Update template search fallback to max out at 10
Before, the fallback algorithm was somewhat adaptive, trying harder and
harder the fewer CirrusSearch results have been found. This updated
algorithm guarantees that 10 results are shown.

Warning: You might see only 9 results. The reason is a bogus, unrelated
behavior in the mw.widgets.TitleWidget in core that's used as a base
class here. There is a "showMissing" option that's apparently enabled
by default, and prepends a non-existing title from the main namespace,
ignoring the "namespace" option. This extra result from the wrong
namespace is later dropped by the very same widget.

This code here sees 10 results before the bogus one is dropped.
Disabling "showMissing" causes other issues. We would need a series (?)
of custom hacks to work around all this, but this seems inappropriate.
Let's live with 9 for the moment.

Bug: T303524
Change-Id: I2c577c9ef2752b6c6cd360f4023e151e9272fcd5
2022-04-21 09:25:00 +00:00
Thiemo Kreuz 50497ee7f3 Drop assumption that all template search index start at 1
The main advantage of this change is that it drops the assumption
that the index starts with 1. This is not necessarily the case when
we prepend extra search results. Dropping this assumption here allows
to simplify such code.

* The incoming list of pages is guaranteed to be an array.
* There is no point (any more) that could cause the array to become
  sparse.
* Note we still make a copy of the `origPages` array at some point,
  e.g. on `.filter()`.

Bug: T303524
Change-Id: Ifbd92bb052155c613d2ca21ab6d54a0b3ef28c0c
2022-04-21 11:23:48 +02:00
Thiemo Kreuz 89e5c2fb92 Disable useless "showMissing" option in TemplateTitleInputWidget
This option is not only buggy (it just doesn't work when the namespace
option is set the same time), it is not useful in this context even
if it would work. It doesn't make much sense to suggest non-existing
templates in the context of the template dialog. If adding a
non-existing template really is what the user wants, they can still do
this by simply typing the name of the template and submitting the form.
We never need this to show up in the suggester below the input field.

The main advantage of this change is that is saves 1 useless API
request that's potentially done every time a key is pressed.

Bug: T303524
Change-Id: I903340a06d6e6490bb58f628f41903aa044ccb21
2022-04-20 14:43:29 +00:00
Thiemo Kreuz d3d3e1cf75 Move "index from redirect" logic up in template search widget
This separates the two steps:
1. See if items in the list of `origPages` miss their `.index`
   property, and add it if possible.
2. Later code doesn't need to care about redirects any more.

Note that `origPages` is not used for anything else. And even if,
it's not wrong to have the index for each search result on both the
redirect and the redirect target.

Change-Id: I12135f0430c944b4e33c49ece7779d7c3bb6c211
2022-04-20 14:50:36 +02:00
Thiemo Kreuz e24c8ecd2d Fix misleading variable name in TemplateTitleInputWidget
This is not a pageid, but a simple numeric index in an array. Luckily
it doesn't make a practical difference for this particluar way of
iterating something.

Change-Id: I7ec9ace00d4fba7adde17670058a0365b30f5617
2022-04-19 14:40:00 +00:00
Thiemo Kreuz af2779fc06 Fix API response default in TemplateTitleInputWidget
The result is guaranteed to be in formatversion=2, where the list of
pages is an array, not an object.

Change-Id: Ic73a68c3e249a70108a6a19a89f4ff6c475794ed
2022-04-19 13:35:27 +02:00
jenkins-bot 616fa37de4 Merge "Fill template search results with prefix matches when Cirrus fails" 2022-04-08 11:57:23 +00:00
jenkins-bot 5fef22001d Merge "Full fallback to prefixsearch when Cirrus returns nothing" 2022-04-01 13:24:51 +00:00
Thiemo Kreuz 912bc34f62 Fill template search results with prefix matches when Cirrus fails
This code is optimized for the 2 most relevant use cases:

1. When Cirrus finds 10 results, we still want to search for the top 1
prefix match. This is critical for templates like !!. This will appear
at the top. unshiftPages() makes sure the limit of 10 is enforced.

2. When Cirrus fails to find anything, we search for 10 prefix matches
and use these instead.

The code can also handle everything in between. For example, when
Cirrus finds 5 results, we search for 5 more prefix matches and add
them when Cirrus missed them. The total number in the end might be 5 to
10 depending on the number of duplicates. This is intentional. Why?
Let's say we always search for 10 prefix matches and add them to the
top when Cirrus missed them. This might remove _all_ Cirrus results.
This shouldn't happen. This extra code is only to fill in glaring gaps,
not to replace Cirrus. 5 results are fine.

Bug: T303524
Change-Id: Ib0471795124c0c7001b6901edaf8e7b380e426b1
2022-03-29 13:18:12 +02:00
Thiemo Kreuz 6bbf7d1907 Full fallback to prefixsearch when Cirrus returns nothing
There is already some kind of "fallback" to prefixsearch. We always
check if the top-1 prefixsearch result is part of the result set.
Because of this the current worst-case scenario is that only this
1 result is shown.

This patch implements a full fallback to prefixsearch. But only when
there are 0 CirrusSearch results. Further tuning might be done in
later patches.

Bug: T304925
Change-Id: I1927eedad60c9b9ac2021481a85376c08ccf6fdb
2022-03-29 13:17:05 +02:00
Thiemo Kreuz c8af207681 Use boolean RegExp.test() instead of .match() where possible
.test() is the dedicated syntax for a boolean "does match? yes/no?"
check. .match() returns an array of matches, or null. This is just not
needed in these situations.

Change-Id: Ibb996ab843d1a6c7d7af98d6a112990665d543b2
2022-03-24 11:04:43 +01:00
Thiemo Kreuz a6f784c095 Fix hiding unused template parameters sometimes not working
We ended mixing two concepts in a single method:

* We need a method that allows us to create the parameter list widget
when it's needed, even if it's empty. This is relevant when a template
is entirely empty, and the first parameter is added. This wasn't
working. Instead the parameter list was created with all parameters.

* On initialization we either want all parameters to be shown, or only
used ones. But this code is only needed once, on initialization. I
ended inlining this code in this patch.

Bug: T300640
Bug: T304046
Change-Id: I6620a870e4420dcb8fecf522b3274458eeec891d
2022-03-22 15:41:55 +01:00
Ed Sanders f6ea2e3457 Fix resize of MWAceEditorWidget when setting up
Bug: T303964
Change-Id: Ic8efbd7df74213fddaec987aff60e733f9550db2
2022-03-18 22:30:54 +00:00
jenkins-bot 401da7ee13 Merge "Remove MWDismissibleMessageWidget and use MessageWidget's showClose option instead" 2022-03-17 11:43:33 +00:00
jenkins-bot cada5a3ab8 Merge "Extract template scrollToTop method" 2022-03-15 12:17:50 +00:00
WMDE-Fisch 96dc96da8d Extract template scrollToTop method
Also putting the findFirstSelected to where it belongs.

Bug: T302965
Change-Id: Ibc56abfdf84a0b5eade5b6a44903d769f424206d
2022-03-11 12:30:51 +01:00
WMDE-Fisch 824648b32a Streamline hide unused handling
Extracted the state change so we do not need the `internal` var.

Change-Id: I0ce1afab35abf3e0e656ad1a3601513d55406537
2022-03-11 12:02:32 +01:00
WMDE-Fisch 037e7ad0b2 Scroll template outline into view when hiding unused
Due to the stickyness we need to scroll the header and the first
visible item from the parameter list to have the best result in all
cases.

We also only want to scroll when the user triggered hiding the
fields. Not when the template outline view is initialized.

Bug: T302965
Change-Id: I84d293888a7dbf13ec655c293c0fc3a79edca698
2022-03-09 19:45:07 +01:00
Thiemo Kreuz 836d36bc16 Skip initial creation of unused parameter widget
In a test case with 200 templates where all but a few parameters are
unused the loading time is cut in half.

Bug: T300974
Change-Id: Ice850cb9e5e95b9e3a19ff511b3a4f32117c7199
2022-03-02 10:19:46 +00:00
Ed Sanders 1b5550f485 Move var declarations inline
Mostly ve-mw/ui and a few left overs.

Change-Id: Idea0c94d974e661c49af8ad4545cd8fd98179ca8
2022-03-01 17:50:24 +00:00
Thiemo Kreuz 0d989b6fee Never collapse newly added templates in transclusion dialog
Bug: T300640
Change-Id: Id400951cf98f1eda780700d726fc10afbc1eaa90
2022-02-22 11:37:21 +01:00
jenkins-bot 839a62829d Merge "Add and fix default values in parameter documentation" 2022-02-21 13:41:51 +00:00
jenkins-bot 8c1ad11a7d Merge "MWEditSummaryWidget: Handle multi-line comments" 2022-02-21 13:39:01 +00:00
Thiemo Kreuz bc0a34b0ed Add and fix default values in parameter documentation
Same random finds while working on something else. I carefully
checked and made sure these methods are actually called without the
optional parameter.

Change-Id: Iab36fd130258322985b5d6e7f8e1f7b4ee235ba2
2022-02-21 13:19:21 +00:00
Thiemo Kreuz 58e27f56d6 Remove not needed self = this indirections
These are only needed when we need to access a specific `this` from
within another `function () {}` context. This is not the case in the
situations here.

This is split from Ibf25d7e to make it smaller and easier to argue
about.

Change-Id: Ide1476de91fc343aa992ad92a1321d3a38b06dd0
2022-02-21 10:52:24 +01:00
Lucas Werkmeister 957036fa19 MWEditSummaryWidget: Handle multi-line comments
The `.` character class matches any character *except* line terminators,
but edit summaries can contain those. Use [^] to match truly everything
in the comment part. (In the section part, I assume `.` is okay.)

Bug: T302103
Change-Id: I29fcdd7489d118674bab5cfe5c0a15b8e4efac64
2022-02-18 19:54:03 +01:00
WMDE-Fisch ce230afa09 Disable hide unused widget when all are selected
I bit more logic was needed to make sure, the state of the widget
resets when all unused fields are added during search.

Bug: T299811
Change-Id: I3006c233fda5490e323bc3a3e631bf0c1199bda3
2022-02-09 09:23:14 +00:00
jenkins-bot 7d297a20e9 Merge "Wire move/delete hotkeys to button functionallity" 2022-02-08 16:09:22 +00:00
WMDE-Fisch b35ea59de5 Hide unused paramters by default on multipart
Covers the base functionality to hide the parameters. Performance
optimizations could be done in a follow up.

Bug: T300640
Change-Id: Ia99b5da392273f1445e475a0720a656460612dcf
2022-02-08 15:56:40 +01:00
WMDE-Fisch ef87088198 Wire move/delete hotkeys to button functionallity
The behavior is now consistant with what would happen when the
buttons are triggered.

Instead of emitting a button click I directly wired the methods
that will by triggerd by the click. This might make it easier to
remove the old sidbar later.

To avoid movement when the buttons should be disabled, an
additional check was added to the onMove method. It's not identical
to the more complex check in the outlineControlsWidget, but should
be enough for our use case. The onDelete method already just does
nothing if nothing is selected.

Bug: T300971
Change-Id: I8a278c9657c91fd648944b5a8c1204c9fff75b7e
2022-02-08 15:41:01 +01:00
Ed Sanders b0e32c22fa Remove MWDismissibleMessageWidget and use MessageWidget's showClose option instead
This option was added in 0.43.0. Now that the close button is handled,
the remaining functionality (store a flag in local storage, and fixing
link targets) doesn't really justify a separate class, especially as
it's currently only used once.

Change-Id: I0fd81cadccc077dbf957302f9f41409c5a1f4f20
2022-02-03 16:37:52 +00:00
jenkins-bot 219e25fb8f Merge "ve.ui.MWEducationPopupWidget: Allow formatting in the popup text" 2022-01-25 18:39:28 +00:00
Thiemo Kreuz be5a752c8e Minor code cleanup in MWTransclusionOutlineTemplateWidget
Change-Id: I98904756e8ab9069634f644dc4d8631d1c0ee8fb
2022-01-23 17:09:46 +00:00
WMDE-Fisch 6cb0e7477e Hide parameter search when there are only 3 params
The search field is of not much use when there is not really anything
to search. It wastes more space than the actual list of parameters.

Approved by UX, see T298259#7626538.

Bug: T298259
Change-Id: I01784a1c463d8b0b504897b20179719f91597d19
2022-01-21 11:23:49 +01:00
Bartosz Dziewoński 9f54e34764 ve.ui.MWEducationPopupWidget: Allow formatting in the popup text
Bug: T298837
Change-Id: I0b8ba7c13e97868ab79dcec5c132d0b30dcc9c60
2022-01-20 22:55:44 +01:00
Thiemo Kreuz 8fd1b6d8b8 Defer creating template parameter widget for 0 parameters
From the user's perspective nothing changes. A template without
parameters doesn't show anything. (Technically there was an empty
<div>, but it doesn't do anything.) The moment the first parameter
is added the required sub-widget is created and available from there
on.

This saves loading time and memory, especially when a multi-part
template contains many templates without parameters.

Bug: T298259
Change-Id: Ib1bd2cd0be4fece4acc92e6e5f63133a7986cf81
2022-01-20 12:06:03 +00:00
Thiemo Kreuz 66f56f6c88 Defer creating template parameter search when it's not needed
From the user's perspective this is the same as before: When a
template doesn't have any parameters, there is no search field. The
moment the first (undocumented) parameter is added the search field
appears.

This is just delayed now. The widgets are only created the moment
they are actually needed.

This saves loading time and memory, especially in a multi-part
transclusion with many zero-parameter templates.

This also makes it a lot easier to change the minimal number of
parameters from 1 to e.g. 4.

Includes reverting the flexible header composition done in
Ib050e30a50ef965c1524e977d3a600c3ff836774

Bug: T298259
Change-Id: Ied7541d8d5c0b478a439dd31ce072e634287f181
2022-01-19 11:23:34 +01:00
Adam Wight a244f510c4 Make sidebar header and search field sticky during scroll
The search field will stay at the top of the window while scrolling a
single template.  In multi-part transclusions, the header will also
be sticky.

Hides the template header in single-part transclusions.

Bug: T298618
Change-Id: Ib050e30a50ef965c1524e977d3a600c3ff836774
2022-01-17 16:09:54 +01:00
WMDE-Fisch 20435b319c Add button to sidebar to hide/show unused fields
Bug: T298259
Change-Id: I8e5091b97dfb19eba981b2a919b82b6f14823990
2022-01-14 11:09:04 +00:00
Thiemo Kreuz 579cdaa145 Enforce formatversion=2 in template search
This is guaranteed via ve.init.mw.Target.getContentApi(). But the
ContentTranslation extension replaces this, and does not set a
formatversion. See e.g. SectionTranslationTarget.getContentApi().

Bug: T298599
Change-Id: I8768cae3153e9cbc29a8796ec21ef249f80471ed
2022-01-05 12:49:44 +01:00
jenkins-bot 717b5cf534 Merge "Use no-jquery/no-html to warn against writing HTML strings to the DOM" 2021-12-17 16:42:53 +00:00
jenkins-bot c92ea76af8 Merge "eslint: Enable no-jquery/no-append-html" 2021-12-17 16:42:42 +00:00
jenkins-bot 53ad459b27 Merge "ve.ui.MWMediaDialog: Clean up image metadata display" 2021-12-17 16:42:39 +00:00
jenkins-bot 6dc75d8283 Merge "Remove obsolete performance bottleneck from TransclusionModel" 2021-12-17 13:24:19 +00:00
Ed Sanders 2098292318 Use no-jquery/no-html to warn against writing HTML strings to the DOM
This forces us to comment when we are doing this deliberately.

Change-Id: Ide1bcb64f6c6076b48e88f1f27045bd93392f8a0
2021-12-16 01:28:42 +00:00