Commit graph

118 commits

Author SHA1 Message Date
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
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
WMDE-Fisch 49bc2e8735 Replace deprecated Language::getFallbacksIncludingSiteLanguage
Change-Id: I24a95ce973169ab3f76abe39ca9780c3bf4ec5a4
2020-12-16 12:07:34 +01:00
WMDE-Fisch 028aaba896 Replace deprecated getNativeData
Change-Id: Icbee3fd7245e81b7c3c49e2aab6607c0a8e61217
2020-12-16 10:36:56 +00:00
WMDE-Fisch ae0dd0e094 Get WikiPageFactory and LanguageNameUtils from services
The bump to 1.36 was overdue because the PageProps are used from
services already.

Change-Id: Ic4b42f58290e15123b281d48be396e8b7e8eeab0
2020-12-15 14:15:47 +01:00
Umherirrender 88f31acbd7 build: Remove unneeded phan suppression
Possibly not needed after core change
I40a305b5e49d67b3f6d7737c0846b93a80b78fa9

Change-Id: Ided42bd763718f0393a874bbadb0b682b4bb9043
2020-12-13 00:20:53 +00:00
libraryupgrader 4d7ffb97a6 build: Updating dependencies
composer:
* mediawiki/mediawiki-phan-config: 0.10.4 → 0.10.5

npm:
* ini: 1.3.5 → 1.3.7
  * https://npmjs.com/advisories/1589

Change-Id: I5f54f5b504df70819338ca17bf2b67af6851f798
2020-12-11 13:35:56 +00:00
Thiemo Kreuz d08a6448e9 Track when (relevant) changes are made to <templatedata> tags
Bug: T267926
Change-Id: I55f72500b7bad7e648238560b516e870bc9130c8
2020-12-07 15:34:13 +01:00
daniel 4478384155 Revert "Add logging for parser cache misses."
We got the info we wanted, the statistics gathering is now just
causing extra ParserCache lookups.

This reverts commit dd81de53d7.
This reverts commit 9a85a1b67e.

Bug: T266200
Change-Id: I830797e287118fbde07e0e22e1304b30ee9f67e5
2020-11-17 21:07:03 +00:00
Cindy Cicalese 45907dc7d4 Make extension data JSON-serializable #2 - write JSON.
Switching ParserCache to JSON serialization requires
extensions to stop writing non-JSON-serializable objects
into ParserOutput::setExtensionData.

This should be deployed at least 1 train after dependencies.

Bug: T266252
Change-Id: I24dfbcff47b6a317d9928fda8c70da64f2d6bc82
2020-11-09 19:48:47 +00:00
daniel dd81de53d7 Apply bucketing to query sizes stats
Change-Id: I921e5bec971fac1303b26322bb0898016c251bea
2020-11-03 20:31:01 +01:00
daniel 9a85a1b67e Add logging for parser cache misses.
This should help us decide whether it would be OK to
rely on the ParserCache to store parsed TemplateData.

This patch should be reverted once we have collected
the desired data.

Bug: T266200
Change-Id: I0631806145d46e4a5e7c177797b8fdfe7a152076
2020-11-02 22:18:38 +01:00
Cindy Cicalese b10862a333 Make extension data JSON-serializable #1 - forward-compat.
Transitioning of ParserCache to JSON serialization will add
a requirement that all the extension data is JSON-serializable.

This is the first step in transition - making it forward-compatible.

Bug: T266252
Change-Id: If1c9d9bb5b0039df80a9d9b30c247206d8844c0a
2020-10-30 12:33:20 -04:00
jenkins-bot 86a6865512 Merge "Fix parameter extraction from wikitext source" 2020-10-06 23:07:23 +00:00
Ammar Abdulhamid 0b03b04dcc Force tag content to string before constructing TemplateDataBlob object
This null was being forced to string by PHP before strict typing in I9a20335

This is a rare error as self-closing tag is not allowed as far as
I can see and will emit proper syntax error after this change; but
it should not raise fatal exception

Bug: T263605
Change-Id: I1d9f674fb92d1f1cf70b57e820f8fc3312be9cc8
2020-09-23 05:35:37 +01:00