Commit graph

154 commits

Author SHA1 Message Date
jenkins-bot e1b5970d3f Merge "Split parameter validation off as separate methods" 2022-12-13 21:09:37 +00: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
libraryupgrader ca32a8ced1 build: Updating mediawiki/mediawiki-phan-config to 0.12.0
Change-Id: If6ebb246effabc99b7d72a336bacee65c54b5c67
2022-10-09 15:42:03 +00:00
Bartosz Dziewoński ba0e71fd33 Migrate usage of Database::select to SelectQueryBuilder
Bug: T312348
Change-Id: I59057174c102c29877608db2a6c26b7a50bd34cf
2022-08-12 23:54:22 +02: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 c0755ea392 Split parameter validation off as separate methods
This only moves code around but doesn't change anything. The tests
should prove this. The only change is that validating if "inherits"
points to an existing parameter is now done a little earlier as part
of validateParameters().

Bug: T301337
Change-Id: I20865d8f93ea0f3cb1c0683804c7871056a700a8
2022-07-15 11:11:32 +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
Umherirrender 560819e270 Use WikiPageFactory to create WikiPage object
Bug: T297688
Change-Id: I5e6da574bd1377b492005adbc1aff3e97fe9c31b
2022-06-24 19:53:40 +02:00
Thiemo Kreuz e297e767f0 Streamline HTML rendering code for format messages
The idea is to make it a little easier to follow what's going on
here.

This also improves an error message when tests fail.

Change-Id: If35be8aefab5a1568d53a9ecdc4313a66f71317b
2022-05-16 18:04:27 +00: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
Thiemo Kreuz 1c8b4ae729 No HTML needed to validate <templatedata> in wikitext
I tried to benchmark this and yes, it makes a difference, but probably
not a big one. This is an additional parse in addition to the one core
will later do when the page is actually saved. For this one here we
are just not interested in the HTML.

Bug: T305105
Change-Id: I71147af5161c934a822651e80e11f3bd26af56cd
2022-04-11 18:29:51 +02:00
gerritbot 42061b7174 Fix usage of ApiBase::PARAM_* deprecated constants
The ones that are replaced with ParamValidator

Bug: T275455
Change-Id: Ia08525d4162d8b460ca8f7fd97b75f564b6bbb7c
2022-04-04 01:29:48 +02:00
Reedy 5341749f56 Use namespaced EventLogging class
Change-Id: I87ed269b205e83ce87e5350ef31d35847a6ad25b
2022-03-06 16:07:22 +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 8fec04c8fd Remove unreachable validation step
I tried to write a test that can cover this code, but realized it is
unreachable. All parameters with all their properties are already
validated in the first loop.

Bug: T301337
Change-Id: If97adba45beb0ef1303907746715613fca23468e
2022-02-22 10:51:00 +01:00
C. Scott Ananian 453c4152af ParserOutput::getPageProperty() now returns null when key is missing.
The return value of ParserOutput::getPageProperty() has transitioned
to returning `null` instead of `false` when the page property is missing.

Bug: T301915
Depends-On: Iaa25c390118d2db2b6578cdd558f2defd5351d15
Change-Id: I1126eab0e882b5bdfecea1ef6e3e27dca7b85115
2022-02-17 11:57:25 -05:00
C. Scott Ananian b87e24813e Update uses of ParserOutput::getPageProperty() to handle new return value
The return value of ParserOutput::getPageProperty() will transition to
returning `null` instead of `false` when the page property is missing.

Bug: T301915
Change-Id: I71628661b4539a4e35ae32846e719f92bcf782e0
2022-02-16 18:26:42 -05:00
jenkins-bot 67d6b77a84 Merge "Move getRawParams helper method to ApiTemplateData class" 2022-02-10 05:44:14 +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
Thiemo Kreuz b1a4a27531 Split and streamline HTML formatter code
Bug: T301337
Change-Id: Ic2dac65e6e54411abc33326abf8d0fab148cb784
2022-02-09 12:37:29 +00:00
jenkins-bot 5407262418 Merge "Improve test coverage for HTML formatter code" 2022-02-08 16:09:17 +00:00
jenkins-bot a64ed0a376 Merge "Fix/narrow visibility of several methods" 2022-02-08 15:54:22 +00:00
Thiemo Kreuz a81a8b52bc Improve test coverage for HTML formatter code
… as well as some smaller improvements to the test coverage of other
code.

Change-Id: I5bec9c456fdc597c340dc0b515d23d837a7c5651
2022-02-03 12:45:27 +01:00
Thiemo Kreuz b674294789 Fix/narrow visibility of several methods
One method is only public to be able to test it. Others look like
they have been made "protected by default", which is not needed
anywhere.

Change-Id: Ib2231f0b2a879323aa53f8d40a175527c5b131d8
2022-02-03 10:48:04 +01:00
Thiemo Kreuz 001494f443 Move last remaining HTML formating code out of blob class
Effectively a no-op. This patch doesn't change what the code does.
Tests are in place to prove this.

As before, the tests are intentionally not moved but left in place.
This is for later patches to clean up.

Change-Id: If130e0d006a36d8c755288f8a4e4e9a4c42a6295
2022-02-03 09:33:03 +01:00
jenkins-bot 59e582cfb6 Merge "Split validation into some smaller steps" 2022-02-02 14:39:59 +00:00
jenkins-bot bd531c2a68 Merge "Use more specific instanceof stdClass instead of is_object()" 2022-02-02 12:31:35 +00:00
Thiemo Kreuz 78e6239444 Split validation into some smaller steps
Bug: T260980
Change-Id: Ibc88b5fd8f8ece919032d13320cad74d9be74bfc
2022-02-02 12:18:34 +00:00
jenkins-bot deeea30725 Merge "Inject localizer service into HTML formatter class" 2022-02-02 11:54:05 +00:00
Thiemo Kreuz dc82db422b Use more specific instanceof stdClass instead of is_object()
PHP is a little weird in so far that what you get from e.g. `(object)[]`
or json_decode() are not objects but stdClass instances. You can think
of stdClass as a subclass of object, i.e. it's more specific.

Using is_object() means that stuff like ArrayIterator will be accepted,
which is not correct in this context here.

Change-Id: I0bffc54508ac7a27bbb59c3aabb9695158eb96b3
2022-02-02 11:45:59 +00:00
jenkins-bot 606ed3642b Merge "Rename all $paramObj to $param" 2022-02-02 11:38:42 +00:00
jenkins-bot 5726af0e30 Merge "Split validation and HTML formatting into separate services" 2022-02-02 11:35:23 +00:00
jenkins-bot e6efeb59d8 Merge "Replace effectively unused $paramNames array" 2022-02-02 11:24:16 +00:00
Thiemo Kreuz 94573e1152 Inject localizer service into HTML formatter class
Change-Id: I7f27b0c42e15ab939749c9dbe9eb51754580ca87
2022-02-01 15:59:32 +01:00
Thiemo Kreuz 15aa40aa1d Rename all $paramObj to $param
The word "param" is not really that ambiguous in this context. The
only other meaning it could have is "parameter name". Such places
already use $paramName.

This makes the following patches easier to review.

Change-Id: I1e6210d1ca7d58726a0fc3b3396d75e0e28c16d8
2022-02-01 15:47:53 +01:00
Thiemo Kreuz 8c24751491 Split validation and HTML formatting into separate services
No functional change was made to the code. It was only moved from one
place to another. Note there are a lot of tests that cover this code.
The tests haven't been touched on purpose. Splitting these as well
is something for a later patch.

Bug: T260980
Change-Id: I9fa0fa87768f2560b83a1b5f3d39211ea9d6cfad
2022-02-01 15:47:52 +01:00
Thiemo Kreuz c6822649d5 Replace effectively unused $paramNames array
All this effectively does is counting the number of properties in the
$data->params object.

Change-Id: I92fff1f70b4f583c27c0e0ba7e4d7239e7790ee3
2022-02-01 15:45:33 +01:00
Niklas Laxström 6725472575 Fix use of formatnum in templatedata-invalid-length
PLURAL magic word expects formatted numbers, so just format them
in the code already, as is common practice.

Change-Id: I813c45f8959d9d013a6176e999622c81f7e86042
2022-01-31 09:34:57 +02:00
WMDE-Fisch 8c36f324e1 Fix use of errorbox in TemplateData
Bug: T300349
Change-Id: Ic4dbc1235887f29cb7737c0e1d4a3efe047c719b
2022-01-28 15:17:07 +01:00
C. Scott Ananian 0a3b28d3de Passing a string to ParserOutput::addModules()/addModuleStyles() is deprecated
Bug: T296123
Change-Id: I9b7fe5acee73c3a378153c0820b46816164ebf21
2022-01-11 17:02:39 -05: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 e83e3f2661 Add missing validation for aliases and suggestedvalues
This is not new. This was always documented to not accept anything
but strings.

Let's apply the same fix to aliases while we are here.

Bug: T297386
Change-Id: I57e18779f28802816d5adb66cc4067df4e58b26e
2021-12-09 14:40:36 +01:00
Reedy 166812da07 Namespace extension
Change-Id: I779e97e512ec0c4f74fb6a4b706772fb1428e40f
2021-11-25 22:53:34 +00:00
jenkins-bot 30204d74f5 Merge "Small clean-up of "format"-related HTML output" 2021-10-08 22:22:17 +00:00
C. Scott Ananian 6e1e698873 Rename deprecated usage of ParserOutput::{get,set}Property()
Bug: T287216
Depends-On: Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa
Change-Id: I1633f6fa00193df6ea1d6633de07bc8d2b269cbf
2021-10-08 10:29:01 -04:00
jenkins-bot 810125500b Merge "Fix and update type hints" 2021-10-07 07:51:56 +00:00
jenkins-bot da2077d5bc Merge "Fix parameter auto-detection picking up syntax elements" 2021-10-06 23:27:08 +00:00
Thiemo Kreuz 37a5285c29 Small clean-up of "format"-related HTML output
I hope this is a little easier to read.

Change-Id: I1ca1cb3d9565f083ad16c3f6aed98f93e3675a3a
2021-10-03 10:07:19 +00:00
Thiemo Kreuz 3ea3de8655 Fix and update type hints
The $this->data property stores whatever json_decode() returned,
which could be anything. The validation happens later.

Change-Id: I0d04831b8253005734c1c6c97b48061be35e5d88
2021-10-02 10:50:45 +00:00
jenkins-bot 4fe8f81dac Merge "Replace deprecated onPageContentSave hook" 2021-09-30 13:54:40 +00:00