Commit graph

363 commits

Author SHA1 Message Date
WMDE-Fisch
ad10a5c5f0 PaserTestRunner: Avoid json_decode deprecation warning
json_decode now emits a deprecation warning when called with null.
Before it would just return null anyway in these cases so I just
introduced a way around that avoids calling the mehod in the frist
place.

Bug: T382590
Change-Id: I47b7aca331a405bb3d2865cc280ef3ced537f84b
(cherry picked from commit b2fad75337256aaabd6e892bdd4bea8f86b47d5c)
2024-12-26 23:49:11 +00:00
Reedy
7a1f0dff6d tests: Use namespaced ParserOptions
Change-Id: Id7b04b61d22ab6ef8980897f1f2e2eb3eee4e619
2024-10-16 01:35:06 +01:00
jenkins-bot
26a696ecdd Merge "ParserTestRunner: consistent normalization of "known failure" output" 2024-10-11 22:12:54 +00:00
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
C. Scott Ananian
1c3078b96c ParserTestRunner: consistent normalization of "known failure" output
Improve the output when a parser test fails because the "known failure"
output differs from the actual output, and use the same normalization
function which Parsoid's test runner does for this comparison.

Previously it would display the actual/expected output from the test,
which had no relationship to the "real" reason the test was failing.

Depends-On: I7ff5b27415d98e45d1364161ed6cdaac2d156a81
Change-Id: I0d56b60abb78e37d539267f744afb52c092cb997
2024-10-08 17:59:21 -04:00
James D. Forrester
9203493606 Add namespace to remaining parts of Wikimedia\FileBackend
Bug: T353458
Change-Id: I49c843c9d8f6459c0fbf774afeea7a82fa564b59
2024-10-03 16:21:22 +00:00
James D. Forrester
9e5c1e8ac7 Add namespace to IDBAccessObject and DBAccessObjectUtils
Bug: T353458
Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
2024-09-27 16:19:10 -04:00
C. Scott Ananian
25da911334 Parser tests: add additional options to test ParserOutput metadata
New options added: `iwl`, `links`, `special`, `extlinks`, and `templates`,
and handling of existing `ill` option tweaked to be consistent.

Added some tests to exercise these options, focusing on the handling
of title fragments.  Attempted to make the output formatting consistent
among options; a future unification (I32df68714ffdf2f0745b974f47bc3ccceef1f41c)
should help DRY these out further.

Bug: T310512
Change-Id: Ic9c766ae4362969de124ad9d66eb47cfa68395c6
2024-09-13 14:42:27 -04: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
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
jenkins-bot
512c78b8ea Merge "Make {{#language}} consistent with {{#dir}} and {{#bcp47}}" 2024-07-31 11:42:16 +00:00
C. Scott Ananian
450fe7fcd8 Make {{#language}} consistent with {{#dir}} and {{#bcp47}}
Add the same no-arg options for language code that
{{#dir}} and {{#bcp47}} have, for consistency:
* `{{#language}}` will return the name of the *target language*
  (for articles, the content language; for messages, the user language)

The default value for the "in language" argument should be the autonym.
This was working previously but only via a baroque code flow path for
invalid language codes.  Make this a bit clearer and add tests.

Since non-autonym language code translations are added via the
[[Extension:CLDR]] in production, hook LanguageGetTranslatedLanguageNames
in the ParserTestRunner to ensure that we can test this.

Followup-To: Ice1c671c5b3cc077d2bb80ea5dc25c5eabbfeb36
Followup-To: I19c3e91a924e080f37dc95a0d4e61493583b533e
Change-Id: Ibf6e7f194cc056eadb48a5ad8e6d01a761d9351c
2024-07-30 20:27:17 +00:00
Tim Starling
ebf3c9be86 ParserTestRunner: add timezone and user language options
* Add wgLocaltimezone to the list of global variables which may be set
  in parser test options.
* Add userLanguage option, which is passed through to ParserOptions.

Bug: T223772
Change-Id: I8498527c276288feae854868a8f4b1f3205a49e8
2024-07-12 11:35:33 +10:00
Ebrahim Byagowi
d21cc67450 Add namespace and deprecation alias to FileBackend
This patch introduces a namespace declaration for the
Wikimedia\FileBackend to FileBackend and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Id897687b1d679fd7d179e3a32e617aae10ebff33
2024-05-19 22:35:58 +03:30
Ebrahim Byagowi
a717db8e60 Add namespace and deprecation alias to FormatJson
This patch introduces a namespace declaration for the
MediaWiki\Json to FormatJson and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5e1311e4eb7a878a7db319b725ae262f40671c32
2024-05-16 16:28:01 +03:30
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
Arlo Breault
3c9b410e17 Add a file to the ParserTestRunner
Bug: T363520
Change-Id: I0d5b577d19f98d4fc6f22930c9199a24fc459b9a
2024-04-25 23:47:54 -04:00
C. Scott Ananian
c2df535b9c Substitute category default sort key when filling links table, not at parse time
This ensures uniform treatment of all places that call `addCategory`
without duplicating the `defaultsort` code; it also ensures that the
effect of the {{DEFAULTSORT}} parser function is independent of page
position.

Bug: T40435
Bug: T353530
Change-Id: I4480a6d59e766fa4eddc9ec9117c58b66771bb47
2024-03-29 18:30:02 -04:00
Daimona Eaytoy
3a2f16d3f1 parsertests: Misc cleanup
Change-Id: Id1b073d80e896a26493206141bddfcf65c171d0b
2024-03-15 00:34:23 +00:00
Derick Alangi
b06f079e2b
ParserTestRunner: Remove parser test caching setup code
As of today, MediaWikiIntegrationTestCase together with TestSetup
already do the correct thing by setting up tests with appropriate
caching backends with HashBagOStuff so this hack is no longer needed.

Change-Id: I7a02ffb1bd7807901fe5d515b6a158865e8e83ea
2024-03-14 21:06:44 +03:00
Arlo Breault
5fc737eb91 Support "showmedia" parsertests option
Bug: T358158
Change-Id: I2db79f9a4658e6cb638ccf2716bd6c3d9917a3cc
2024-02-22 15:38:29 -05:00
C. Scott Ananian
cf5aabc42f ParserTestRunner: add [[pmid:]] interwiki prefix
This supports writing tests for the behavior requested in
T145590#8608455 whereby magic links are preferentially serialized
as interwiki links.

Bug: T145590
Change-Id: I2db78bdba6a32fbc2ef625e8c4a34091455bc234
2024-02-17 01:58:04 +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
jenkins-bot
3ab381ec90 Merge "ParserTestRunner: clean up ::addArticles()" 2024-02-13 00:09:04 +00:00
jenkins-bot
1c058326af Merge "ParserTestRunner: Fix behavior of bare parsoid-compatible file option" 2024-02-12 23:46:12 +00:00
C. Scott Ananian
11b3ea2f6a ParserTestRunner: clean up ::addArticles()
Properly chain teardown objects.

Change-Id: Ie07a4db476216eafeff82dee05b36519a35feb60
2024-02-12 10:51:21 -05:00
C. Scott Ananian
c705f1b9d7 ParserTestRunner: Fix behavior of bare parsoid-compatible file option
The intent was that a `parsoid-compatible` flag without specified modes
would enable all of the parsoid modes.  However, the value of
`$fileOptions['parsoid-compatible']` in that case is '', and the
test was looking specifically for a null or false value, not a falsey
one.

This exposed a bug where, because the LinkCache was destroyed and reset,
the calls to Title::clearCaches() didn't have the expected effect, since
the LinkCache held by Title was different from the one held by the
PageStore.  This caused the wrong page IDs to be associated with titles,
which then in turn caused the Disambiguator extension (which looks up
page properties by page id) to return the wrong results.

Depends-On: Ib65dd0adb472da53823c07af5991a140374501e4
Depends-On: Id9d6b3ab9d168048f46b1ab8783d06a7cbc9e6d4
Change-Id: Ifca13393c3bbec27c23cbdc311d4550fbccf21ca
2024-02-12 10:44:59 -05:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Atieno
b531666770 Remove indirect calls to IDBAccessObject::READ_* constants
We are getting rid of the schema of implementing this interface and
calling self::READ_* constants, it's confusing, inconsistent, prone to
clashes and isn't really useful for non-ORM systems (which we are not)

Bug: T354194
Change-Id: I4c722807b27db4e59f5ba3acc3ddb57fca9140b1
2024-01-29 21:00:03 +03:00
jenkins-bot
368d3f22a4 Merge "Don't use Parsoid\Config\PageConfig::getTitle()" 2024-01-27 00:54:03 +00:00
C. Scott Ananian
5d1c43cdb4 Don't use Parsoid\Config\PageConfig::getTitle()
This has been replaced by ::getLinkTarget(), which returns a Parsoid
LinkTarget.  This is identical to the core LinkTarget interface, but
we can't quite alias them for technical reasons (sigh).  In actual
practice, LinkTargets generated by core are usually Title objects, so
Title::newFromLinkTarget() is a no-op that just returns the argument
after a type check.

It appears that newer code uses a TitleFormatter rather than calling
methods on Title, but TitleFormatter currently takes LinkTarget not a
ParsoidLinkTarget.  That would force us to go via
TitleValue::newFromLinkTarget() which isn't a simple type check.

Change-Id: I490bb38108d0202b43ea2a9b391b2e664e7d2d48
2024-01-26 19:29:14 -05:00
jenkins-bot
855c7b5913 Merge "ParserTestRunner: Skip selser-auto-composite if Parsoid HTML is missing" 2024-01-26 21:49:07 +00:00
jenkins-bot
fa6a87bb57 Merge "ParserTestRunner: Bug fix that skipped selser tests in CI" 2024-01-26 21:47:28 +00:00
Subramanya Sastry
86905c0973 ParserTestRunner: Skip selser-auto-composite if Parsoid HTML is missing
* This matches the preamble in selserAutoEdit().
* Without this fix, PHPUnit was running selser tests on a Cite test
  that didn't have a parsoid/html section.

Change-Id: I7fb86778cfb674ecc76f748786fa08d8f6ac9c65
2024-01-26 15:15:10 -06:00
Subramanya Sastry
5e04b08a3b ParserTestRunner: Bug fix that skipped selser tests in CI
This only impacts PHPUnit testing (not the CLI test runner)
since we init numchanges to 0 because PHPUnit cannot run dynamic
tests. We instead install a single selser-auto-composite test
which then runs *all* selser auto-edit tests in a single run.

This bug affected that run since the reset to 20 failed with the
use of "??" instead of "?:"

Change-Id: Id81e2f4331ce73145389e717b7c78f49b29743bf
2024-01-26 15:15:10 -06:00
jenkins-bot
23d0c5a015 Merge "ParserTestRunner: HACK: Prevent crashers if no selser tests are run" 2024-01-25 23:55:31 +00:00
jenkins-bot
1a66246e19 Merge "Use native str_contains/str_starts_with in a few more places" 2024-01-25 16:27:36 +00:00
Subramanya Sastry
d24c29e8c3 ParserTestRunner: HACK: Prevent crashers if no selser tests are run
* If no selser tests are run, $test->changetree will be null
  because none is generated. However, Test::testAllModes will
  look to halt selser test run if it runs into a duplicate change
  tree for which it expects a non-null tree to be set. Without
  a change tree on the test, the test runner crashes (as is happening
  with a Cite test).

* One option is to change Test::testAllModes to bail if it runs
  into null. But, that can potentially hide bugs if change tree
  is null when it shouldn't have been.

* Ideally, we would change how testAllModes handles this by passing
  the ParserTestResult (which requires us to move ParserTestResult
  into the Parsoid repo) and checking if the test was skipped and
  not doing any duplicate test check if the test was skipped.

  That is going to require changing test runner code in Parosid
  and also coordinate across train deploys and I'll look into
  that separately.

  This is a short term fix to let us unblock running CI on Cite.

Change-Id: I093aeed933fe5927e031c879d48e0191e8ef4685
2024-01-25 10:13:22 -06:00
thiemowmde
4e7c3ca094 Use native str_contains/str_starts_with in a few more places
This makes the code quit a bit more readable, I believe.

strpos is especially confusing because it can return false when a
string doesn't contain the needle, as well as 0 when the string
starts with the needle. This is sometimes used as a feature (i.e. to
check if a string contains the needle, but doesn't start with it),
but that's not the case here.

A slightly more complicated change is made in TitleTest. But this is
only in a test and should verify itself when the test still succeeds.

Change-Id: I355ad1dc8e1725ae7a1eb652ec047ce7ff589cdf
2024-01-25 12:17:27 +01:00
thiemowmde
373f02e8f7 Improve type documentation in parser test runner classes
Mostly unspecific "array" type hints that can be made more specific.

Change-Id: I5ceb042d0a8740867ae7e5718dfed1f4b632596f
2024-01-20 20:24:35 +01:00
Isabelle Hurbain-Palatin
7f63d5250e Revert "Use Remex for DeduplicateStyles transform"
This reverts commit 82da9cf14b.

Passing through Remex seems to have unexpected consequences to be
investigated but, for the sake of unbreaking the UBN, let's revert this
first.

Bug: T353920
Change-Id: Iaac7942aa77aee5ab525852ac5b41dd516ff13c9
2023-12-22 11:26:09 +01:00
C. Scott Ananian
82da9cf14b Use Remex for DeduplicateStyles transform
The previous implementation was using an ad-hoc regular expression which
was matching inside the data-mw attribute of Parsoid output, eg:

 <sup about="#mwt42" [...] typeof="mw:Extension/ref mw:Error" data-mw="{&quot;name&quot;:&quot;ref&quot;,&quot;attrs&quot;:{&quot;name&quot;:&quot;infobox_stats_ref_rail&quot;},&quot;body&quot;:{&quot;html&quot;:&quot;<style data-mw-deduplicate=\&quot;TemplateStyles:r1133582631\&quot; typeof=\&quot;...">

After substitution, the <link> element inserted contained " instead of
&quot; and so broke out of the attribute.

Instead use a proper HTML tokenizer (via wikimedia/remex-html) so that
we don't allow bogus matches inside attribute values.

To fix up tests:
* Don't deduplicate styles when parsing UX messages (also helps performance)
* Don't deduplicate styles in ContentHandler integration tests
* Don't deduplicate styles by default in parser tests
  (unless explicit option is set)

Depends-On: Id9801a9ff540bd818a32bc6fa35c48a9cff12d3a
Depends-On: I5111f1fdb7140948b82113adbc774af286174ab3
Followup-To: Ic0b17e361bf6eb0e71c498abc17f5f67f82318f8
Change-Id: I32d3d1772243c3819e1e1486351d16871b6e21c4
2023-12-15 17:49:21 +01:00
James D. Forrester
9bfb75ff90 Namespace ParserOutput
Most used non-namespaced class!

Bug: T353458
Change-Id: I4c2cbb0a808b3881a4d6ca489eee5d8c8ebf26cf
2023-12-14 14:57:34 -05:00
C. Scott Ananian
00b5a968e9 [parser tests] Support htmlVariantLanguage option name
This replaces the previous `variant` name for this option to help avoid
confusion: Parsoid maintains both an 'html variant' and a 'wikitext variant'
and this helps us ensure we're all talking about the same thing.

Change-Id: I01b5eef72e8b4433510bc8cb9b684b1e37715821
2023-10-17 15:54:32 -04:00
C. Scott Ananian
d20663259f Hard-deprecate ParserOutput::getCategories(), deprecated in 1.40
It is difficult to distinguish this method from OutputPage::addJsConfigVars()
in code search:

   https://codesearch.wmcloud.org/deployed/?q=%5BOo%5Dut%28put%29%3F%28%5C%28%5C%29%29%3F-%3EgetCategories%5C%28&files=&excludeFiles=&repos=

We generally try to replace $output with $parserOutput or $pOutput
as we touch code to improve the ability of codesearch to dig up
deprecated ParserOutput methods.

Bug: T305161
Depends-On: I02dd4f61c43c225b0ef6dc51c3e4f9d967a0a272
Depends-On: I61d2d77591579d825ad9d37f902e40366be55dd6
Depends-On: I91155106b7a9e10d3334f95ba4936d02851bfb11
Depends-On: Iaca745c79d9587571af03b23b21d76a6cba0ebf1
Depends-On: Id10a171c44411b1233ee4d6cf8fbd3dc57744eef
Depends-On: I47a25c011d9bd4b1a15dda4e673e32c25eb64f2b
Depends-On: I683fc768aba50b801f46467fcfa1668fa8731ea6
Change-Id: I5a2ac1c99b8b199102e12f0d32dd6ec5cdc24054
2023-09-29 15:25:50 -04:00
jenkins-bot
346c408c3b Merge "ParserTestRunner: fix handling of multiple property/extension options" 2023-09-22 22:57:47 +00:00
James D. Forrester
1d0b7ae1e2 Namespace User under \MediaWiki\User
Bug: T166010
Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
2023-09-19 19:18:16 +00:00