Commit graph

173 commits

Author SHA1 Message Date
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
C. Scott Ananian 3f270b9ad7 Don't use deprecated Parser::enableOOUI() hook
Follow up to I71be19c1d735fef5b781c68ef7ba47cafc37595d.

Bug: T236809
Change-Id: Ib75f530506bfc9692137b0538f66eb5b511637f0
2020-04-08 13:47:08 -04:00
DannyS712 720aff85b1 PHP coding conventions: reorder doxygen tags
See https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#Doxygen_tags

Change-Id: Ied27b09fd717fd469170dc842091732195b4046d
2020-03-26 15:48:33 +00:00
libraryupgrader e3fb9734b1 build: Updating composer dependencies
* jakub-onderka/php-console-highlighter: 0.3.2 → 0.4.0
* mediawiki/minus-x: 0.3.2 → 1.0.0
* mediawiki/mediawiki-phan-config: 0.9.0 → 0.9.1

Change-Id: Ifdb5afed1ec5114d9e25ebbd81259d77cdc33e13
2020-01-30 12:25:48 +00:00
Timo Tijhof 6f362c6d8a Minor clean up in new ParsoidFetchTemplateData hook
Follows-up 956367fb90.

* Fix typo.
* Remove <del>footgun</del><ins>dangerous return value</ins>
  from this unabortable hook.
* Document the weird PageProps workaround.
  This should be fixed in core.

Change-Id: I6b22e9c2112039e5703e6a62252f1909b15c8887
2020-01-28 19:14:12 +00:00
libraryupgrader 9a41a95389 build: Updating mediawiki/mediawiki-codesniffer to 29.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate

Additional changes:
* Also sorted "composer fix" command to run phpcbf last.

Change-Id: I8846de470461b4887dbc1e33653c8cdec8839366
2020-01-14 12:46:52 +00:00
libraryupgrader 1c8f1b14e8 build: Updating mediawiki/mediawiki-phan-config to 0.9.0
Additional changes:
* Added .eslintcache to .gitignore.

Change-Id: I96c348782dc892efb80e2fffa898f595fa76c43a
2019-12-28 17:21:07 +00:00
Subramanya Sastry 956367fb90 Implement ParsoidFetchTemplateData hook for Parsoid/PHP
* This hook supports functionality that Parsoid/JS used the MW API for.

  Parsoid's html2wt code requests templatedata for titles one
  at a time currently and so this hook also supports lookups one
  title at a time.

  This initial implementation is good enough for initial Parsoid/PHP
  deployment.

* As part of later performance optimization, we should figure out if
  we want to fetch templatedata for all templates in batch mode and
  work out the details (selser doesn't touch all templates, for one).

  The hook does accept an array of titles, but it looks them up
  serially in a simple for-loop.

  Separately, we need to resolve if this is better architected as
  a lookup service vs. a hook as it is now (see discussion on gerrit).

* Tested locally on my local wiki.

Bug: T238954
Change-Id: I01fb6a9f334ca37a703be497524180f87fb8bbf7
2019-11-25 11:09:13 -06:00
jenkins-bot 2aeec4610d Merge "Do not always store template data compressed" 2019-09-30 23:56:21 +00:00
saper ce13175017 Do not always store template data compressed
Only MySQL can handle blobs in page_props.pp_value

Bug: T203850
Change-Id: Ie20d412d89855e451d48f7656d97fb305b1c4c55
2019-09-30 14:24:39 +02:00
DannyS712 313d627774 Use Special:MyLanguage in API help links
Bug: T231269
Change-Id: I2ba71ea4f777ee72e649a8db9e211229f6584e63
2019-08-27 06:44:14 +00:00
Fomafix 962a84ed82 Preload tablesorter styles by module 'jquery.tablesorter.styles'
This change avoids the flash of missing sorting buttons while loading,
but only with I0b446d18f47428d8c0c4aed78b75de16fe106218 in MediaWiki
core included in MediaWiki 1.33 or higher.

Depends-On: I0b446d18f47428d8c0c4aed78b75de16fe106218
Change-Id: I2c3eeb3a83822798ae0c46fcfea071df706798d7
2019-06-12 07:37:10 +02:00
Fomafix b56cba7d18 Use MediaWikiServices instead of $wgContLang
Bug: T200246
Change-Id: Ic4f08ccb50c7a92a34b6a70c7b726825ba07fd45
2019-06-12 06:40:01 +02:00
James D. Forrester ecab0b8dbb build: Upgrade mediawiki/mediawiki-phan-config from 0.5.0 to 0.6.0
Change-Id: I5d1e3bde15fb951f7dc8ee7d753b090a12661e3c
2019-05-19 18:42:33 +02:00
Umherirrender 5ef5287267 Use php null coalesce operator ??
Change-Id: I50244cd16f2c30bacc90421fa9218a8bf454ca6a
2019-03-11 22:03:39 +01:00
Brad Jorsch c14203edde ApiTemplateData: Check for $data->paramOrder being unset
Ib40d23da made it possible for $data->paramOrder to be unset.
ApiTemplateData needs to check for that before passing it to
ApiResult::setIndexedTagName().

Bug: T213953
Change-Id: I7647ddfc47426c7b6be8ddcd84472371eec07d72
2019-01-20 10:41:02 -05:00
Timo Tijhof 4aaa9dfcf8 Remove default value for 'paramOrder'
When normalising a TemplateData blob for API consumers, we previously
automatically generated the 'paramOrder' with the order of the keys
as they were specified in the JSON blob (which, unlike in JS, is
known to be reliable in PHP).

While this was useful to some extent, it made it mandatory for
Parsoid and VisualEditor to always re-order properties during
edits to match the specified order.

In order to allow the order to remain flexible/unspecified, the
original Specification made paramOrder optional, but during the
implementation I gave it a default, which kind of defeated that
intention. This patch fixes that.

Bug: T138200
Change-Id: Ib40d23dac7e75274083f95a25c5aa1c22dfffb22
2019-01-08 19:55:59 +00:00
Umherirrender 9ac1604d19 Improve param doc
Change-Id: Idc0780dae2748d6353ae7e1731f183307489626a
2019-01-03 00:21:18 +01:00
jenkins-bot 4221945fc9 Merge "Ignore bang magic word in table syntax when guessing parameters" 2018-12-10 23:55:08 +00:00
Sam Wilson 75e54ae999 Ignore bang magic word in table syntax when guessing parameters
Three-braces-and-a-bang can be a table starting construct in templates.

This also fixes an overlooked bug in which the test wasn't checking
array element key names.

Bug: T157029
Change-Id: I69ed4fc9fe3bb126b7b39abea0f58ad56adf3885
2018-11-27 11:46:23 +08:00
Ed Sanders 822d0cd345 Rename module editPage→editTemplatePage, create minimal new editPage module
VisualEditorPluginModules loads whenever VE loads, so create a minimal
loader page to check if we are in the template namespace before loading
the rest of the TemplateData init code.

Bug: T208765
Change-Id: Id127eb4a2472a6ce9da7672f9237b182cf6be2eb
2018-11-24 00:14:03 +00:00
jenkins-bot db3d73bc84 Merge "eslint: Introduce wikimedia/qunit ruleset" 2018-11-15 23:57:55 +00:00
Ed Sanders 9a8c807f51 eslint: Introduce wikimedia/qunit ruleset
Change-Id: I3972918c00e69d325c5cb2055d4996a8c07b1034
2018-11-15 23:21:32 +00:00
Bartosz Dziewoński 1421878eee Separate parameter aliases in the description table with spaces
This allows them to wrap over multiple lines if necessary, greatly
improving the result for templates with ridiculous number of aliases,
like <https://en.wikipedia.org/wiki/Template:Cite_book/TemplateData>.

Change-Id: I5826ac31b83e81f89f85e87f9098570b3759ccfb
2018-11-15 23:08:18 +00:00
jenkins-bot 593d23fd36 Merge "Don't store templatedata pageprop on doc-subpage" 2018-10-31 15:21:49 +00:00
Timo Tijhof 73aed63e0a ApiTemplateData: Address non-array count() warning on PHP 7.2
The $data value here comes from TemplateDataBlob which is always
an instance of stdClass. It has no items that make sense to count,
and the object was already being used as $data->params a few lines
higher, which means this count operation would always yield "1",
by proxy of count() effectively seeing the non-array as an array
containing the one non-array item.

Bug: T202087
Change-Id: If725aa8b4229613bf60290eb78654a42497056c8
2018-10-14 03:54:24 +01:00
Timo Tijhof 777ddee3aa ApiTemplateData: Use strict check for $langCode
This is assigned as boolean false or any string value.
The previous code used in implicit boolean cast to differentiate,
but the check is insufficient given that "" and "0" would also
cast to false. It is not the responsibility of this code to filter
those out.

Change-Id: I2cc707432b93703b29c49ac17d737f34119fc400
2018-10-14 03:52:55 +01:00
Timo Tijhof 29162276eb ApiTemplateData: Remove needless count() call
These variables always hold arrays, and to assert an array being
non-empty, boolean evaluation is reliable and suffices.

Change-Id: I5173f9d38ff52807a8025897115823d093052ecf
2018-10-14 03:51:38 +01:00
Umherirrender 8d0a3ea30c Update namespace for MediaWiki\Revision\RevisionRecord
Follow-Up: I16bea8927566a3c73c07e4f4afb3537e05aa04a5
Change-Id: Iae4f59a54a0fb65058ef43f51c5c819646935ac7
2018-10-11 19:56:27 +02:00
Timo Tijhof 326558fc77 Don't store templatedata pageprop on doc-subpage
This resolves two issues:
* Database inefficiency (T52512).
* Doc pages showing on Special:PageWithProp.

It also makes progress on (but doesn't fully resolve) T54448,
by not outputting encouraging accidental use of "/doc" by
displaying descriptions and parameter documentations for them
below the suggestions in VisualEditor.

Bug: T52512
Bug: T54448
Change-Id: I99323d7adc5fc072a85ff1d3595f805f537bbb43
2018-10-09 17:46:21 +00:00
jenkins-bot 49f1201621 Merge "Remove empty Default, Example and Auto value sections of the output table" 2018-09-28 16:08:34 +00:00
Agabi10 348edb68d2 Remove empty Default, Example and Auto value sections of the output table
Bug: T125333
Change-Id: I1f7135cdf22c04aaa31744096900fd7ea65f9a37
2018-09-28 15:24:14 +00:00
Volker E e06b2b1686 Replace deprecated 'advanced' by renamed to 'settings' icon
One more, after my comment in I997bc0f8c7d99f73c1cc6b4ce46f6bcdc1eee410
got happily ignored.

Bug: T190581
Change-Id: I26dc9018693ffd4c5edcda021c8adce52325cdc9
2018-09-12 12:49:10 -07:00
Sam Wilson 79e5347d90 Prevent leading hash from starting param names when guessing
Parameter names can be constructed with parser functions, so
we should not include these as raw parameter names. There
might be more characters to add here.

Bug: T203605
Change-Id: If57a9ed7edf1e881cd121d9a1bcb2e7455c04ec9
2018-09-12 10:04:45 +08:00
jenkins-bot 6d438766c8 Merge "Fix problems with MediaWiki messages and non-displaying icons" 2018-09-09 10:41:50 +00:00
Saint Johann c608d204c1 Fix problems with MediaWiki messages and non-displaying icons
Bug: T160252
Change-Id: I997bc0f8c7d99f73c1cc6b4ce46f6bcdc1eee410
2018-09-03 17:14:16 +02:00
Sam Wilson bc1422b788 Ignore subsequent similarly-named parameters when extracting
When extracting raw parameters from wikitext, ignore those that
only differ from already-found ones by spaces, underscores, or
hyphens.

Bug: T193265
Change-Id: I012e06bf4353eaaf0613124d7d6b88f3444d248a
2018-08-27 11:14:27 +08:00
Sam Wilson f5fece10fd Guess template parameters when templatedata is missing
Deprecate the 'doNotIgnoreMissingTitles' parameter and
replace it with 'includeMissingTitles'. If this parameter
is requested 'raw parameters' will be added to the
response in the same format as templatedata parameters.
Raw parameters are those that *might* be in the
template (using the same logic as the TemplateData generator
wizard).

Also fix the example that was using a falsy value which
meant the option was enabled rather than disabled as it
says in the docs.

Bug: T191756
Change-Id: Ie5fe2097cda45968bb080643d3afcac0b2868a6c
2018-04-25 11:42:18 -07:00
Kunal Mehta de96754626 Move PHP classes to includes/
Change-Id: I7f46b6da2995687b3ec1ed95cf6f35c2a40d4f1e
2018-04-24 16:50:31 -07:00