Commit graph

115 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
Cole White
89a10817dc diff: migrate TextSlotDiffRenderer to use StatsFactory
Bug: T359241
Change-Id: I4f443b004b9ed77b9e6b8b1144d0cc2847a55d16
2024-06-28 19:29:31 +00:00
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
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
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
Máté Szabó
84ee098126 Fix ExternalTextDifferTest on macOS
In POSIX sh, `echo` flags are undefined. On macOS, this causes the
expected output to include literal `-n`s instead of the expected
behavior of not printing trailing newlines. So, use `printf` instead,
which should work consistently on both macOS and Linux.

Follows-up I5c506e3916285.

Change-Id: I54fc42d8fb8156fcf1d623ef4a7515092e634f09
2024-05-04 19:56:27 +00:00
Arthur Taylor
5ab72270e5 Make DifferenceEngineTest run standalone
When running in a CI / Quibble context, this test class was
failing - it relies on other classes in the suite already having
initialised OOUI.

Explicitly enable OOUI in this test to avoid the failure mode.

Bug: T363797
Change-Id: I63c65d32b32f6e47b2b1900e819b58b9bbfe30c3
2024-04-30 09:45:39 +02:00
Tim Starling
bd6ed0acdf Fix some spelling errors
Change-Id: I3632ce1ae00527f806652deb96cafb473aed3dcf
2024-03-18 20:58:11 +11:00
thiemowmde
0606238e15 Fix weird (auto-generated?) namespaces in PHPUnit tests
Same as I710a077.

Change-Id: I2b8eaf060229da3e0b5035fc43e38d610d554535
2024-02-20 19:23:36 +00:00
Reedy
85396a9c99 tests: Fix @covers and @coversDefaultClass to have leading \
Change-Id: I5629f91387f2ac453ee4341bfe4bba310bd52f03
2024-02-16 22:43:56 +00:00
James D. Forrester
4bae64d1c7 Namespace includes/context
Bug: T353458
Change-Id: I4dbef138fd0110c14c70214282519189d70c94fb
2024-02-08 11:07:01 -05:00
Umherirrender
388b0374fa tests: Use namespaced classes
Changes to the use statements done automatically via script
Addition of missing use statements and changes to docs done manually

Change-Id: Ib326ae1e5c8409a98398c721e8b8ce42c73bd012
2023-12-11 15:59:55 +01:00
Timo Tijhof
d0a96db0f9 parser: Move lang/dir and mw-content-ltr to ParserOutput::getText
== Skin::wrapHTML ==

Skin::wrapHTML no longer has to perform any guessing of the
ParserOutput language. Nor does it have to special wiki pages vs
special pages in this regard. Yay, code removal.

== ImagePage ==

On URLs like /wiki/File:Example.jpg, the main output handler is
ImagePage::view. This calls the parent Article::view to handle most of
its output. Article::view obtains the ParserOptions, and then fetches
ParserOutput, and then adds `<div class=mw-parser-output>` and its
metadata to OutputPage.

Before this change, ImagePage::view was creating a wrapper based
on "predicting" what language the ParserOutput will contain. It
couldn't call the new OutputPage::getContentLanguage or some
equivalent as Article::view wouldn't have populated that yet.

This leaky abstraction is fixed by this change as now the `<div>`
from ParserOutput no longer comes with a "please wrap it properly"
contract that Article subclasses couldn't possibly implement correctly
(it coudln't wrap it after the fact because Article::view writes to
OutputPage directly).

RECENT (T310445):

A special case was recently added for file pages about translated SVGs.
For those, we decide which language to use for the "fullMedia" thumb
atop the page. This was recently changed as part of T310445 from a
hardcoded $wgLanguageCode (site content lang) to new problematic
Title::getPageViewLanguage, which tries to guestimate the page
language of the rendered ParserOutput and then gets the preferred
variant for the current user. The motivation for this was to support
language variants but used Title::getPageViewLanguage as a kitchen
sink to achieve that minor side-effect. The only part of this
now-deprecated method that we actually need is
LanguageConverter::getPreferredVariant().

Test plan: Covered by ImagePageTest.

== Skin mainpage-title ==

RECENT (T331095, T298715):

A special case was added to Skin::getTemplateData that powers the
mainpage-title interface message feature. This is empty by default,
but when created via MediaWiki:mainpage-title allows interface admins
to replace the H1 with a custom and localised page heading.

A few months ago, in Ifc9f0a7174, Title::getPageViewLanguage was
applied here to support language variants. Replace with the same
fix as for ImagePage. Revert back to Message::inContentLanguage()
but refactor to inLanguage() via MediaWikiServices::getContentLanguage
so that LanguageConverter::getPreferredVariant can be applied.

== EditPage ==

This was doing similar "predicting" of the ParserOutput language to
create an empty preview placeholder for use by preview.js. Now that
ApiParse (via ParserOutput::getText) returns a usable element without
any secret "you magically know the right class, lang, and dir" contract,
this placeholder is no longer needed.

Test Plan:

* EditPage: Default preview
  1. index.php?title=Main_Page&action=edit
  2. Show preview
  3. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>

* EditPage: JS preview
  1. Preferences > Editing > Show preview without reload
  2. index.php?title=Main_Page&action=edit
  3. Show preview
  4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
  5. Type something and 'Show preview' again
  6. Assert old element gone, new text is shown, and new element
     attributes are the same as the above.

== McrUndoAction ==

Same as EditPage basically, but without the JS preview use case.

== DifferenceEngine ==

Test:

1. Open /w/index.php?title=Main_Page&diff=0
   (this shows the latest diff, can do manually by viewing
   /wiki/Main_Page, click "View history", click "Compare selected revisions")
2. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>
3. Open /w/index.php?title=Main_Page&diff=0&action=render
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>

== Special:ExpandTemplates ==

Test:

1. /wiki/Special:ExpandTemplates
2. Write "Hello".
3. "OK"
4. Assert <div class="mw-content-ltr mw-parser-output" lang=en dir=ltr>

Bug: T341244
Depends-On: Icd9c079f5896ee83d86b9c2699636dc81d25a14c
Depends-On: I4e7484b3b94f1cb6062e7cef9f20626b650bb4b1
Depends-On: I90b88f3b3a3bbeba4f48d118f92f54864997e105
Change-Id: Ib130a055e46764544af0f1a46d2bc2b3a7ee85b7
2023-11-03 19:24:47 -04:00
MusikAnimal
02e7fdb26a diffs: add line number headings to inline diffs
Adds new regex in BaseTextDiffer::localizeLineNumbers() to work with
wikidiff2 inline diffs as well as table diffs.

Since there are no "columns" in inline mode, we have a new message to
indicate how the line numbers changed from the old diff versus the new.

Deprecate DifferenceEngine::localiseLineNumbers() as no longer used and
redundant to BaseTextDiffer::localizeLineNumbers().

Bug: T346460
Change-Id: I7b195879b677e2242ad73070fe19ad82121576a8
2023-10-09 22:53:14 -04:00
thiemowmde
46bed8ac6d Make use of assertStatusGood/Error and such in tests
Change-Id: I11eace3d9823ca28a1d9a64f959f5f8ca2945821
2023-10-04 17:16:00 +00:00
James D. Forrester
c1599c91b3 Namespace Config-related classes under \MediaWiki\Config
Bug: T166010
Change-Id: I4066885a7ea071d22497abcdb3f95e73e154d08c
2023-09-21 05:41:58 +00:00
TheresNoTime
b20ea3a54f DiffToggleSwitch: remove temporary inline switch flag
Remove `$wgShowDiffToggleSwitch`, ensure the inline switcher
is always shown.

Bug: T341630
Change-Id: I37d1abe0d9773654df24dd8316cd1b351e3b91a4
2023-09-06 20:13:00 +00:00
Amir Sarabadani
d8e542abf9 Reorg: Move three output related classes to includes/Output/
And namesapce them:
 - StreamFile
 - OutputHandler
 - OutputPage

Bug: T321882
Change-Id: Iedf8d88c595e580f2d8f0734c92aa5c45618ba33
2023-09-05 19:36:42 +01:00
Tim Starling
7887b66ade Include $wgWikidiff2Options in the diff cache key
Bug: T341754
Change-Id: I3b7d71f811d7ebd0cf83273164c479762e1a680b
2023-08-23 10:00:47 +10:00
jenkins-bot
1d5e4f3d0a Merge "Add support for wikidiff2_multi_format_diff()" 2023-07-31 11:54:12 +00:00
Tim Starling
8d69f99a1a Don't show the inline toggle selector on Special:MobileDiff
Have Article opt in to inline toggle switch display, so that random
callers of DifferenceEngine::showDiffPage() do not receive a
non-functional format selector.

Bug: T342158
Change-Id: Id4e38c2a20b5381e5f70b1244304da2895eaf8e7
2023-07-26 05:16:55 +00:00
Umherirrender
3010fd8157 tests: Skip ManifoldTextDifferTest on windows
Fails with a
1) ManifoldTextDifferTest::testHasFormatExternal
ExternalDiffEngine config points to a non-executable

Change-Id: Ifb32694f2c1cef32a354e20636463a22b7ab5f6f
2023-07-22 21:59:41 +02:00
Tim Starling
4014f56d73 Add SlotDiffRenderer::localizeDiff()
It makes sense for SlotDiffRenderer to localize the diffs that it
returns.

DifferenceEngine can't conveniently use this right now since it stores
all slot diffs concatenated together in a cache entry. It can't break
the string apart again to call the right SlotDiffRenderer on each
slot diff. So it assumes there must be a text diff in there somewhere
and calls TextDiffer over the whole thing.

EntitySchema does not have this problem and can benefit from this
method.

Bug: T342209
Change-Id: Ie06e100bb0e945de5dbe3dade14b2e6b706e078d
2023-07-20 10:09:42 +10:00
Tim Starling
2ed4e600b4 Add support for wikidiff2_multi_format_diff()
Bug: T341754
Change-Id: I17396985d0b26516a06df17e9bd1343054521e01
2023-07-19 12:38:18 +10:00
Tim Starling
191ec35340 Add unified format
The code is there, so we may as well expose it.

Change-Id: Ic4cf5c0d4a5b46f0f0f25454815dcea1f69970eb
2023-07-19 12:38:18 +10:00
Tim Starling
2aa87cdf2c Factor out TextDiffer hierarchy from TextSlotDiffRenderer
* Follow the TODO comment in TextSlotDiffRenderer
  ::getTextDiffInternal() by moving the code out to three parallel
  implementations, namely ExternalTextDiffer, PhpTextDiffer and
  Wikidiff2TextDiffer.
* Add a container/factory class ManifoldTextDiffer to glue them
  together and collate available formats.
* Move the inline legend to Wikidiff2TextDiffer. Not the toggle since
  the ability to toggle depends on the available format, not the current
  format.
* Update the diff cache keys so that ManifoldTextDiffer can store the
  engine=>format map it used to generate the diff.
* Drop support for the second parameter to TextSlotDiffRenderer
 ::setEngine(), since nothing used it anymore.
* Provide a format batch API, since some engines are able to efficiently
  generate multiple formats. This might be used by DifferenceEngine in
  future.

Needs risky change notification for the cache key change.

Bug: T339184
Depends-On: I8a35b9b8ec1622c9a36d2496bdd24f51bc52c85f
Change-Id: I5c506e39162855aff53dd420dd8145156739059c
2023-07-19 12:38:18 +10:00
jenkins-bot
ea6e237948 Merge "Add a test for DifferenceEngine::showDiffPage" 2023-06-27 03:14:29 +00:00
Tim Starling
38f760268c Add a test for DifferenceEngine::showDiffPage
An integration test that checks for a regex match on the HTML output.
Achieves 92% coverage of showDiffPage.

Change-Id: I3b2af33257f2326b67ff6f0734aeff0da3b69f43
2023-06-27 12:17:06 +10:00
Sam Wilson
ae46eb63d5 Switch back to oo-ui-element-hidden from mw-diff-element-hidden
Using the OOUI class name is an established pattern outside of
OOUI widgets, so it's easier to stick with it for the diff page
hiding and showing (switching to and from inline/table diffs, etc.).

Bug: T324759
Change-Id: I805b6b71d8e137eaa3e000b15455557df42af838
2023-06-26 19:14:41 +08:00
jenkins-bot
7b7f1181d3 Merge "diff: Move SlotDiffRenderer::getTablePrefix() parts assembly up to DifferenceEngine" 2023-06-26 03:13:42 +00:00
Tim Starling
8983c9d862 diff: Move SlotDiffRenderer::getTablePrefix() parts assembly up to DifferenceEngine
getTablePrefix() is used to show the inline legend and inline switcher.
It is not yet part of a released stable interface.

Theoretically there may be multiple text slots on a page, and we don't
want multiple inline legends. There was already a fragment assembly
system, for the benefit of hook handlers, so move that up to the page
level, so that it can also deduplicate prefix fragments coming from
each slot.

Add tests.

Bug: T324759
Change-Id: I9baa5c24128c63bc318ba13e83a024843f4ab15e
2023-06-26 11:28:59 +10:00
Gergő Tisza
a9e0562cfb Improve handling of diffs between incompatible content models
When the old and new content object for a slot cannot be compared,
show an error message for that slot only, instead of throwing an
exception.

Bug: T214217
Change-Id: I6e982df358f85ca78f0448b3a93ded3f40676310
2023-06-23 19:09:59 +00:00
Tim Starling
2e4880e52a DifferenceEngineTest: improve data providers
* Have data providers return plain data instead of objects.
* Use addDBDataOnce() instead of a DIY equivalent.
* Use a data provider instead of a loop in testMapDiffPrevNext and
  testLoadRevisionData. Resolve the problem of the provided data
  depending on auto-increment IDs from addDBDataOnce by using special
  strings that are replaced with IDs in the test case.

Bug: T332865
Change-Id: Ie41f3222aa1b48c69dbfe4cd7f6ef84e394e31fa
2023-06-22 11:49:49 +10:00
jenkins-bot
bdb701a634 Merge "Move DiffEngine and helpers to includes/libs/Diff and put them in a namespace" 2023-06-20 19:03:46 +00:00
Tim Starling
359ce91a12 Move DiffEngine and helpers to includes/libs/Diff and put them in a namespace
I will address the dependencies on MW core in a followup.

Bug: T339184
Change-Id: I892364b0c9f15c9de4cfc29c683670c172d71764
2023-06-20 15:15:13 +10:00
Umherirrender
580439e604 tests: Use MainConfigNames consts to refer config names
PasswordSalt was dropped in 2e909bcb

Change-Id: I58d2b8d4e2a235afdc8054eafdea4e85b61f03c1
2023-06-19 20:21:08 +00:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00:00
libraryupgrader
7375f3a5fe build: Updating mediawiki/mediawiki-codesniffer to 41.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Usage.ForbiddenFunctions.eval

Change-Id: I6fd0a9296c88a77c3abec6e5e8d568bb469c2d6e
2023-03-11 19:04:09 +00:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Umherirrender
82466b0594 diff: Handle timestamp correct for suppressed revisions
- No linking when the user cannot see the suppressed revision
- Double-strike the timestamp (b6f148b)

Bug: T325450
Change-Id: If94e9655d72e59a2b9d5147c5c2338e98f0ad163
2022-12-17 23:17:16 +01:00
Umherirrender
48bde498db tests: Add tests for DifferenceEngine::getRevisionHeader
Test all situation with or without revision deletion

Change-Id: I9b490cb764853a85d4a0ab64b4c3118c34f71335
2022-12-17 23:15:28 +01:00
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
daniel
166b569444 Make use of the new PageUpdateStatus
PageUpdateStatus provides clean access the the newly created
RevisionRecord.

Depends-On: Ia08c586198082ea47e8313d0d41835f9830fb29e
Change-Id: Id6963842321c4eaa3d7d029ad0b769f73433c103
2022-11-30 17:56:58 +00:00
Umherirrender
f1db4bed17 tests: Use MediaWikiIntegrationTestCase::editPage for edits
Change-Id: I1db7294635bb85e03841c4f7b100e2243ddf013b
2022-09-23 22:49:59 +02:00
Derick Alangi
6e5f2d0822 tests: Migrate setMwGlobals() to overrideConfigValue(s)()
Directories covered are:
- tests/phpunit/includes/cache/
- tests/phpunit/includes/changes/
- tests/phpunit/includes/changetags/
- tests/phpunit/includes/config/
- tests/phpunit/includes/content/
- tests/phpunit/includes/debug/
- tests/phpunit/includes/deferred/
- tests/phpunit/includes/diff/

Change-Id: I3a1f586867db7d57b177e13a03a4593f7eed09f4
2022-07-23 05:53:49 +01:00
Thiemo Kreuz
61ae7504df Replace trivial usa of mock builder with createMock() shortcut
createMock() does the same, but is much easier to read.

A small difference is that some of the replacements made in this
patch didn't use disableOriginalConstructor() before. In case this
was relevant we should see the respective test fail. If not we can
save some CPU cycles and skip these constructors.

Change-Id: Ib98fb06e0fe753b7a53cb087a47e1159515a8ad5
2022-07-15 16:43:48 +00:00
Umherirrender
047c184bfe tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ibfccfe696f0b8bfda0b99abae324e60bbecef7d8
2022-07-06 00:44:00 +02:00
jenkins-bot
c82ced1ba1 Merge "diff: Fix small issues and compact syntax in DifferenceEngine" 2022-02-04 15:09:28 +00:00
Thiemo Kreuz
32bbb421c7 diff: Fix small issues and compact syntax in DifferenceEngine
The purpose of all these changes is not only to make the code
shorter, but to make it more readable.

Notable:
* Fix wrong type hints.
* The `foreach ( $roles )` loop was processing everything twice.
* Inline preg_replace_callback() callbacks.

Change-Id: I2b8146946ab6966cc6f047556a0a898624af181a
2022-02-04 10:55:48 +01:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00