Commit graph

334 commits

Author SHA1 Message Date
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
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
jenkins-bot
0833fba86e Merge "parser: Mark ParserOutput::addOutputPageMetadata as internal and document" 2022-02-08 15:29:54 +00:00
Timo Tijhof
37967aaf5d parser: Mark ParserOutput::addOutputPageMetadata as internal and document
Change-Id: I4fc181d703d6edde4f0cc5a60c82692650545ecb
2022-02-07 22:21:16 -05:00
C. Scott Ananian
1a34a2d761 Update document comment for new ::appendExtensionData() method
As the @note says, only types which can be array keys are currently supported
as values.  Fix the phan @param to match.

(In the future we might use a different data representation which would
allow richer types, but we're starting simple.)

Change-Id: I141dc5381a8b260a3a99553b7855a1fd01b0170f
2022-02-07 12:16:23 -05:00
C. Scott Ananian
1161d3cb9c Fix documentation comment for ParserOutput::addTrackingCategory()
The @todo requested in the comment was done in
9632dfb041.

Change-Id: I152b04ae9f9d9ec42bb0654b31060265274245f4
2022-02-07 12:15:19 -05:00
C. Scott Ananian
baaee141e4 Add ParserOutput::appendExtensionData()
Soft-deprecate the use of ::setExtensionData() to destructively update
the value stored under a single key.  Add the new
::appendExtensionData() method to use where multiple values are
desired.  This accomodates the asynchronous and incremental parsing
goals on the Parsoid roadmap.

Bug: T300981
Change-Id: I2dea4ba71ea506428854a9983c1abd906b2efd5f
2022-02-04 13:43:22 -05:00
C. Scott Ananian
0f5dc718ce Add ParserOutput::{set,append}JsConfigVar()
Deprecate ParserOutput::addJsConfigVars() and add setter methods which
better ensure that the ParserOutput contents are independent of parse
order.  This accomodates the asynchronous and incremental parsing goals
on the Parsoid roadmap.

Bug: T300307
Change-Id: I4f08d1098da211f7bf5c43c08c620de224cbf37f
2022-02-04 13:42:59 -05:00
C. Scott Ananian
75480cf1e0 Narrow the signature of ParserOutput::addModules() and ::addModuleStyles()
We always implicitly converted a string argument to an array anyway; just
ask the caller to do this instead so that we can have a simpler and
more straight-forward method signature which matches the plural form
of the method name.

Part of the ParserOutput API cleanup / Parsoid unification discussed
in T287216.

In a number of places we also rename $out to $parserOutput, to make it
easier for codesearch (and human readers) to distinguish between
ParserOutput and OutputPage methods.

Code search:

https://codesearch.wmcloud.org/deployed/?q=p%28arser%29%3F%28Out%7Cout%29%28put%29%3F-%3EaddModule%28Style%29%3Fs%5C%28&i=nope&files=&excludeFiles=&repos=
https://codesearch.wmcloud.org/deployed/?q=arser-%3EgetOutput%5C%28%5C%29-%3EaddModule%28Style%29%3Fs%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T296123
Depends-On: Iedea960bd450474966eb60ff8dfbf31c127025b6
Depends-On: I7900c5746a9ea75ce4918ffd97d45128038ab3f0
Depends-On: If29dc1d696b3a4c249fa9b150cedf2a502796ea1
Depends-On: I8f1bc7233a00382123a9b1b0bb549bd4dbc4a095
Depends-On: I52dda72aee6c7784a8961488c437863e31affc17
Depends-On: Ia1dcc86cb64f6aa39c68403d37bd76f970e55b97
Depends-On: Ib89ef9c900514d50173e13ab49d17c312b729900
Depends-On: If54244a0278d532c8553029c487c916068e1300f
Depends-On: I8d9b34f5d1ed5b1534bb29f5cd6edcdc086b71ca
Depends-On: I068f9f8e85e88a5c457d40e6a92f09b7eddd6b81
Depends-On: Iced2fc7b4f3cda5296532f22d233875bbc2f5d1b
Depends-On: If14866f76703aa62d33e197bb18a5eacde7a55c0
Depends-On: I9b7fe5acee73c3a378153c0820b46816164ebf21
Depends-On: I95858c08bce0d90709ac7771a910f73d78cc8be4
Depends-On: If9a70e8f8545d4f9ee3b605ad849dbd7de742fc1
Depends-On: I982c81e1ad73b58a90649648e19501cf9172d493
Depends-On: I53a8fd22b22c93bba703233b62377c49ba9f5562
Depends-On: Ic532bca4348b17882716fcb2ca8656a04766c095
Depends-On: If34330acf97d2c4e357b693b086264a718738fb1
Change-Id: Ie4d6bbe258cc483d5693f7a27dbccb60d8f37e2c
2022-01-20 13:14:20 -05:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Amir Sarabadani
3cacc7f9c3 Fix local rendering of link in diff view with action=render
We probably should move Linker::expandLocalLinks( $text ) somewhere
better.

Bug: T263581
Change-Id: Iac446e761a709b6ceff5bd83dfa9a80db50a08d5
2021-12-01 17:18:53 +01:00
C. Scott Ananian
59d728f136 Hard-deprecate ParserOutput::hasDynamicContent()
This method was renamed in 1.37 to ::hasReducedExpiry() and only has a
single use in core (and no uses outside of core, as far as I can
tell).  Rename the single use and deprecate the old name.

Code search:

https://codesearch.wmcloud.org/search/?q=hasDynamicContent&i=nope

Change-Id: Ie2bea78e31433a01a5590becc06f32294b04522e
2021-11-23 15:40:46 -05:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
Ppchelko
643fc535c3 Reapply "Move limit report rendering to ParserOutput"
This reverts commit 2bcb3fe567.

Reason for revert: this is a good change,
just needed more work to not break CI

Change-Id: I23768bee242e3cf81b1493a740cf070e7ad1e224
2021-11-09 11:08:08 -08:00