Commit graph

356 commits

Author SHA1 Message Date
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
James D. Forrester
1b29886a32 build: Update mediawiki/mediawiki-codesniffer to 44.0.0
Change-Id: Ic83ac1282b1b0b414450aa69731a9efcc55db665
2024-08-11 13:08:16 +02:00
James D. Forrester
f7ce0a0976 Move remaining four classes in includes/content into Content namespace
Bug: T353458
Change-Id: Ia0f3e22078550be410c4b87faf6aa4eabe6e270d
2024-08-10 10:40:53 +02:00
James D. Forrester
6df7a51484 Drop MessageContent, deprecated since 1.38
Change-Id: Ib53d4a04e6faa82b0ea553221e6c0c827f36017a
2024-08-10 09:28:37 +02:00
jenkins-bot
365854bdad Merge "Made the JsonContent Responsive" 2024-08-08 20:50:51 +00:00
Anuj Agrawal
a3894b32da Made the JsonContent Responsive
Wrapped the HTML of JsonContent with a div and added a custom class to it. The class .noresize in mediawiki.content.json.less sets the overflow-x to auto and white-space to nowrap. This will make the JsonContent responsive with a horizontal scroll bar. Updated tests for the new behaviour of the JsonContent.

Bug: T366300
Change-Id: Ibf1494fa0940c37cf36ebfa18442d86c318dd1d1
2024-08-08 19:49:48 +05:30
Ebrahim Byagowi
c586a7207c Add namespace to ContentModelChange
It adds MediaWiki\Content namespace to ContentModelChange

Bug: T353458
Change-Id: Ia9fbff3b7d25a83be58fffbfc01274c9fcc7a482
2024-08-08 11:14:45 +02:00
Ebrahim Byagowi
35867f0e21 Add namespace to FileContentHandler
It adds MediaWiki\Content namespace to FileContentHandler

Change-Id: I2db36de12a60c78524ea6ee2d8866ff901a48cac
2024-08-07 09:34:01 +03:30
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
Timo Tijhof
64734f61ee content: Widen @covers tags in phpunit tests
https://gerrit.wikimedia.org/r/q/owner:Krinkle+is:merged+message:Widen

> Given all called methods are de-facto and liberally claimed, and
> that we keep the coverage limited to the subject class, it maintains
> the spirit and intent by listing the class explicitly instead.
>
> PHPUnit offers a more precise tool when you need it (i.e. when testing
> legacy monster/god classes), but for well-written code, the
> class-wide tag is exactly what you want.
>
> We lose useful coverage and waste valuable time on keeping tags
> accurate through refactors (or worse, forget to do so).
> Tracking tiny per-method details wastes time in realizing (and
> fixing) when people inevitably don't keep them in sync, and time
> lost in finding uncovered code to write tests to realize it was
> already covered but "not yet claimed".

While at it, also fix PHPUnit warnings in CssContentHandlerIntegrationTest
and JavaScriptContentHandlerIntegrationTest about not having any
`@covers` annotations.

Change-Id: I5afd9fe0bca0fa86cc096f6e5e79f2ba1cfbfa77
2024-07-21 21:03:10 +00:00
thiemowmde
bbc9b0785a content: Restore broken test coverage for TextContent::getNativeData
The getNativeData() method got deprecated and wasn't tested any more.
The test case was made identical to the existing test for getText().
This mistake happened in 2018, see Id2c61dc.

I suggest to re-arrange the existing test cases to make it much more
obvious what's happening here.

Change-Id: I022a7183b87402290898bee3458ef700009e1401
2024-07-21 17:14:58 +00:00
Daimona Eaytoy
6469955810 Replace User, Title, and WikiPage in more signatures
Change-Id: I04e408e734edc5498c32c4433f02da613bbfafa6
2024-07-10 01:25:57 +02:00
Timo Tijhof
faf4cb3384 content: Improve roundtrip tests for JavaScriptContent
* Re-use the same data provider explicitly instead of manually
  keeping them in sync.

* Add test case names as array keys to improve debugging.

* Widen `@covers` annotations in unit tests.

Bug: T107289
Change-Id: I9a321400855ddd1f56334f6ecf85590fd8ed4aaf
2024-07-05 19:28:14 +01:00
Isabelle Hurbain-Palatin
69b9733bce Use stripParsoidIds from Parsoid
Now that use Ib263439ae221232ffe0902a0c58d155402fb7a17 is merged,
we can use it instead of keeping it in ParsoidLocalizationTest.
It solves the issue pointed out in
I7da0823d4686238003579afe425a635541e9baf6.

Change-Id: I8744382dd24b28c623d0dc6569f800fb5489e6c1
2024-07-05 13:56:24 +02:00
Umherirrender
6c41df61e9 tests: Use namespaced classes (1)
Changes to the use statements done automatically via script
Addition of missing use statement done manually

Change-Id: Iae45fa269363be8ee05c598ea6926514ce817762
2024-06-14 17:19:36 +00:00
Ebrahim Byagowi
c556eda906 Add MediaWiki\Content namespace to FallbackContent{,Handler}
This adds MediaWiki\Content namespace to FallbackContent
and FallbackContentHandler and declares the unnamespaced version
as deprecated since version 1.43.

Bug: T353458
Change-Id: I3ee80aea379788b71539cc1c7a4ec216b753e042
2024-05-21 17:05:28 -04:00
Ebrahim Byagowi
656c7fac3b Add namespace and deprecation alias to JsonContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to JsonContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ia4ba6d3eddcb7b3f3d9f41a5ff80f724dbd01b22
2024-05-21 17:10:20 +03:30
Ebrahim Byagowi
848a9f279f Add namespace and deprecation alias to JsonContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JsonContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I44abb1ab5bd1fabf9886dc1457e241d7cae068bc
2024-05-20 18:57:07 +03:30
Ebrahim Byagowi
16197f7d76 Add namespace and deprecation alias to TextContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I2c72dacf28ee72fb70b15acdd81d0eb717ea949a
2024-05-20 05:34:31 +03:30
Ebrahim Byagowi
97d1202784 Add namespace and deprecation alias to TextContent
This patch introduces a namespace declaration for the
MediaWiki\Content to TextContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic251b1ddfcf6db9c85cb54cddf912aa827d2bc3a
2024-05-19 23:23:01 +03:30
Ebrahim Byagowi
8e5b26837b Add namespace and deprecation alias to CssContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to CssContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I5504c21b4fabd6ce82c4dac37aacd1c74462c41b
2024-05-19 17:01:54 +03:30
Ebrahim Byagowi
6316a253aa Add namespace and deprecation alias to CssContent
This patch introduces a namespace declaration for the
MediaWiki\Content to CssContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I6ab25787893cb2195f8cd2ba125ed8dd5a60de43
2024-05-18 01:48:53 +03:30
Ebrahim Byagowi
f0c5cd0d33 Add namespace and deprecation alias to JavaScriptContentHandler
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContentHandler and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: Ic30789d4e80a27004b6bc3b3ba891a7332a5e1ba
2024-05-17 15:06:40 +03:30
Ebrahim Byagowi
ccde5085de Add namespace and deprecation alias to JavaScriptContent
This patch introduces a namespace declaration for the
MediaWiki\Content to JavaScriptContent and establishes a class
alias marked as deprecated since version 1.43.

Bug: T353458
Change-Id: I87c17327911e28a461feaf2ff46242454cff257a
2024-05-17 13:51:18 +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
jenkins-bot
7934a84307 Merge "Add Parsoid HTML version to wrapper div" 2024-05-14 04:36:58 +00:00
C. Scott Ananian
5735f94648 Add Parsoid HTML version to wrapper div
Followup-To: I941d31479eebb12ea1f4dcdb0a1737033ddc8ac1
Depends-On: I95be56e3662f9cffd1eb5c03bbc0379d4e0a9ee0
Change-Id: I4aaa4b9e800271c2bcfc2fd74f09853b31ee6859
2024-05-06 15:56:02 -04:00
Isabelle Hurbain-Palatin
8de2e66ca7 Localization output transform
This is an output transform to resolve the mw:I18n and mw:LocalizedAttrs
to their localized forms.

Bug: T358191
Change-Id: Id32bc05ff72eb2d9fba7f8c2f192c9f7812cbc70
2024-05-06 15:24:38 -04:00
James D. Forrester
a5a10aff9b ContentHandler: Hard-deprecate deprecated methods
Depends-On: If0049aabff2dedfcecf739dbbcf688d16d9cc864
Depends-On: I7f82748be5a7c16525bc57e33ebeb0bb974267b9
Change-Id: Ife87b189e73883cfc8a4ef115d431ec8ad37dea7
2024-05-01 07:41:18 +01:00
daniel
67f047bb32 tests: Remove usage of deprecated methods on ContentHandler
Prepare for hard deprecation of static ContentHandler methods.

Change-Id: Ie37937da26630d4c9782f2ac4aa413e9c18ea535
2024-04-30 17:45:13 +01:00
jenkins-bot
b671e574eb Merge "Add ParserOptions::setCollapsibleSections()" 2024-04-29 21:17:15 +00:00
C. Scott Ananian
7738554eee [OutputTransform] Add data-mw-parsoid-version to wrapper div
Adding a data-mw-parsoid-version attribute to the wrapper div helps to
unambiguously mark parsoid-generated output in a way which is compatible
with CSS rules and client-side JavaScript.

By embedding the current version of parsoid in the data attribute,
sophisticated CSS rules can match against a specific version of
Parsoid in order to facilitate proper behavior; for example:

    div[data-mw-parsoid-version^="0.20.0"]

This could be useful in deployment scenarios where the parser cache
might contain content generated by older or newer versions of Parsoid,
for roll-forward or roll-back deployment scenarios, respectively.

Bug: T363378
Change-Id: I941d31479eebb12ea1f4dcdb0a1737033ddc8ac1
2024-04-29 12:36:50 -04: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
jenkins-bot
c6ae3b2ed0 Merge "tests: Refactor common code out of Parser used-options tests" 2024-04-26 04:23:21 +00:00
C. Scott Ananian
25f2bf0d34 tests: Refactor common code out of Parser used-options tests
Change-Id: I05e7da17d3ecaed111e545f09106a1f1ac9dd174
2024-04-25 14:13:08 +00:00
Taavi Väänänen
f28348d9c0
Hard-deprecate ContentHandler::getContentText()
No remaining uses in WMF-deployed extensions. (Although there is a
similarly named but separate function in CiteThisPage.)

Bug: T268041
Change-Id: Iec68845c631758fe85d32a939b28b6d8b1243858
2024-04-21 22:15:09 +03:00
jenkins-bot
cf35b37992 Merge "HtmlOutputRendererHelper: fall back to page language" 2024-03-13 15:57:24 +00:00
Timo Tijhof
3dad835561 content: Remove unclear assertEquals() on Status objects
We don't usually compare object serializations with assertEquals as
they tend to make it difficult to know what is and isn't being asserted,
giving the illusion that it checks "everything" but can in some cases
be closer to "too much" or "nothing".

Actual logic:
* https://github.com/sebastianbergmann/phpunit/blob/9.6.17/src/Framework/Assert.php#L330
* https://github.com/sebastianbergmann/phpunit/blob/9.6.17/src/Framework/Constraint/Equality/IsEqual.php
* https://github.com/sebastianbergmann/comparator/blob/5.0.1/src/ObjectComparator.php
* https://github.com/sebastianbergmann/exporter/blob/5.1.2/src/Exporter.php

This means sub classes or value objects are needlessly discarded,
as well as potentially irrelevant state in the object is becoming
part of the test.

It is not a surprise then, that these assertions are not comparing
against any particular desired outcome, but are literally a copy-paste
of the source code, including functions that have no effect in testing
such as `ContentHandler::getLocalizedName( 'testing' )` === 'testing',
and untested expressions like `$wikipage->getTitle()->getPrefixedText()`
instead of an explicit expectation.

Replace this with assertStatusError and limit the assertion to
being !isOK, and error using the specified interface message key.

Testing that the correct parameters are passed is imho not a part
of this test, since the test isn't actually validating it to be
correct or sensible in terms of message contents and parsed outcome,
it is only verifying that we have correctly copied the source, which
still needs the same review as it otherwise would.

Change-Id: I8c7a660489e9000f9790f8d69478a05ad8c446b6
2024-03-12 06:28:08 +00:00
daniel
e7f21f6e64 HtmlOutputRendererHelper: fall back to page language
HtmlOutputRendererHelper should not crash hard if the ParserOutput has
no language set. ParserOutput may come from a variety of places, we
should be lenient about it not having a language.

However, we should try harder to actually set a language on ParserOutput
if we have one available. So this also updates
PageBundleParserOutputConverter to keep the ParserOutput's language in
sync wit the language header in the PageBundle.

Bug: T349868
Bug: T353689
Bug: T359426
Change-Id: I2edf20dc3b199e22cda2f32bc858c21ca7d8f4bd
2024-03-06 17:18:16 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +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
b01eb624c4 [OutputTransform] Add section edit links to Parsoid output
Bug: T269630
Change-Id: I9d5fb6348609642ad94743cc5dae81ce608be99d
2024-02-15 13:09:02 -05:00
jenkins-bot
a31820649f Merge "test: Add PHPUnit tests for PreSaveTransformParamsValue" 2024-02-10 14:38:25 +00: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
Doğu Abaris
15360da7c6 test: Add PHPUnit tests for PreSaveTransformParamsValue
Covered:
- `testConstruct`: Validates property initialization.
- `testGetPage`: Tests correct PageReference return.
- `testGetUser`: Checks getUser() returns expected UserIdentity.
- `testGetParserOptions`: Validates ParserOptions retrieval.

Change-Id: Ic6e4fa00828a06267a382209478e14fbe066dea7
2024-02-09 22:35:42 +00:00
jenkins-bot
0c886022e4 Merge "WikiTextStructure: Support heading tags with attributes" 2024-02-09 16:24:28 +00:00
Bartosz Dziewoński
9fe361091b WikiTextStructure: Support heading tags with attributes
Change-Id: Ie68c7c695cb84ed6844d6d422284dca8c0c13072
2024-02-08 23:57:42 +01: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