Commit graph

88 commits

Author SHA1 Message Date
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
Thiemo Kreuz f6de5d3493 Fix parameter extraction from wikitext source
This fixes a series of issues:
* The JS implementation had a trim() in one place that was
  missing in PHP.
* The actual parameter name in the paramNames/$params array was
  trimmed, but the "normalized" name (this is only for duplicate
  detection) was not trimmed.
* It was possible for an empty parameter to show up.

This resulted in very strange behavior, e.g. {{{ 1}}}{{{1 }}}
was detected as "1" and "10" (?), i.e. it would try to renumber
the duplicate in a strange way (string "1" plus a counter that
starts with 0).

Change-Id: I0a6371f3633b03b5b21809ecd06ea4c72d7d914d
2020-09-22 18:27:23 +02:00
jenkins-bot 077cb83cc9 Merge "Add and update soft PHPDoc type hints" 2020-09-21 01:00:27 +00:00
jenkins-bot 6d6ef56ea2 Merge "Prefer Html::rawElement instead of open/closeElement" 2020-09-21 00:53:23 +00:00
Thiemo Kreuz 9f878897cf Turn static variables into private constants
These are not really variables. They are never modified, and not
meant to be modified. Using "static" was a common workaround
when we had no private constants in PHP.

Change-Id: Ie1234ce8833986431be95f8537282fa174978063
2020-09-14 14:17:25 +02:00
Thiemo Kreuz ac0630edd1 Add all missing PHPDoc comments
Change-Id: I4bf77867209e8aef524707b02363ae0ff7ca1f2a
2020-09-09 17:05:54 +02:00
Thiemo Kreuz eeffc4bf38 Prefer Html::rawElement instead of open/closeElement
Html::open/closeElement are hard to read and possibly error
prone. We can easily avoid it in this case here.

Change-Id: I2251cb63e58bc132ced0bb684e3f0e3be35ab1aa
2020-09-09 16:54:59 +02:00
jenkins-bot 6dd0b66fea Merge "Make TemplateDataBlob::normaliseInterfaceText() private" 2020-09-08 22:45:15 +00:00
jenkins-bot 8e56813b6e Merge "Use more canonical (object)[] instead of new stdClass" 2020-09-08 22:45:13 +00:00
jenkins-bot 3319103531 Merge "Make properties in TemplateDataBlob private" 2020-09-08 22:17:40 +00:00
jenkins-bot 81c7cc823e Merge "Make subclass constructors properly call each other" 2020-09-08 22:17:39 +00:00
Thiemo Kreuz f2306a2eab Make properties in TemplateDataBlob private
No subclass is directly using these. They don't need to be
protected. There are getters, if needed.

Change-Id: I27dcb8bee37b9559242451774c52240b490a18af
2020-09-04 15:28:15 +00:00
Thiemo Kreuz a4813c26f3 Add and update soft PHPDoc type hints
In detail:
* Callers don't need to know that the return value can be a
  TemplateDataCompressedBlob. All relevant stuff is declared in
  the base class.
* It's not relevant which internal method returned the status.
  It's just the status of the object after it was constructed.
* "stdClass" is more specific. "object" includes more stuff
  which can't be returned here.
* Avoid duplication and use @inheritDoc instead.

Change-Id: I68878a5b26ecd566fbea88b513ee697b45769659
2020-09-04 06:10:24 +00:00
Thiemo Kreuz 53d6c2fcd9 Make subclass constructors properly call each other
In detail:
* Mark both as protected and make them call each other.
* Avoid duplication.
* Remove unused "null" default value.

Change-Id: I272a68bb3cc0c544ef306b16c2998458c2eb1a2d
2020-09-04 06:09:35 +00:00
Thiemo Kreuz 62c608f172 Add strict type hints in unambiguous places
Notes:
* In PHP, when a function parameter does have a strict type,
  all it does is forcefully casting the value to this type. It
  doesn't cause warnings.
* Violating a strict return type causes a warning.
* I'm intentionally not touching places where the result from
  json_decode() is passed through. In theory this could be
  anything. Let's update these later, after more refactoring
  is done.

Change-Id: I9a203356f70cf9edd434f7dc4ca130c2b7605ab4
2020-09-03 12:12:19 +02:00
Thiemo Kreuz a2415bb32a Turn static property into private constant
We can do this in PHP now.

Change-Id: I54ae244651134424d5a2b1ce27d685f8165692da
2020-08-26 13:00:26 +02:00
jenkins-bot b442c40255 Merge "Remove obsolete return true and & from hook handlers" 2020-08-20 15:45:21 +00:00
jenkins-bot 4a45fd6cbf Merge "Remove unused variables" 2020-08-20 15:07:00 +00:00
Thiemo Kreuz 1d798c0e43 Remove redundant null check after isset()
isset() already checks if a thing a) exists, and b) is not null.

Change-Id: I5291ee30c8897dda1a5c095e196d5b5477a1877b
2020-08-20 12:20:58 +00:00
Thiemo Kreuz 10971b6124 Make TemplateDataBlob::normaliseInterfaceText() private
Not used anywhere else:
https://codesearch.wmcloud.org/search/?q=normaliseInterfaceText
Doesn't even need to be static, as it is never called from a
non-static context.

Change-Id: I0981392e18cab08fb19501f57d805caf8f57dd4a
2020-08-19 15:40:55 +02:00
Thiemo Kreuz c355a8fac4 More strict validation of InterfaceTexts
This fixes parts of a TODO in the code. Specifically:
* When an InterfaceText is an object, it can not be any object,
  but must be an stdClass.
* It can't be empty.
* Language codes must be non-empty strings.
* Values must be strings.

I'm intentionally not adding more validation for the language
codes, as this needs discussion (what values should be allowed?),
and can potentially break existing pages.

Same for empty strings. This can easily happen when users
manually create a <templatedata> tag and copy-paste pieces that
are meant to be filled in later. Empty strings are not really
invalid (again, this needs discussion), but might be something a
client want's to ignore.

Change-Id: I0facaa08cffe5a5a038423a58d55bc90a40b2d75
2020-08-19 15:29:55 +02:00
Thiemo Kreuz 62ac9da173 Use more canonical (object)[] instead of new stdClass
Both styles create the exact same object. Casting an array to an
object creates an stdClass object as well. The main benefit of this
syntax is that there is much less repetition. Everything is one
token instead of individual lines, where each line might contain a
typo.

Change-Id: I8fb09e9d33e5a1d91d4b32a71f658b31c629987b
2020-08-19 14:23:29 +02:00
Thiemo Kreuz 7fd1367918 Remove obsolete return true and & from hook handlers
In detail:
* Don't pass the Parser by reference. Hook handlers don't need to
  replace the object with another one, and shouldn't.
* Use __CLASS__ instead of repeating the class name.
* Returning true from a hook is meaningless and indistinguishable
  from the default.

Change-Id: Iac60f7f4946eb78cfb3b579fcdb1cab8bdcac7cd
2020-08-19 14:14:35 +02:00
Thiemo Kreuz 4a0d7139ca Remove unused variables
Change-Id: I3f307113be730d770af796e91bc28bb149c45ad5
2020-08-19 14:11:02 +02:00
Siddharth VP 512911b92e Make getRawParams() ignore parameters in comments and nowiki tags
This is used by the includeMissingTitles option of API action=templatedata.
Parameter syntax existing within nowiki tags or comments will not be valid
for the template.

Bug: T237195
Change-Id: Ibbfa3e21488f2a37fc494862e929baf50607d4c9
2020-08-17 00:33:06 +00:00
adham-khatean 55a423a5ba Remove Sortable class from tables that have one row or less
Removing the sorting arrows from tables that have one row or less in
templates. By using variable $sorting that changes according to the
coung of elements in the array $data->params, to determine whether the
table should have "sortable" class or not.

Bug: T126150
Change-Id: I414c2375d4eb4da5d78f92f6b4e99b55e314ce4d
2020-06-22 09:13:17 +01:00
libraryupgrader d2cee1239d build: Updating mediawiki/mediawiki-phan-config to 0.10.2
Additional changes:
* Removed phan-taint-check-plugin from extra, now inherited from mediawiki-phan-config.

Change-Id: I1f52b9bd1dbbdf15359d16efd5fc35eaf8b8ea76
2020-06-02 02:54:09 +00:00
Reedy 0deac36b6e Fix PSR12.Properties.ConstantVisibility.NotFound
Bug: T253169
Change-Id: I92970c67565792e8d2282e9f4c4c02a61ed30dbe
2020-05-20 01:06:40 +01:00
James D. Forrester edf85c08e7 Use QUnitTestModule instead of deprecated ResourceLoaderTestModules
Bug: T232875
Change-Id: I5612a9be65f4d4adf4912645856540dbb04d2b34
2020-05-11 19:45:10 +00:00
C. Scott Ananian e3c95c281f Improve directionality settings for TemplateDataBlob rendering
The <templatedata> extension tag wants to render itself into HTML
before an OutputPage has been set up.  Unfortunately, this meant that
we needed to hack in a call to OutputPage::setupOOUI() with default
theme and directionality, regardless of whether those were correct.

Slightly improve matters by using the directionality of the user
language object, but this codepath really needs to be rethought.

Follow up to Ie3f37b8b972dc6e89e3cd334672954d3632c1b20; see also
the discussion in T101666.

Change-Id: I6ae99ea6bd8b6ee21b8ed8b06dc4e9e324050ab7
2020-04-09 11:45:24 -07:00
C. Scott Ananian 4dcda73ef7 Remove deprecated Parser::enableOOUI(), take 2
This adds a missing call to OutputPage::setupOOUI(), to fix a code path
where `<templatedata>` is expanded via API call (eg, during Parsoid
rendering) and an OOUI theme has not been set up.  This hacky workaround
is pretty bogus, since the output will not have the proper user skin
or directionality, but it avoids a crash (and duplicates the previous
behavior, without using the deprecated method).

Change-Id: Ie3f37b8b972dc6e89e3cd334672954d3632c1b20
2020-04-08 16:10:33 -04:00