Commit graph

353 commits

Author SHA1 Message Date
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
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
C. Scott Ananian
55e1aa0144 ParserTestRunner: fix handling of multiple property/extension options
The parser test reader (imported from Parsoid) already converts
comma-separated lists to an array; we get an exception from explode()
if we then try to split that array by comma.

Change-Id: Id17ed22d81cc880f41f584406369323232c00bdf
2023-09-11 20:17:17 -04:00
Tim Starling
136b7133cc Reset the OOUI element ID before each test
Change-Id: I490d196250e578dae88f47b485fdf068e424a120
Depends-On: I8925e84b9f04c631a8b8dec6bd4fd7a9e848b239
Bug: T345515
2023-09-11 11:03:24 +00:00
Daimona Eaytoy
f83e611efa Make MediaWikiIntegrationTestCase::addCoreDBData a noop
The method should never be called directly, so make it throw an exception.
Nonetheless, mark it as deprecated and detect overrides in the
constructor, so that anyone who tries to override this method will see a
warning.

Fix the few tests that were relying on the existence of the test page.

Bug: T342428
Depends-On: Ic64ded5e2c0b59e7c888ece9566076058a125be4
Change-Id: I308617427309815062d54c14f3438cab31b08a73
2023-09-05 00:36:36 +00:00
Derick Alangi
228b603622
tests: Remove unused var in ParserTestRunner
Was introduced in I6c1e9bfad9790cf805809c28a3f8d45952cbb981 and
later rendered unused in Ie62250242965d3d90873909795ced2cbda506ddb.

Since we want to make sure we're using the right instance passed in
closures, let's keep getting it from the global service container
then keep locally in a variable.

Change-Id: I834b09933efc8835c73b9fafaad80cc7041757b6
2023-08-23 20:58:19 +01:00
Amir Sarabadani
15a278189f Reorg: Move MWTimestamp to MediaWiki\Utils
Bug: T321882
Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
2023-08-19 05:53:40 +02:00
jenkins-bot
43607fd156 Merge "language: Inject ParserFactory into MessageCache" 2023-08-16 15:59:05 +00:00
Umherirrender
59af14aef1 parsertests: Readd Title::clearCaches()
The interaction between the title cache, the link cache and the parser
tests is very strange. With different parser tests and different
extension enabled it can fail and seems not very deterministic

Follow-Up: Ie4b67106512fb1a3a1b595dc4f6036276db96378
Change-Id: I55501eea7de739cac044b22caec150089183620b
2023-08-06 13:10:37 +02:00
Umherirrender
b232dafd41 title: Uncache title from internal title cache on id reset
The instance in the title cache does not see the reset of the id (lazy
loaded Title::mArticleId). When a title instance with Title::newFromText
is used from cache the instance can assume the title does not exists,
while the page was created. Remove the cached instance to get a fresh
instance which can do a fresh db lookup for the id when needed.

This should remove the issues from the parser test
with wrong title states

Follow-Up: Id056580c7b869ae4984de5e2c89fb4687eecf7bd
Follow-Up: Ibc8e0ddbe9e53c3334b9c26ec2d1eda976c2a62b
Change-Id: Ie4b67106512fb1a3a1b595dc4f6036276db96378
2023-07-31 23:21:16 +00:00
Umherirrender
937ebeb585 language: Inject ParserFactory into MessageCache
Avoid clone of Parser object, create a new one

Reset the UrlUtils services after changing the server setting,
it is a dependency of the ParserFactory and gets initalizied earlier now

Bug: T250448
Change-Id: Ie62250242965d3d90873909795ced2cbda506ddb
2023-07-30 22:08:46 +02:00