Commit graph

131 commits

Author SHA1 Message Date
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 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
TChin 457476611f Replace deprecated onPageContentSave hook
Bug: T291001
Change-Id: I5ac84af28a4687337bb21eafb907ac7224e67b5b
2021-09-29 13:49:10 -04:00
Alexander Vorwerk 062d099f2c Replace usage of deprecated PageProps::getInstance()
Bug: T289544
Change-Id: I1a5dc0d81063d666cbbea5be6457f97b9cf4e4fc
2021-09-26 14:12:19 +02:00
jenkins-bot 75ca493b68 Merge "Add test cases for (almost) all possible parsing errors" 2021-09-20 13:11:09 +00:00
libraryupgrader e5cb2df074 build: Updating composer dependencies
* mediawiki/mediawiki-phan-config: 0.10.6 → 0.11.0
* php-parallel-lint/php-parallel-lint: 1.3.0 → 1.3.1

Change-Id: I759468d63803b310d5385af517589e70db75c62c
2021-09-09 11:45:31 +00: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 eb12e48b14 Add test cases for (almost) all possible parsing errors
"Almost" because I found at least one that appears to be
unreachable (the very first check for null). But changing this
code is out of scope of this patch.

This also updates some of the error messages to explain the
location of the error better. It appears like the incomplete
paths are copy-paste mistakes.

I also found one duplicate test case and removed it.

Change-Id: Ic0ee9d04f5cd1060ade385ef308e70d221dd2f18
2021-08-30 15:17:21 +00:00
jenkins-bot b745f0961a Merge "Make parameter order when sorting by status independent of language" 2021-08-02 12:51:37 +00:00
jenkins-bot 6871af2766 Merge "Remove unused pieces of code from API module" 2021-07-30 13:45:49 +00:00
Thiemo Kreuz c2508a78ad Make parameter order when sorting by status independent of language
At the moment, when the user clicks the "Status" column to
sort by status, the statuses are ordered alphabetically,
which gives widely varying results depending on the language.
But there is an inherent order for these, even hard-coded in
the code: When a parameter is deprecated, nothing else matters.
Otherwise it's required → suggested → optional. Doesn't it
make much more sense to order the column this way? Especially
because there are never more than these 4 hard-coded values.

This is one of the (few remaining) issues mentioned on
https://de.wikipedia.org/wiki/Vorlage:TemplateData#Vorlagendokumentationsseite_verbessern_%E2%80%93_MediaWiki_ungen%C3%BCgend

This patch also makes it so that a CSS class name is always
added to all status fields, not only to the required ones.
This allows for per-wiki or per-user styling.

Change-Id: Id3f1ffafe09a3817972a4ee4bd4a3ded7be6f039
2021-07-30 13:42:00 +00:00
jenkins-bot 654e1ba037 Merge "Render docs with HTML5 <section>/<header> markup" 2021-07-30 13:40:14 +00:00
libraryupgrader a09e939fe7 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0

npm:
* postcss: 7.0.35 → 7.0.36
  * https://npmjs.com/advisories/1693 (CVE-2021-23368)
* glob-parent: 5.1.0 → 5.1.2
  * https://npmjs.com/advisories/1751 (CVE-2020-28469)
* trim-newlines: 3.0.0 → 3.0.1
  * https://npmjs.com/advisories/1753 (CVE-2021-33623)

Change-Id: I23a441a089501a97f329b7b6d37bc658481e682f
2021-07-24 02:43:18 +00:00
Reedy 6e4902fd72 ApiTemplateData: Fix ORDER BY
Change-Id: Ife2b6b5792e6c4312774fc42d073a663f19051ea
2021-07-15 01:01:30 +01:00
Thiemo Kreuz 4b110c6c85 Render docs with HTML5 <section>/<header> markup
Change-Id: I91083561f7c4bcd3ee7184aee114a735de153fc4
2021-07-12 12:13:34 +02:00
Thiemo Kreuz f6e1004720 Various minor JSDoc/PHPDoc documentation fixes
Change-Id: I537bf4086058a7e18c9118f7433090c4bfaf98e7
2021-07-12 11:47:55 +02:00
Thiemo Kreuz e70251a949 Remove unused pieces of code from API module
This is all unused, e.g. because it just repeats a default
value. All verified by my PHPStorm IDE.

Change-Id: I69665e07ca2d04016dc16e93290ef276f6b2cd95
2021-06-11 09:33:37 +00:00
Thiemo Kreuz 0bfb242ecc Fix TemplateData API not properly working with a generator
All API modules that are a submodule of the action=query API do
this already. What this method does is to forward all additional
information from the "generator" module to the module that uses
the generator as input. Without this line only the list of pages
is forwarded, but all metadata is lost.

The thing is: The templatedata API is not an action=query API,
but a separate action. But it's largly compatible. It might
even be possible to turn it into an action=query API, but this
is beyond our capacity at the moment.

Bug: T274907
Change-Id: I3c3c684109688c112ec15424119d4d30430ffd86
2021-06-10 14:52:01 +02:00
Adam Wight 7b32bcefb4 Add suggested values parameter
Parameters may include a `suggestedvalues` property, which is rendered
in the UI for some parameter types.

TemplateData editor UI elements are implemented behind the
TemplateDataSuggestedValuesEditor feature flag.

Bug: T271897
Change-Id: I14012c79b3fa0d48c58fd8999584cc03ec03575e
2021-04-09 12:05:37 +02:00
Adam Wight d63a375fac Finalize event platform migration
Bug: T275011
Bug: T275012
Change-Id: I51a3c3b6b3943db651807fbb2c0eb17c8c51440f
2021-02-24 16:52:55 +01:00
Thiemo Kreuz 6129f5d589 Don't validate <templatedata> tags on non-wikitext pages
I tested this locally, and indeed: Try to edit for example your
own page http://en.wikipedia.org/wiki/Special:MyPage/common.js
Try to paste and save this:

 var notWikitext = '<templatedata>{</templatedata>';

The page fails to save. (You might not see the error message
because of T258790#6751678.)

But this is not even wikitext. The <templatedata> string is
meaningless and does not trigger any TemplateData code when
the page is parsed and saved. Still there is an additional (!)
parser run that processes every page with the wikitext parser,
no matter what the actual content model is.

This does not only cause strange stack traces (see T272231),
it's most probably a massive performance bottleneck. Luckily
the majority of pages on the Wikimedia cluster is wikitext
anyway.

Bug: T272231
Change-Id: I2efcadc9bae6ecb37314f6d45c0c520abfbb85a0
2021-02-19 15:10:28 +01:00
jenkins-bot f26a5d37ec Merge "More strict validation of InterfaceTexts" 2021-02-13 17:23:44 +00:00
Thiemo Kreuz 294786223d Remove inconsistent capitalization of parameter names
Example:

On
https://en.wikipedia.beta.wmflabs.org/wiki/Template:Anschutz
the two parameters "state" and "capitalization_test" don't have
a label in the <templatedata> JSON structure. Instead the
internal parameter name is shown. But it's capitalized for an
unknown reason. I guess this is done to make the table look
"nice". But it causes confusion – see the ticket.

This capitalization is there since the very first commits from
2013, see I16d3f9e.

Compare with VisualEditor: Edit the template on
https://en.wikipedia.beta.wmflabs.org/wiki/Conflict-title-0.8542952978413387-I%C3%B1t%C3%ABrn%C3%A2ti%C3%B4n%C3%A0liz%C3%A6ti%C3%B8n
or use the old wikitext editor and TemplateWizard to insert
the template. In both cases the parameter names are not
capitalized.

Another argument why this capitalization is misplaced: When
there is no <templatedata> JSON blob, the TemplateData editor
auto-detects the parameters and semi-automatically creates a
minimal JSON blob. This is the moment where labels should be
created and stored so the user can edit them. But this doesn't
happen (for good reasons).

The user can't do anything about the current capitalization.
The only way to change it is to add a label that does nothing
but repeat the parameter name, just to undo the capitalization.
That should not be the way this works, I would like to argue.

Bug: T174771
Change-Id: Ia8133d3f0d6b79fe89c63bb0392a334c0a185a65
2020-12-23 11:59:12 +00:00
jenkins-bot 39d95be801 Merge "Replace deprecated Language::getFallbacksIncludingSiteLanguage" 2020-12-17 10:50:08 +00:00
WMDE-Fisch b8b1df894f Add tracking for template data presence
This will give results whenever template data is requested e.g. by
VisualEditor or the TemplateWizard.

Bug: T259705
Change-Id: I2a9e864b94b6f8f49ca3adaa46502627ab6b3322
2020-12-16 12:50:44 +01:00