Commit graph

346 commits

Author SHA1 Message Date
jenkins-bot
ece6ba5417 Merge "ParserOutput: point to documentation for serialization compatibility." 2023-01-03 18:27:59 +00:00
daniel
f2febebb30 ParserOutput: point to documentation for serialization compatibility.
Any changes to the way ParserOutput is serialized must follow the
instructions at
<https://www.mediawiki.org/wiki/Manual:Parser_cache/Serialization_compatibility>.

Change-Id: Ic16a6804ca0a65f8f9abbc3112359cc239febde3
2023-01-03 19:08:22 +01:00
Amir Sarabadani
523ab7cff8 Reorg: Move RawMessage to under language/
To follow Message. This is approved as part of RFC T166010.

Also namespace it but doing it properly with PSR-4 would require
namespacing every class under language/ and that will take some time.

Bug: T321882
Change-Id: I195cf4c67bd51410556c2dd1e33cc9c1033d5d18
2022-12-16 11:30:19 +01:00
Matěj Suchánek
a592d47e91 Clean up redundant array manipulation
PHP does this implicitly.

Change-Id: I009a7c93d44fb5e8c430c971cfc637fa04a8e68d
2022-12-11 12:42:29 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Umherirrender
1b342a8893 Various doc fixes about false and null on method arguments/return types
Doc-only changes

Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
2022-11-03 18:55:47 +01:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
thiemowmde
d81f01e417 Replace various array type hints with more specific string[]
There are many, many more. I touch only a few where I'm sure it's
never anything but an array of strings.

Change-Id: I8b798f2e9d48f07a241b95ce0ace8fa9d981695d
2022-09-27 09:24:22 +02:00
Umherirrender
5c5498a202 Remove unused key variable from foreach loops
Change-Id: Id2d91e30a6f7cc4eb93427b50efc1c5c77f14b75
2022-09-21 21:18:43 +02:00
C. Scott Ananian
6c242a8a11 OutputPage::addParserOutputText(): use default ParserOutput options from skin
This addresses the common case patched by
I530d71d0f9279b40a263cd62467d3ef8c76975c3,
If6267f3389b166043fc94d7f952bc54122b1a378 and probably
the code in Article.php from I44045b3b9e78e7ab793da3f37e3c0dbc91cd7d39
by ensuring that "injectTOC" in the options passed to
ParserOutput::getText() defaults to the correct value based on the skin
being used by OutputPage.

Bug: T317333
Change-Id: Ica30569efbb5730eff5b807e8fc34beb2e13e74f
2022-09-08 15:46:23 -04:00
jenkins-bot
6d840fa896 Merge "ParserOutput::mergeMapStrategy - use a more robust comparison for objects" 2022-07-21 02:51:31 +00:00
Umherirrender
e00a52e6f5 Clean up line indent with mixed tabs and whitespaces
Change-Id: Ifcd15ecc4212d4ebfc26b2e18d6f1da47abf2a86
2022-07-09 22:21:53 +02:00
C. Scott Ananian
541542e588 ParserOutput::mergeMapStrategy - use a more robust comparison for objects
Map values can include JsonUnserializable objects, and strict
(reference) equality comparison of these objects is not going to
reflect value equality.  Serialize the values and compare strings
instead; this case should be hit very infrequently given that
rewriting the same extension data key is discouraged.

Bug: T312588
Change-Id: I942e7fa662b2f1a5e32fd55ef65eaa10a22afcfb
2022-07-08 16:07:18 +00:00
C. Scott Ananian
577879841c ParserOutput::mergeMapStrategy: don't crash if merging non-array values
The PHP `isset(...)` construct covers a multitude of possible "wrong
types" for the left hand side of an array access, but it still crashes
(with "Cannot use object of type stdClass as array") if the left hand
side is an object.

Bug: T312242
Change-Id: I35026c573fb941004764d46d5652ebcddc559c03
2022-07-07 15:02:57 +00:00
jenkins-bot
3ed9d3a6f9 Merge "Use the same tooltip for transcluded sections as normal ones" 2022-06-22 18:31:43 +00:00
daniel
697f28df32 ParserCache: always use JSON
When JSON support was introduced into ParserCache in 1.36, it was
controlled by a feature flag, $wgParserCacheUseJson. The feature flag
was "born deprecated" in 1.36. It can now be removed.

This means that ParserCache will always store entries as JSON.
Support for reading old non-JSON entries remains intact.
This is needed when updating wikis from a version older than 1.36
to the current version.

Change-Id: Id04e42bfb458d98414bac50e0d6c505e8878e5c0
2022-06-07 15:19:45 +02:00
Isabelle Hurbain-Palatin
1277d9f154 Still collect metadata on multiple writes
Follow-up to I9d1f0f6bab1305552a0350667d6142a24bc04049. That patch was
not collecting data at all (not even overwriting them over and over
again) - the assignment operation was, in practice, a NOP. This patch
fixes this.

Bug: T303014
Bug: T303015
Change-Id: I7d09b532f3270edf4327c16e032d665353d992f6
2022-05-17 11:14:51 -04:00
C. Scott Ananian
db492e204f ParserOutput: Ensure that array elements are always terminated with a comma
Change-Id: I47263fef3b6ad10ffcaa128ee415e560a3ed86c3
2022-05-17 11:14:43 -04:00
Derick Alangi
1618bbd671 Add data-parsoid data to ParserOutput for caching
NOTE: This changes the HTML returned by the endpoint!
It will now include the id="mwXYZ" attributes needed to
later map to data-parsoid entries.

Bug: T268205
Change-Id: I0a29434b996cc289eb67083e62bd6f1ad750cb4d
2022-05-16 15:06:15 +00:00
Bartosz Dziewoński
b19fcb64bf Use the same tooltip for transcluded sections as normal ones
Remove the code that outputs self-closing <mw:editsection ... /> tags
in Parser, previously used for transcluded sections.

Remove the ability to handle them in ParserOutput. We don't need
backwards-compatibility with cached content, because that feature did
not work correctly for several years: Remex-Tidy always expanded them
to normal open and close tags.

Remove handling for this case in skin code (and fix documentation).
These are backwards-compatible changes.

Depends-On: Idbf0b95a3c0b04caa056b71dd08f46659920114a
Bug: T306299
Change-Id: I3fac0f34d134d8eec46c7eefa3ad2b67abb957da
2022-05-14 02:44:46 +02:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
Brian Wolff
bec8dada48 Clarify generate-html and make ParserOutput behave as expected
Previously:
* It was unclear that generate-html is an optional optimization
* Most of MediaWiki core was doing $parserOutput->setText('') if
html wasn't generated. However this is wrong and will cause
$parserOutput->hasText() to return true and also potentially cause
cache pollution if a content handler both does that and supports
parser cache (Like MassMessage; see T299896)
* The default value of mText in the constructor was '', and most
of the time MW used that default. This doesn't seem right. If
setText() is never called, the ParserOutput should not be considered
to have text
* It was impossible to set mText to null, as $parserOutput->setText(null)
was a no-op. Docs implied you were supposed to do this, so it was very
confusing.

This patch clarifies docs, changes the default value for ParserOutput::$mText
from '' to null, and makes $parserOutput->setText(null) do what you
expect it to. The last two are arguably breaking changes, although
the previous behaviours were unexpected, mostly undocumented and
based on a code search do not appear to be relied on.

It seems like the main reason this only broke MassMessage is most
content handlers either don't support generateHtml, or they don't
support parser cache.

Bug: T306591
Change-Id: I49cdf21411c6b02ac9a221a13393bebe17c7871e
Depends-On: I68ad491735b2df13951399312a4f9c37b63a08fa
2022-05-03 11:23:08 +02:00
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
jenkins-bot
1a91fcb41e Merge "Emit deprecation warnings for ParserOutput::addOutputHook()" 2022-04-07 21:27:33 +00:00
C. Scott Ananian
05eda60400 Emit deprecation warnings for ParserOutput::addOutputHook()
Once no one is calling ::addOutputHook() we can stub out ::getOutputHook()
to just return an empty array.

Code search:
 https://codesearch.wmcloud.org/deployed/?q=-%3E%28addOutputHook%7CgetOutputHooks%29%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T292321
Change-Id: I1081696c4cc2e67c3c38b8f6e53054e62ac71502
2022-04-07 02:48:57 +00:00
jenkins-bot
6429390102 Merge "Use uniform representation for ParserOutput "index policy"" 2022-04-06 11:38:55 +00:00
jenkins-bot
fd5b58d80f Merge "Ensure forward compatibility with new ParserOutput index policy fields" 2022-03-31 20:19:25 +00:00
C. Scott Ananian
1143370a45 [doc only] Improve the documentation re non-string page property values
Bug: T305158
Change-Id: I64eb7ff8e7fdf4a94a2ce3206b73aefef34a6825
2022-03-31 11:10:03 -04:00
C. Scott Ananian
a331b0130b [doc only] Update ParserOutput @deprecation to include 'since' information
Change-Id: I92f15dbf3d9cc90bee2093e09d26a623fd5d2d0b
2022-03-31 11:09:14 -04:00
C. Scott Ananian
46acc1a257 Use uniform representation for ParserOutput "index policy"
As part of the project of enforcing uniform semantics for
combining ParserOutput objects (T300979) use standard boolean flags
for the 'index' and 'noindex' index policy metadata.

The forward-compatibility "1.39_wmf.7-ParserCache-*" serialization
test cases have been renamed to "1.39-ParserCache-*" in this commit;
backward compatibility with the prior representation of index policy
will continue to be tested via the "1.38-ParserCache-*" cases.

Bug: T300979
Change-Id: I683e5ae054a0425b03c60a4af8c845b576414c1d
2022-03-31 09:51:21 -04:00
C. Scott Ananian
664012e23f Ensure forward compatibility with new ParserOutput index policy fields
Instead of ParserOutput::$mIndexPolicy, a future MW version
(I683e5ae054a0425b03c60a4af8c845b576414c1d) will use two boolean fields
ParserOutput::$mIndexSet and ::$mNoIndexSet.  For parser cache migration
purposes, ensure that core can deserialize the new version so that
rollback are safe.

Add serialization test cases with the new boolean fields as
"1.39_wmf.7-ParserOutput-*"; compatibility with the existing
"mIndexPolicy" serialization will continue to be tested with the
"1.38-ParserOutput-*" cases.

Change-Id: I5e4fc68cea18b31ecb028b3867537dcbd86b93cd
2022-03-31 09:51:21 -04:00
jenkins-bot
b148414cd3 Merge "ParserOutput::collectMetadata: Suppress hard failures from Parsoid" 2022-03-12 01:25:51 +00:00
jenkins-bot
85c43c06bc Merge "Export ParserOutput strategy keys for jsConfigVars" 2022-03-11 22:36:10 +00:00
C. Scott Ananian
71f2705498 ParserOutput::collectMetadata: Suppress hard failures from Parsoid
A number of exceptions assume that the ParserAfterParse hook is called
exactly once per top-level page, and use that hook to "finalize"
various write-once properties in ParserOutput, including jsconfigvars.
Unfortunately, ParserAfterParse can't be supported properly in Parsoid
(T303630), which results in legacy extensions using this hook
overwriting extensiondata and jsconfigvars multiple times.

Instead of throwing an exception, restore the previous Parsoid
behavior where the last write wins.  This doesn't fix the root cause,
but at least it doesn't regress.  Eventually we'll have to deprecate
the ParserAfterParse hook, and when we do so we can add deprecation
warnings to these code paths in ParserOutput::collectMetadata() as
well and eventually remove them.

Noting uses ParserOutput::collectMetadata() except Parsoid at the
moment.

Bug: T303014
Bug: T303015
Change-Id: I9d1f0f6bab1305552a0350667d6142a24bc04049
2022-03-11 12:51:32 -05:00
C. Scott Ananian
a6d443f352 parser cache: Adjust types for timestamps
Split from Ifc7fc64ac26a756f181b7d0155f13a6500114f5e.

Found by phan strict checks.

Change-Id: I897367ecc1448edb542a0383e34fb34c0de8ed73
2022-03-11 11:42:05 -05:00
C. Scott Ananian
a3000c2972 Export ParserOutput strategy keys for jsConfigVars
This allows Parsoid to properly merge jsconfigvars via the external API
(ie, when Parsoid is run in 'standalone mode') when an extension uses
the new-in-1.38 ParserOutput::appendJsConfigVar() method.

Change-Id: I974d9ecfb4ca8b22361d25c4c70fc5e55c39d5ed
2022-03-09 17:42:00 -05:00
jenkins-bot
a9900325fa Merge "Ensure that ToC is converted into the proper target language" 2022-03-09 05:34:10 +00:00
jenkins-bot
74ebfcc00a Merge "Revert "ParserOutput: Use page language instead of site content language for conversion"" 2022-03-09 05:11:23 +00:00
C. Scott Ananian
0955046ca5 Ensure that ToC is converted into the proper target language
This patch exports the necessary information from the Parser into the
ParserOutput to ensure that the Table of Contents can be properly
language-converted: both ensuring that the target language is correct
(in cases where it differs from the content language) and that various
conversion-suppression mechanisms are functional.  When the
ParserCache does not (yet) have the new properties from Parser, the
behavior is unchanged from before (the content language is used, and
its "preferred variant").

This is a follow up to the "quick fix" deployed in
Ic14b3a49a8ee7ed600485d4f8a363a206035a847 to fix an UBN regression.

Parser tests have also been added to verify that ToC conversion
is correctly done (T299973).

Task T303329 has been opened to (eventually) rename the
'core:target-lang' and 'core:target-lang-variant' properties added to
the ParserOutput in this patch.

Bug: T303235
Bug: T295187
Bug: T299973
Followup-To: Ic14b3a49a8ee7ed600485d4f8a363a206035a847
Followup-To: Ib273f88531c340b561072ee9f616aa60725091e6
Change-Id: Ie0f1d7b6daffc8ff47228f6f086a257518f72717
2022-03-09 00:08:57 -05:00
C. Scott Ananian
e997f811ef Revert "ParserOutput: Use page language instead of site content language for conversion"
This reverts commit 0fdd607a84.

This attempt to fix T295187 caused other issues (T303235). A proper
fix is in Ie0f1d7b6daffc8ff47228f6f086a257518f72717.

Bug: T303235
Change-Id: Ib273f88531c340b561072ee9f616aa60725091e6
2022-03-08 16:01:08 -05:00
C. Scott Ananian
773801e439 Deprecate the ParserOutputHook functionality
These hooks should be implemented in the OutputPageParserOutput hook
instead.

Bug: T292321
Change-Id: Ib6f457596ea9d193bc03e15a48f135db4f4a6b27
2022-03-07 16:56:10 -05:00
jenkins-bot
df0801833a Merge "ParserOutput: Use page language instead of site content language for conversion" 2022-02-24 16:08:07 +00:00
jenkins-bot
5abb2ecdd5 Merge "ParserOutput: implement the abstract ContentMetadataCollector interface" 2022-02-22 22:52:52 +00:00
Func
0fdd607a84 ParserOutput: Use page language instead of site content language for conversion
Content language of specific pages can be changed manually or by the Translate extension.

Bug: T295187
Change-Id: I714711201ba71a2234d625c2e71505973655f36e
2022-02-21 14:59:37 +08:00
jenkins-bot
99dee6855a Merge "Change return value of ParserOutput::getPageProperty() when property is missing" 2022-02-19 00:49:48 +00:00
C. Scott Ananian
bc36c768f0 ParserOutput: implement the abstract ContentMetadataCollector interface
This has core implement an abstract interface defined by Parsoid in order
to allow Parsoid to record metadata in ParserOutput without introducing
a cyclic dependency.

Bug: T287216
Followup-To: Ia02c6774c87b13d1ae5a8ed1e55cdd8c88c19b9e
Depends-On: Ie0e358a4910c1946eb4added76318fcacf9308df
Change-Id: I15c0e81185b9957fe097c82e6609a200742ee7d1
2022-02-18 16:24:50 -05:00
C. Scott Ananian
c39ef6c6c9 Change return value of ParserOutput::getPageProperty() when property is missing
The old ParserOutput::getProperty() method returned `false` when a property
was missing.  This requires callers to use the `?:` syntax to supply default
values, which then causes any falsey value to be treated as missing.
So, for example, setting the defaultsort to '0' will cause the default
sort to be ignored.

Modern php convention is to use `null` for missing values, and the `??`
syntax is a better/more restrictive alternative to `?:`.

We renamed `ParserOutput::getProperty()` to `::getPageProperty()` in
1.38 (Ie963eea5aa0f0e984ced7c4dfa0fd65d57313cfa/T287216) but kept the
return value convention.  Before this actually makes it into a 1.38
release, take the opportunity to fix the return value for the new
`ParserOutput::getPageProperty()` method to return `null` when the
property is missing.

We need to do some temporary workarounds to the places we'd
already swapped over to use the new `::getPageProperty()` method
to allow them to handle either `false` or `null` as a return value;
we'll clean that up once this is merged.

Code search:
https://codesearch.wmcloud.org/deployed/?q=-%3EgetPageProperty%5C%28|T301915&i=nope&files=&excludeFiles=&repos=

Bug: T301915
Depends-On: I3f11ce604970e47b41fc1c123792df8c3045626f
Depends-On: Ie7533f49fe4cad01ebfda29760d23c61e9867b10
Depends-On: Ic5c09f5caa4c897bc553c614fbae9cee159566a2
Depends-On: I0278b2eafd90e77e4fee41c45a1165fb79ddf47e
Depends-On: I383abb6b7dc5e96c0061af13957609f6e31a1065
Depends-On: I79f9f4078e415284af29b15047bafd1c823d7f5b
Depends-On: I02276c48c49f5d2d241a69eb0a6cdf439b572d8b
Depends-On: I71628661b4539a4e35ae32846e719f92bcf782e0
Depends-On: I7e215cb43de0ce150a6bcc00f92481dcdcfed383
Change-Id: Iaa25c390118d2db2b6578cdd558f2defd5351d15
2022-02-18 21:15:58 +00:00
C. Scott Ananian
7f849e965b Provide method to merge a ParserOutput into a ContentMetadataCollector
ContentMetadataCollector is a write-only interface defined by Parsoid
that performs the metadata collection functions of ParserOutput.  In
order to support asynchronous and out-of-order parses,
ContentMetadataCollector is write-only and merges of fragments are
defined to be independent of merge order.

This provides an initial implementation of ParserOutput::collectMetadata()
which transfers metadata from a ParserOutput to a ContentMetadataCollector.
It is intended that the flags and accumulators in ParserOutput will be
(incrementally) made more regular so that ::collectMetadata() grows
simpler over time.

An optional $strategy argument is added to ::appendExtensionData() and
::appendJsConfigVars() to allow future expansion of merge strategies,
although only `union` is supported for the moment.

The MW_MERGE_STRATEGY_UNION constant will be upstreamed into Parsoid's
ContentMetadataCollector class as MERGE_STRATEGY_UNION; we've added a
prefix to ParserOutput's copy for now to avoid a conflict with the
constant which Parsoid will define.

Bug: T300979
Change-Id: I4e20b84eb590296fb3c011bb4d658d7a65082a11
2022-02-17 12:29:19 -05:00
C. Scott Ananian
735670adba Add parameter type to ParserOutput::setEnableOOUI()
This is a tiny cleanup.  All the callers have been checked to pass boolean
values here.

Change-Id: I113648ea8262065dbfc0a6b61f3bc7abb2611b98
2022-02-09 12:47:05 -05:00
C. Scott Ananian
98615667f7 Add return types to methods in ParserOutput
Just added the low-hanging fruit: the methods where the return type was
obvious from local inspection.

Change-Id: If6aabfc8f0dacb156167745808fd5c57cdb3eb23
2022-02-09 12:47:05 -05:00