Commit graph

730 commits

Author SHA1 Message Date
jenkins-bot
672f5d7e6b Merge "parser: Avoid cache stampede on pages which use {{CURRENTYEAR}}" 2024-08-26 16:00:08 +00:00
Isabelle Hurbain-Palatin
a3cf629d2f Remove ParserOutput::getText() calls from core (direct pipeline)
This is the second patch of a series of patches to remove
ParserOutput::getText() calls from core. This series of patches should
be functionally equivalent to I2b4bcddb234f10fd8592570cb0496adf3271328e.

This patch replaces the calls to getText where the legacy parser is
called directly by creating a pipeline and invoking it on the generated.
These should probably eventually use the Content framework to generate
output instead of using Parser directly (T371008), which will also allow
them to transparently support Parsoid.

Bug: T293512
Change-Id: I45951a49e57a8031887ee6e4546335141d231c18
2024-08-23 18:15:00 +02:00
Isabelle Hurbain-Palatin
7964b98ce9 Remove ParserOutput::getText() calls from core (getRawText)
This is the first patch of a series of patches to remove
ParserOutput::getText() calls from core. This series of patches should
be functionally equivalent to I2b4bcddb234f10fd8592570cb0496adf3271328e.

This first patch replaces the calls to getText to calls to
ParserOutput::getRawText when the pipeline has no reason to be executed.

Bug: T293512
Change-Id: I0ad53cd074ca9cf13e96e6b08179e13aeea180f4
2024-08-19 14:20:20 +02:00
thiemowmde
ba36bf46a1 tests: Make use of ??= and ?? operators in various tests
The main benefit is that this syntax avoids repeating the variable
name. It does the same as before.

Change-Id: I2040be889c749f4e2416ca9948ba261345858af2
2024-08-15 11:44:46 +02:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
Ebrahim Byagowi
697e19e461 Add MediaWiki\Registration namespace to registration classes
Bug: T353458
Change-Id: Ifa3b6a6e0353bb4ce21a3f4456f1fc696c8d377c
2024-08-10 10:08:22 +00:00
Ebrahim Byagowi
4c270a72ac Add namespace to WikitextContent
It adds MediaWiki\Content namespace to WikitextContent
and two classes related.

Change-Id: Ib74e4c5b3edac6aa0e35d3b2093ce1d0b794cb6d
2024-08-06 17:42:51 +03:30
Bartosz Dziewoński
df4cbf5ac6 Replace gettype() with get_debug_type() in debug/log/test output
get_debug_type() does the same thing but better (spelling type names
in the same way as in type declarations, and including names of
object classes and resource types). It was added in PHP 8, but the
symfony/polyfill-php80 package provides it while we still support 7.4.

Also remove uses of get_class() and get_resource_type() where the new
method already provides the same information.

For reference:
https://www.php.net/manual/en/function.get-debug-type.php
https://www.php.net/manual/en/function.gettype.php

In this commit I'm only changing code where it looks like the result
is used only for some king of debug, log, or test output. This
probably won't break anything important, but I'm not sure whether
anything might depend on the exact values.

Change-Id: I7c1f0a8f669228643e86f8e511c0e26a2edb2948
2024-07-31 19:33:57 +02:00
Kunal Mehta
4d49a4a59e Extract LintErrorChecker out of SignatureValidator
This code was partially copied into MassMessage and will hopefully
enable more places that accept arbitrary wikitext to check lint errors.

It also hides the internal details of checking with the Linter
extension's configuration in one place until it can be refactored into
something more acceptable (T360809).

Bug: T368690
Change-Id: Iaeb3ccbd61a2a8cb0d8b3dc8b06a3a10bc8fa653
2024-07-29 14:35:40 -04:00
thiemowmde
32d214dd6d Drop duplicate test cases and @dataProviders from tests
A single test function can have multiple @dataProviders. No problem.

A @dataProvider can also be used by multiple test functions. No
problem. No need to duplicate such large pieces of code when it's
identical anyway.

Change-Id: I5aea36304ec2d1666ff2334ba883df07a70c15c5
2024-07-19 10:18:31 +00:00
Ebrahim Byagowi
fab78547ad Add namespace to the root classes of ObjectCache
And deprecated aliases for the the no namespaced classes.

ReplicatedBagOStuff that already is deprecated isn't moved.

Bug: T353458
Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
2024-07-10 00:14:54 +03:30
Novem Linguae
3391b91af2 Sanitizer: delete method removeHTMLtags()
Git blame on wfDeprecated() is 7 years old.

Unique name, no sign of it in CodeSearch for MediaWiki & services
at WMF. Couple of CodeSearch hits using the "Everything" filter.

Bug: T362636
Change-Id: I8961ebb3a72b328e839659aeeee3e73512a88dee
2024-06-27 14:09:00 +00:00
Umherirrender
b4e0d31644 tests: Use namespaced classes (@covers)
Some fixes done via codesniffer fix (Ibd0f48e14e)

Change-Id: I0404ceca7c5abe8d32ef9a8fce404c7b89ffbaae
2024-06-14 00:15:40 +02:00
C. Scott Ananian
0e6649bdec Add parser cache test data for JsonDeserializable extension data
I realized that even though we have a lot of ParserCache serialization
tests, and we have unit tests for JsonCodec, we don't have any tests
which bring these together and include JsonDeserializable data inside
ParserOutput objects.

Change-Id: I9dfe1050c18010d1447e77e0670e9e601449b110
2024-06-12 21:13:28 -04:00
James D. Forrester
19f4e6945a Rename JsonUnserial… to JsonDeserial…
This is to make it clearer that they're related to converting serialized
content back into JSON, rather than stating that things are not
representable in JSON.

Change-Id: Ic440ac2d05b5ac238a1c0e4821d3f2d858bc3d76
2024-06-12 14:50:58 -04:00
C. Scott Ananian
5c18d18f46 SerializationTestUtils: handle 1.xx_wmf* versions; don't fail immediately
The validate* maintenance scripts for CacheTime, ParserOutput, and
MessageValue didn't handle 1.xx_wmf* versions correctly, sorting them
*after* the final released 1.xx version.  Further, failing immediately
when a mismatch is found in the validate* scripts can mislead maintainers
into thinking only a single mismatch is present.

Change-Id: I4c7bc281c7398d889652a6a1bd9c511d31ffca39
2024-06-03 12:23:46 -04:00
jenkins-bot
a45f7cf0df Merge "SerializationTestTrait: make phpunit data providers static" 2024-05-22 16:18:49 +00:00
C. Scott Ananian
5d775fa1b3 SerializationTestTrait: make phpunit data providers static
PHPUnit 10 requires test data providers to be static.  This patch doesn't
completely do the job, as some providers currently call the non-static
method `$this->markTestSkippedIfPhp()`, but it gets us closer to PHPUnit 10
compatibility.

This also lets us simplify the validateParserCacheSerializationTestData
maintenance script and make it slightly more generic.

Change-Id: Ie3696bfaa29aca9da45f54239126222e8c847ea9
2024-05-22 11:43:26 -04:00
Fomafix
66aa439d00 Parser: Inject service LanguageNameUtils
Change-Id: Ia9884f991550c96e4d9bbca9bfb882144716cd24
2024-05-20 19:23:37 +00:00
thiemowmde
52ddf3e8ce Remove all @package comments
I don't think these do anything with the documentation generators
we currently use. Especially not in tests. How are tests part of a
"package" when the code is not?

Note how most of these are simply identical to the namespace. They
are most probably auto-generated by some IDEs but don't actually
mean anything.

Change-Id: I771b5f2041a8e3b077865c79cbebddbe028543d1
2024-05-10 13:53:15 +02:00
C. Scott Ananian
c668d33d21 parser: Avoid cache stampede on pages which use {{CURRENTYEAR}}
With the precise expiration computation for magic words like
{{CURRENTYEAR}} there's the potential for all the pages which
use (say) {{CURRENTYEAR}} to expire at the exact same time,
causing a cache stampede.

I9acb42b0d9ff67798a1624cbf9c7cac99c8fbe2f added code to "randomly"
stagger the cache expiration:

  $ttl += ( $deadlineUnix % self::DEADLINE_TTL_STAGGER_MAX );

However, this "stagger" was not actually random, since it is
based on the computed deadline.  So all of the pages which use
{{CURRENTYEAR}} will all compute the same `$deadlineUnix` (midnight
of January 1st of the next year) and thus compute the same "stagger".

Change $deadlineUnix to $tsUnix so that the stagger is based on when
this particular page is being parsed, which should actually have
the desired effect of spreading out the possible cache stampede.

Followup-To: I9acb42b0d9ff67798a1624cbf9c7cac99c8fbe2f
Change-Id: I95272e301c00e4646dd29ca22abc26c6cbe9028e
2024-05-06 16:36:45 -04:00
Bartosz Dziewoński
f0c7fa9234 Move section edit links outside headings (new heading HTML)
Legacy parser can now output headings using a more accessible markup,
which is also identical to the markup used by the Parsoid parser.

Changes to client-side JS and CSS necessary to support the new markup
have already been merged in earlier commits.

includes/skins/Skin.php
includes/ServiceWiring.php
* Define a new skin option, 'supportsMwHeading', which can be used
  to toggle the new markup per-skin.
* Update the built-in fallback skin to enable it. This affects the
  output in parser tests.

docs/config-schema.yaml
includes/config-schema.php
includes/config-vars.php
includes/MainConfigNames.php
includes/MainConfigSchema.php
* Add a new configuration setting, 'ParserEnableLegacyHeadingDOM',
  which can be used to toggle the new markup per-site.

includes/OutputTransform/Stages/HandleSectionLinks.php
* Output new heading HTML for skins that enabled the option.

tests/*
* Duplicate parser tests that cover heading generation to cover both
  new and old markup. Update other parser tests to use new markup.
* Add some unit and integration tests for the behavior of the skin
  option and some parser tests for edge cases of the new markup.

Bug: T13555
Change-Id: I1180169a8e83af834c2984ba16089e6277f2a8dd
2024-05-06 12:25:33 -04:00
Timo Tijhof
c02513c97e phpunit: Fix tests relying on implicit wgScript/wgArticlePath
A number of tests have hardcoded expections that pass only in WMF CI
where Quibble has LocalSettings.php with $wgScript and $wgArticlePath
set a certain way.

We could fix these by adding setMwGlobals() in their tests, as we
often do, but these are so often forgotten that I'd rather we just
add them to TestSetup.php so that it is simply impossible to write a
test that that passes locally for you (if you have the same config)
but not for someone else.

There is a larger project in there somewhere about expanding this
slowly such that we basically only pluck DB-settings and extension
enablement from LocalSettings and otherwise run the tests with the
default settings in PHPUnit. Pretty much by definition, any (other)
setting you have in LocalSettings is irrelevant because it either:
1. has no effect on the test (majority, harmless either way),
2. has a custom default via TestSetup.php (which has precedence over
   LocalSettings.php),
3. is relevant to the code being tested and the test case correctly
   calls setMwGlobals() to ensure a consistent value during test.
4. is relevant to the tested code but has no override, thus only
   passes if you happen to have the "right" value set for it
   (undesirable).

Case 4 is already categorically impossible for the most common config
settings that influence random code because we give them a value
in TestSetup.php. This patch expands that to include $wgScript
and $wgArticlePath. Perhaps in the future we can think about a way
to do this automatically by either re-applying MainConfigSchema
(sans db settings) or by only selectively applying LocalSettings.php
in the first place.

This patch follows-up I072ddf89562fe, which added a test case in
WikitextContentHandlerIntegrationTest.php that assumed "/index.php"
as the value of $wgScript. This passes in WMF CI since Quibble uses
that value, but the tests failed in most local development installs
since those tend to use "/w" instead.

Rather than one-off fixing that one test with overrideConfigValues(),
switch to a more general fixture, since the precise values don't
matter for this test.

Bug: T349087
Bug: T277470
Change-Id: If4304b7ca4a838bd892d4516a0b5c6dfbc30986e
2024-05-05 00:00:01 +00:00
Amir Sarabadani
214674d6b1 namespace MWDebug
Bug: T353458
Change-Id: I99d728bd111ff882220cd175ff09d4da20b81eae
2024-05-03 22:59:47 +02:00
jenkins-bot
b671e574eb Merge "Add ParserOptions::setCollapsibleSections()" 2024-04-29 21:17:15 +00:00
C. Scott Ananian
8d031bcf87 Add ParserOptions::setCollapsibleSections()
This is a non-default option that will add a <div> wrapper around
section contents to allow client-side collapsing.  This is intended
for use by MobileFrontEnd, but could eventually be enabled for
desktop read views as well.

Since this parser option is in the "cache-varying options" set, any
caller who sets this option will fork the cache for that page, which
is reasonable as the parser options sets a ParserOutput property.
In the future our caching strategy will get smarter and we'll add
code which avoids the cache split and just transfers the appropriate
values from ParserOptions to ParserOutput flags after the cached
output is retrieved.

Bug: T359001
Change-Id: Ie93959a056ed15a728404eb293e4bb6eeaeb15c0
2024-04-29 12:11:09 -04:00
Tim Starling
917f0a5996 Replace all instances of "per default" with "by default"
According to the dictionary, "per" (or more conventionally "as per")
means "according to". Refer OED "per" sense II.3.a. For example:

"No value was passed, so return null, as per default".

In this sentence, we are not specifying the default, we are referring
to the default. This correct usage of "per default" was used nowhere
in MediaWiki core as far as I can see.

Instead we have "per default" being used to mean "by default", that is,
giving the value to use when no explicit value was specified.

In OED, the phrase "by default" is blessed with its own section just
for computing usage:

"P.1.e. Computing. As an option or setting adopted automatically by a
computer program whenever an alternative is not specified by the user
or programmer. Cf. sense I.7a."

There are highly similar pre-computing usages of the same phrase,
whereas the phrase "per default" is not mentioned.

As a matter of style, I think "per default" should not be used even
when it is strictly correct, since the common incorrect usage makes it
ambiguous and misleading.

Change-Id: Ibcccc65ead864d082677b472b34ff32ff41c60ae
2024-04-29 10:47:54 +10:00
jenkins-bot
7586f61189 Merge "Mark ParserOptions suppressSectionEditLinks as safe to cache" 2024-04-26 04:23:13 +00:00
C. Scott Ananian
06f683b983 Mark ParserOptions suppressSectionEditLinks as safe to cache
This will split the cache for now, but pages are generally either
always rendered with suppressed edit links or always rendered without
suppressed edit links.  Previously, ParserCache would report the page
as "not safe to cache" and always bypass the cache when
suppressSectionEditLinks was set.  This isn't a problem since no one
uses this parser option yet in production, although the original
motivation was to replace the mutation of the $options array
done by the Translate extension in the ParserOutputPostCacheTransform
hook here:
  5eff51db88/src/PageTranslation/Hooks.php (197)

See 770d2bf040 for more information.

Change-Id: I88e33248c1e40a8aa694974b2a1f94e36d8c7ed6
2024-04-25 14:12:40 +00:00
C. Scott Ananian
195ac55bfe [ParserOutput] Remove deprecated ::getTOCHTML() and ::setTOCHTML() methods
These were deprecated with warnings in 1.40.

Change-Id: I8027bc26c71ae94d3d5c7e5112545cd1b35749aa
2024-04-16 13:00:58 -04:00
jenkins-bot
1caf41bb73 Merge "ParserOutput: Rename ::setIndexedPageProperty() to ::setNumericPageProperty()" 2024-04-16 10:57:58 +00:00
C. Scott Ananian
2429785470 ParserOutput: Rename ::setIndexedPageProperty() to ::setNumericPageProperty()
Before this method name gets baked forever into the 1.42 release, rename
the ParserOutput::setIndexedPageProperty() and ::setUnindexedPageProperty()
methods to ::setNumericPageProperty() and ::setUnsortedPageProperty() to
try to address some confusion about whether the *presence* of the page
property is still indexed (it is!), in contrast to whether there's an
additional "sort key" associated with the *value* assigned to the page
property.

This naming is compatible with the feature request in T357783 to have
the sort key and property value specified independently.  The new
method signature in that case would be:

  ...setSortedPageProperty( string $name, string $value, int|float $sortKey )

Although PHP 8.0 will throw a TypeError if a non-numeric type is coerced
to numeric using `0 + ...`, use an explicit is_numeric check to obtain
the same behavior in PHP 7.x.

Change-Id: Ia94c192c429d0482c58467bed787fd2e0aca052f
2024-04-15 15:13:56 -04:00
jenkins-bot
bd6b83c25f Merge "Parser::statelessFetchTemplate: remove dead code; add test cases" 2024-04-15 09:39:41 +00:00
C. Scott Ananian
4cc84cdafa Parser::statelessFetchTemplate: remove dead code; add test cases
Remove dead code left over from the removal of the
BeforeParserFetchTemplateAndtitle (sic) hook in
20c5632c4e.

While we're at it, add test cases for statelessFetchTemplate and
improve coverage.

Followup-To: Ifecd4108eb02ebccc0c7bc4ec432036da08ffe53
Followup-To: Idf1fd12cc61ca30867dc9f8aeb1701fe035fc5ff
Change-Id: I135f5234e7be015a2781d6cb8d23b3143b618c5a
2024-04-10 17:36:04 -04:00
C. Scott Ananian
de57c4e7c2 Add ParserOutput::setIndexedPageProperty(); deprecate numeric properties
Deprecate non-string values to ::setPageProperty(), which introduce easy
traps for programmers to fall into.  Instead if page properties are intended
to be indexed, use the new ::setIndexedPageProperty() instead.  Also add
::setUnindexedPageProperty() for symmetry, with a tighter string type on
the value.

Bug: T305158
Bug: T350224
Change-Id: I8a39a7c90341dfee932aa819c9a0a637a8782f69
2024-04-05 19:12:29 -04:00
Derick Alangi
483321e601 parser: Remove explicit StatsdDataFactory backward-compat logic
This is a follow-up to: I0b683461212a357c7eb09ddec59c87539e323c65
and I40a8372a76f33c5f62ea73bb1180dd7c47412c89 which explicitly for
backward compatibility reasons supports IBufferingStatsdDataFactory.

Now that we've fully switched to StatsFactory together with the
`copyToStatsdAt()` method, we're fine to fully remove this `instanceof`
logic.

Bug: T356815
Change-Id: I164d82904b6d3fb575cb973c14f9454569bf09ac
2024-03-26 22:53:58 +00:00
Bartosz Dziewoński
0d99a1c445 HandleSectionLinks: Remove old debug logging for resolved bug
This is just a cleanup change. The exception should never happen,
but if it does, this can be reverted.

Change-Id: I26a7c4105d39d83015c09b779a2de3fd1ddacec1
2024-03-07 23:09:25 +01:00
Umherirrender
a5cc068e40 tests: Avoid php warnings about deprecation from data providers
Call the suppression function in the data provider as that function is
called there. Also escape \ for the P to avoid \P

PHP Deprecated:  CacheTime::setCacheTime called with -1 as an argument
[Called from
MediaWiki\Tests\Parser\ParserOutputTest::provideMergeInternalMetaDataFrom
in /workspace/src/tests/phpunit/includes/parser/ParserOutputTest.php at
line 1028] in /workspace/src/includes/debug/MWDebug.php on line 379
PHP Warning:  preg_match(): Compilation failed: unknown property after
\P or \p at offset 19 in /workspace/src/includes/debug/MWDebug.php on
line 370
PHP Deprecated:  Use of MediaWiki\Parser\ParserOutput::setTOCHTML was
deprecated in MediaWiki 1.40. [Called from
MediaWiki\Tests\Parser\ParserCacheSerializationTestCases::getParserOutputTestCases
in /workspace/src/tests/phpunit/includes/parser/ParserCacheSerializationTestCases.php
at line 236] in /workspace/src/includes/debug/MWDebug.php on line 379

Bug: T355952
Follow-Up: Ifed584aac7947c47fd494a66564a3bd367f83c49
Change-Id: I7d6075b2c2b3d53db47e37040394bd013cece8a6
2024-02-25 15:55:30 +00:00
jenkins-bot
a62f5c7911 Merge "[ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()" 2024-02-21 17:11:00 +00:00
C. Scott Ananian
72c4945a72 [ParserOutput] Rename $mText to $mRawText and ::setText() to ::setRawText()
ParserOutput::getText() is not a simple getter, but does
transformations on the "text" of the ParserOutput; the simple getter
is named ::getRawText().

To maintain consistency, rename ParserOutput::setText() to
::setRawText() and the property name ParserOutput::$mText to
::$mRawText so future readers are not confused.

The JSON property name as it appears in the serialized ParserCache
is left as 'Text' so that we don't have any forward- or backward-
rollback issues.

Change-Id: I3ef34814ab9473cc70d0a6806e8c5a4a02b73491
2024-02-20 17:13:28 +00:00
Reedy
8771b338e4 tests: Namespace more parser classes
Change-Id: I35d6e3181ed885b8731ff1c4b5703459fb4223e4
2024-02-17 00:38:31 +00:00
jenkins-bot
f3389a38be Merge "ParserCacheSerializationTestCases: Fix MWDebug::filterDeprecationForTest call for setTOCHTML" 2024-02-16 23:25:23 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
Reedy
23d22307a1 ParserCacheSerializationTestCases: Fix MWDebug::filterDeprecationForTest call for setTOCHTML
Bug: T355952
Follows-Up: I3d8e2beaf68dc55b93297b23e450c3bc89c5b222
Change-Id: Ifed584aac7947c47fd494a66564a3bd367f83c49
2024-02-16 20:33:35 +00:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
C. Scott Ananian
770d2bf040 [ParserOutput] Make 'enableSectionEditLinks' a ParserOption
This will allow the Translate extension to set this parser option
in the ArticleParserOptions hook, instead of mutating $options passed
to ParserOutput::getText() in the ParserOutputPostCacheTransform hook.

It ought to also help to handle the many places which call:

   ... = $parserOutput->getText( [
       'enableSectionEditLinks' => false,
   ] );

by allowing them to set the appropriate ParserOption instead
of passing arguments to ::getText().

Bug: T350626
Change-Id: I719c115194059060f7f888608417a194ac80cc92
2024-02-09 23:42:03 +00:00
jenkins-bot
e831aa9c8b Merge "Namespace includes/context" 2024-02-08 18:04:34 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
C. Scott Ananian
242c6d2cf9 Introduce ParserOutput:setFromParserOptions() and use for preview flag
Bug: T341010
Co-Authored-by: cananian <cananian@wikimedia.org>
Co-Authored-by: ihurbain <ihurbainpalatin@wikimedia.org>
Change-Id: I03125fdaa7dd71ba57d593e85ecb98be6806f3f6
2024-02-07 21:22:06 -05:00
C. Scott Ananian
1858e1cdd7 Rename ParserOutput::{get,set}Timestamp() to ::{get,set}RevisionTimestamp()
This avoids confusion with the "render timestamp" held by the cache,
and is consistent with ::get*RevisionId() etc.

The old ::getTimestamp() and ::setTimestamp() methods have been
deprecated.

Change-Id: Idb5e687709c98086c5d3075d31885c58a0723197
2024-02-07 21:22:06 -05:00