Commit graph

263 commits

Author SHA1 Message Date
Umherirrender 06d6054ade stylelint: Enable selector-pseudo-element-colon-notation
Via stylelint --fix

Change-Id: Iafee0799add6495119f174d3022af17206167c0e
2023-03-30 01:01:00 +02:00
thiemowmde 22d5363208 Fix placeholder size for the "edit template data" button
This placeholder was added in Ic8f9bf7. It makes sure the page
content below the button doesn't shift down the moment the button
appears. See T279869 for a screencast that demonstrates the issue.

Unfortunately something changed (possibly related to T323773) and
the size of the placeholder is not correct any more. At the moment
the page shifts up a few pixels.

Bug: T279869
Change-Id: Ie6e585d2061342c11aabb4414bb9b0bedecf3a12
2023-03-13 09:40:17 +01:00
Thiemo Kreuz ec72e43858 Move var declarations (and initializations) down in Dialog class
Note the code style in this file is already a mixture of some early
declarations and others that happen in place. We mostly prefer the
later nowadays because it makes the code much more readable. Some of
the code touched in this patch was really a little confusing, I would
argue.

Change-Id: Ib2777c6f6c86876c016e50d7bd2fe3d82c611914
2023-01-10 20:27:23 +00:00
jenkins-bot d1b7f188ad Merge "Reduce code duplication when switching dialog panels" 2023-01-10 01:41:11 +00:00
thiemowmde 73ec256285 Fix broken maps panel in TemplateData editor
A change in OOUI made .addItems() silently ignore non-array input.
The most robust fix is to make all callers follow the documentation
instead of relying on undocumented behavior.

The change to onMapItemRemove is not strictly needed but done to make
this piece of code much more robust.

Change-Id: I95f9a058766720d3809c3e56309326c2a91f2bcd
2023-01-05 16:47:00 +01:00
thiemowmde 8f6493a198 Reduce code duplication when switching dialog panels
Main change is that we don't map between strings and object
references any more but use the object references directly.

Change-Id: Iecc011f62089d902bb5cbd9ff3b4189d3258a2b4
2023-01-05 15:27:13 +01:00
jenkins-bot 9bca2b9d36 Merge "Set focus to first input field on all panels" 2023-01-04 19:17:52 +00:00
Thiemo Kreuz 7d0f0da623 Use type info instead of repeating individual field names
The data structure at the top of Model.js uses types like "string",
"array" and so on. Fields that share a type behave identical. I find
it odd to repeat parts of this data structure in the code. That's
what the types are for.

Change-Id: Iae55c18ececb809a56e40d3179d2cde357309d0a
2022-12-31 10:45:48 +01:00
jenkins-bot dda14a168c Merge "Fix copy paste mistakes and outdated code documentation" 2022-12-29 01:12:27 +00:00
jenkins-bot d24fc8ee2f Merge "Streamline code duplication in nested if in Dialog.js" 2022-12-29 01:01:27 +00:00
jenkins-bot 088b0c8600 Merge "Rename message not specific to suggestedvalues" 2022-12-29 01:00:27 +00:00
jenkins-bot b0cb613a58 Merge "Create dialog elements from "type", not from element name" 2022-12-29 00:57:03 +00:00
thiemowmde 981054937d Streamline code duplication in nested if in Dialog.js
… by turning the nested `if` around and simplifying the remaining
parts a little. This patch is intentionally minimized. More
meaningful changes will be done in the next patch.

Change-Id: I56cfa5c8ac8ca29acd42bd71786f5433e884e1b2
2022-12-23 12:06:36 +01:00
thiemowmde e222666e1f Rename message not specific to suggestedvalues
This fixes a FIXME in the code.

Change-Id: I3302352d000d865f074ddafe479d3f1afa62e93d
2022-12-19 07:39:17 +00:00
jenkins-bot 310bf46cf9 Merge "Simplify some overly complex comparisons with undefined" 2022-12-16 22:51:30 +00:00
thiemowmde b4c960287a Unhoist a bunch of variables in Dialog.js
Previously, our eslint configuration required all variables
to be declared together at the top of the scope, but that
was changed, and declaring the variables where they are needed
is clearer.

Change-Id: I87e74ceadd5374a6ba6b7a4f8f49dca03a5c4bca
2022-12-16 09:31:46 +01:00
thiemowmde ca5a2f26ea Create dialog elements from "type", not from element name
The data structure in Model.js, starting at line #125, does have a
"type" property that's supposed to do this. What kind of input element
we need depends on the type. Repeating individual element names here
means we are duplicating parts of the data structure.

The mapping is unambiguous, i.e. the new code is guaranteed to do the
same as before.

This is a tiny cleanup patch in preparation for later changes.

Change-Id: I162dcd6f9a31f5ab2c6eb7027befd4736de40ca5
2022-12-16 09:29:20 +01:00
jenkins-bot 09677910fe Merge "Inline some trivial single-use variables" 2022-12-16 03:05:52 +00:00
thiemowmde b53d754639 Renaming misleading "type" variable
"children" is an array. See line #148 in Model.js. What's called "type"
here is just the numeric index in this array.

Change-Id: I73c190f754d113ac90f5df76fb8cc8b7a75fc927
2022-12-07 15:30:18 +01:00
Ed Sanders 678d95251b Add an "Edit template data" button to the TemplateData output
This button, similar to an edit-section link, will launch the editor
and immediately open the TemplateDataGenerator UI.

Bug: T316759
Depends-On: Idb5e3c51a22361e0d9916d3c31444daeff310ed2
Change-Id: Ieb575c499c16d87c28972a55662ef0bd9cb72c06
2022-11-08 13:36:38 +00:00
Thiemo Kreuz 685363d947 Set focus to first input field on all panels
* This is most notably when adding a new parameter. The cursor should
  start in the input field.
* Focus the first input field when editing a parameter, whatever that
  input field is.
* Focus the big JSON editor when editing a map.

Change-Id: I5a3df626810007e83bd2300b540df75bc1b8cac4
2022-09-23 11:20:45 +02:00
Thiemo Kreuz 4790aaed4e Inline some trivial single-use variables
There is sometimes a good reason to arrange code like this, especially
when the additional variable name acts as documentation and helps
explaining what's going on. I think this is not the case here.

Change-Id: I46f4a18a4f78f4b03cf063a226de3f43ba13b1a2
2022-09-23 10:35:03 +02:00
Thiemo Kreuz 2d55ab3e68 Simplify some overly complex comparisons with undefined
The short `|| defaultValue` pattern is very common in JavaScript.
Note that in JavaScript – in contrast to PHP – empty arrays and
objects are not considered "falsy".

Change-Id: I97935c4dc2276d48d53ade3f7b4fdc28b62d89ba
2022-09-23 10:31:19 +02:00
Thiemo Kreuz 61dce0bf00 Fix copy paste mistakes and outdated code documentation
This patch intentionally doesn't touch any code to make it as easy
to review as possible.

Change-Id: I3089bd09f38b3aaa6424e7e263d514625f63f9f1
2022-09-23 10:28:12 +02:00
Thiemo Kreuz 17d6c485bb Fix broken comparison when editing the template description
This was always comparing with the English description. The effect of
this was that the comparison was always false and the value always
set, even if it didn't change, resulting in unnecessary events being
fired. So this is only about performance but not really user facing.

Change-Id: Id7a46dbac81e2595478848bbf325eece21815bec
2022-09-23 10:25:09 +02:00
jenkins-bot 9251dd1c18 Merge "Add space between icon and text in formatting message" 2022-09-07 09:09:38 +00:00
Ed Sanders d2e72a252f Add space between icon and text in formatting message
Change-Id: Id0b8b36b8f2145847fafa8005bc6bdc7b3f98e55
2022-08-31 11:43:40 +01:00
Ed Sanders 64b8be314c Fix font size of "Manage TemplateData" button in vector legacy + 2017WTE
Change-Id: I26a7a0956d2bcce1700b583a2e8c684d4d72b948
2022-08-31 11:27:46 +01:00
Thiemo Kreuz d36356326a Make use of LESS features for more structured CSS
This patch includes two bugfixes:
1. The previous rule with a `p + p` didn't do what it was supposed to
   do. It was adding a margin after the 2nd, 3rd and all following <p>
   elements, but not between the 1st and the 2nd. It should have been
   margin-top instead. The approach in this patch is different and
   avoids the need to repead the 0.5em.
2. The red background color was not applied to the input fields any
   more because OOUI doesn't use <input> elements any more.

Change-Id: Ia57b742e8b3cd29c1f55cd7e918f26f70eebab18
2022-08-08 17:40:08 +00:00
Thiemo Kreuz f92fed31c7 Turn all TemplateData .css files into .less files
This patch intentionally doesn't do anything else. Later patches will
make use of LESS features.

Change-Id: I7ce7fdba12aa9f5fb49a752706b83f831632bed6
2022-08-08 15:29:03 +02:00
jenkins-bot bc064ce8a2 Merge "Fix CSS styling of the HTML rendering broken since 2016" 2022-08-08 10:38:39 +00:00
Thiemo Kreuz 8497d85a2d Fix CSS styling of the HTML rendering broken since 2016
Some time ago there was a little bit of custom CSS applied to the HTML
table rendering. This is broken since patch I74214ea from 2016. This
patch renamed all CSS classes but forgot to update the PHP code
accordingly.

I decided to not change the HTML rendering because these class names
might already be used in custom per-wiki or per-user CSS. Instead I
partly revert I74214ea.

Unfortunately, some of the styles are quite dramatic, don't look good
or just don't work. I decided to remove some. The argument is that
the HTML rendering looks the same for 6 years now. I don't see a good
reason to change it now.

In detail:
* Suggested values are not aliases and should not be rendered in
  gray.
* The message "no description" is rendered in gray and italics. But
  this was applied to the wrong DOM element and made everything else
  gray and italic as well.
* The color #777 is not readable, violating WCAG rules. While it's ok
  to dim aliases and such, it must be at least #555 or darker.
* The "nowrap" destroys the table the moment one of the parameters
  does have a longer name or alias. Let the browser handle this, as
  it did for 6 years now.
* Same for rendering aliases as individual, indented blocks. This
  makes the table unnecessarily big when there are many aliases, and
  just doesn't look right. Again, let's stick to what we had for
  6 years.

Change-Id: Idfa76eed6e2d68474c79d4674efce091cb031b66
2022-08-08 11:56:16 +02:00
Thiemo Kreuz bd0e348032 Fix JSON export to fail on missing "params" key
It's required via the spec. We should act as if it's always there,
even when the actual "original data object" doesn't contain it.

Bug: T307331
Change-Id: I129b0c77e701df6ebbdc39432360cea8f10575e8
2022-07-21 13:10:12 +02:00
WMDE-Fisch d1ffdc2b95 Remove $wgTemplateDataSuggestedValues feature flag
Feature is always enabled now.

Bug: T307188
Bug: T310684
Change-Id: Ic99c594ceec0020a6c9d20f0a4f10285b74ea9a8
2022-06-27 12:14:02 +02:00
Thiemo Kreuz ff7470e316 Add placeholder to avoid wikitext editor jumping down
Bug: T279869
Change-Id: Ic8f9bf7c95b42422dc4b477f9c752f5e89b20dc7
2022-04-25 08:42:59 +00:00
Ed Sanders ef6294074e build: Update devDependencies
Change-Id: I80bd6849b1616b9c94e75eddfbf5f476b799e07b
2022-03-13 17:17:03 +00:00
Thiemo Kreuz d3f00177ba Don't extract template parameters from <pre>
<pre> behaves very similar to <nowiki> in so far that whatever it
contains doesn't get parsed as wikitext. It might contain {{{…}}}
tripple brackets, but these aren't going to be activated as template
parameters.

Bug: T91326
Change-Id: I05c24e369d97c48161c565e2ef30969ec28c6a23
2022-03-03 21:20:40 +00:00
Thiemo Kreuz da8969812c Move getRawParams helper method to ApiTemplateData class
This method is not used anywhere else:
https://codesearch.wmcloud.org/search/?q=getRawParams

I tried to make the code a bit more readable. Notable:
* Make use of the return value we get from the preg_… function.
* {{3,} means "the character '{' 3 or more times". {{{+ does the
  same. Note the { doesn't need to be escaped when it's not
  followed by a number.
* At the end, it doesn't make any difference when we scan for
  optional closing brackets. The moment we find at least 3 we are
  done.

The test is intentionally not moved. This is something for a later
patch.

Bug: T301337
Change-Id: I55e31ceecea2ae7c35bcfbc2d641b35f751820db
2022-02-09 12:37:33 +00:00
jenkins-bot c8537793c1 Merge "Fix and update type hints in JSDoc comments" 2022-01-17 17:11:19 +00:00
Thiemo Kreuz 5f749c6418 Allow aliases to be integers in addition to strings
Parameter names in a template can be numeric. While it makes a lot of
sense to force a specific format in the TemplateData JSON (i.e. only
strings), it's inconvenient and confusing if numbers are rejected for
being "invalid".

Effects of this patch:
* The incoming JSON is allowed to contain numbers in the aliases
  array.
* However, the API normalizes these and forces all aliases to be
  strings, as it was always documented.
* The editor component accepts anything in the aliases array, but
  forces all aliases to be strings. Again, as documented.
* Note that it was never possible to use numeric keys in the `params`
  list. This patch is only about aliases.

At the moment this is a somewhat "hidden" feature. We might or might
not update the documentation to officially allow numeric aliases.

Bug: T298795
Change-Id: I32ea296b4520e7f21b03a1f6390db4f43b613bdd
2022-01-10 13:33:27 +01:00
Thiemo Kreuz e79f19f09c Fix and update type hints in JSDoc comments
Change-Id: Ib38d3c4eff7630bd3aed04beee33adc5ae2101f3
2022-01-10 11:48:42 +01:00
Adam Wight 709c89909f Remove comma-delimiting code
No longer needed as of I9450f70e705d9596c7e0d7545f9b5505fc4aae04

Change-Id: I342db496a1e3e0b6c4466dbdd62ee0d8d21258c0
2021-12-17 12:08:10 +01:00
Thiemo Kreuz f7771a22a6 Edit aliases via a proper widget instead of comma-separated
Bug: T285284
Change-Id: I9450f70e705d9596c7e0d7545f9b5505fc4aae04
2021-12-17 11:50:27 +01:00
Thiemo Kreuz 2b2033c6ec Fix serialization adding empty autovalue when not needed
The autovalue field appears to be the only one with this edge-case.
This is because all other fields are either multi-lingual and
processed by the `….allowLanguages` code path above, or because
of other special-case handling somewhere else.

The idea is:
* Non-empty values are always added.
* When the property (in this case `"autovalue": "…"` existed
  before, it's kept, even if it's now empty.

Bug: T295074
Change-Id: Ie4d9825b89edb4bbbbc4283dc48e9113e537869a
2021-11-29 10:53:35 +01:00
jenkins-bot da2077d5bc Merge "Fix parameter auto-detection picking up syntax elements" 2021-10-06 23:27:08 +00:00
jenkins-bot f16838ebc0 Merge "Remove small pieces of unused code" 2021-10-06 23:05:34 +00:00
Ed Sanders da93a0fffa Move var declarations inline
Change-Id: I177f91e67ea2ea2ab07d64002ae80365fabdedd3
2021-10-05 17:37:33 +01:00
Thiemo Kreuz 3060559d1d Fix parameter auto-detection picking up syntax elements
See T290322 for a detailed description.

Bug: T290322
Change-Id: Id9935482fb466e7a1f6e55f042b13fe5851412d0
2021-09-03 13:18:42 +02:00
Thiemo Kreuz 4766216948 Remove small pieces of unused code
Mostly unused variable initializations. Note I'm inlining some
`var` keywords in this patch. This is in line with the current
style guides. See for example the discussion in I4f198e2 (search
for "hoisted" in the comments). However, I'm not changing the
entire codebase, as this is not the goal of this patch and also
just not necessary at this point.

Change-Id: Ibd80566c44584851ee2530d6b16dd28eb3db6bfe
2021-08-28 12:10:22 +02:00
Thiemo Kreuz 2cb03827cc Fix several type hints in JavaScript code
Two main mistakes:
* The {...foo} syntax is for a variable number of parameters.
  But this is not the case here.
* Optional parameters should be marked as such via [foo].

Change-Id: I0c26ea44fab6094616443ce8fae4fd47c61fd7c4
2021-08-28 12:08:28 +02:00