Commit graph

515 commits

Author SHA1 Message Date
Lucas Werkmeister
1a3f15cd43 Restore DifferenceEngine::localiseLineNumbers()
Since it’s needed by EntitySchema, and because it was also, as far as I
can tell, removed without following the stable interface policy in
change I5c506e3916 (commit 2aa87cdf2c).

Not marked as soft-deprecated because there doesn’t seem to be a way to
access the replacement.

Bug: T342209
Change-Id: Iba9fd8bb56ea0e1543c9a9beab85b01f9549fbd7
2023-07-19 12:26:43 +02: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
Tim Starling
cbeceb1ae3 Slot diff option "contentLanguage" should be a string
Quick fix for production error.

Bug: T342099
Bug: T341961
Change-Id: Ifab76ab7018ee1498851223e1181b527d506efbb
2023-07-18 21:56:11 +10:00
Tim Starling
6790bf9910 Remove $wgLang usage from Title
StubUserLang was meant to avoid the cost of looking up the user
preferences on requests which don't need it. There's no point in using
it if you are going to unconditionally call a method on the resulting
object.

StubUserLang proxies to RequestContext::getLanguage() via __call(),
which has a cost. Originally this cost was avoided on subsequent calls
by overwriting $wgLang, but this mechanism is not effective if you retain
a reference to the StubUserLang.

Removing the potential for Title::getPageLanguage() to return
StubUserLang simplifies the type declarations for methods that call it.

Bug: T160814
Change-Id: I12ad75c2496ca727580aac55e860178d15febb6e
2023-07-11 11:15:02 +10:00
jenkins-bot
e7373e24e3 Merge "Inject page language into TextSlotDiffRenderer" 2023-07-07 01:37:43 +00:00
jenkins-bot
2b68525941 Merge "Add DifferenceEngine::getDefaultLanguage()" 2023-07-06 09:31:09 +00:00
Tim Starling
36b92d45db Inject page language into TextSlotDiffRenderer
Fix fixme by sending the language code to SlotDiffRenderer as an option.

Note that this is the language used for word segmentation of the
content, not the UI language.

Change-Id: I2d0a6996b02d37a3f2d8fefa851244803025bb6c
2023-07-06 10:35:03 +10:00
jenkins-bot
f74a79dc4f Merge "Migrate several wfGetDB() to use ICP" 2023-07-05 10:50:57 +00:00
Amir Sarabadani
3e157496ff Migrate several wfGetDB() to use ICP
And doing proper dependency injection.

Bug: T330641
Change-Id: I4978c158e513f88f5547343c4fbbe4b39078dc09
2023-07-05 11:00:59 +02:00
jenkins-bot
77e2974aa8 Merge "Optimise DifferenceEngine::addLocalisedTitleTooltips()" 2023-07-05 05:21:40 +00:00
Tim Starling
4fd2b0dfd5 Add DifferenceEngine::getDefaultLanguage()
So that Wikibase can stop accessing the protected property mDiffLang.

Change-Id: I1fc6dd8b6187682659a1689708405ddb81e22acd
2023-07-05 10:48:42 +10:00
Tim Starling
f1d1092f73 Optimise DifferenceEngine::addLocalisedTitleTooltips()
* Remove unnecessary regex
* Move message expansion outside the loop

Change-Id: I44c273f1d798c436687be1a43b3aa94be0a8fdcc
2023-07-03 18:44:31 +10:00
Tim Starling
4d0604d8fa Remove hard-deprecated public properties of DifferenceEngine
And remove commented-out code also dating from 1.32 with no near-term
prospect of being implemented.

Change-Id: I526c558b2efae4b77ae38d0b5bb8127c8b31c280
2023-07-03 16:51:22 +10:00
jenkins-bot
06fc24ee35 Merge "Update cascading protection when showing a diff page" 2023-06-26 16:55:08 +00:00
jenkins-bot
7b7f1181d3 Merge "diff: Move SlotDiffRenderer::getTablePrefix() parts assembly up to DifferenceEngine" 2023-06-26 03:13:42 +00:00
jenkins-bot
5e1979ce15 Merge "diff: Change from WikiPage::getParserOutput to ParserOutputAccess" 2023-06-26 02:58:27 +00:00
Tim Starling
12ec0d8557 Update cascading protection when showing a diff page
Links must be updated when the parser cache is updated, because
otherwise the subsequent parser cache hit on page view will suppress
further updates, breaking cascading protection.

Change-Id: I41b99e745e46329c73187c70627888651cf2d890
2023-06-26 12:04:42 +10:00
jenkins-bot
f7388feffa Merge "diff: Add inline format switch when Wikidiff2 is installed" 2023-06-26 02:03:41 +00:00
Umherirrender
25029b2739 diff: Change from WikiPage::getParserOutput to ParserOutputAccess
- Allows to reuse the RevisionRecord and not reloading in
  WikiPage::getParserOutput from the RevisionStore
- Allows to pass ParserOutputAccess::OPT_NO_AUDIENCE_CHECK to get a
  ParserOutput also for revision deleted content, where a check
  against RevisionRecord::FOR_PUBLIC would reject the content
- Allows to show error message when render does not work

Bug: T212316
Change-Id: Id3c2de3e5cf796f5a9b213bd7bd94c9291014eb5
2023-06-26 11:58:58 +10: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
hmonroy
360182a566 diff: Add inline format switch when Wikidiff2 is installed
Add a switch that allows toggling between inline and two-column format
when Wikidiff2 is installed.

Inline toggle should also support no-JS toggling

The legend should toggle when switching from table to inline after the
first load.

Introduced a temporary feature flag to show this inline toggle so that
we can merge and easily continue the improvements. It will be removed
when ready for production.

Bug: T336712
Bug: T330229
Change-Id: Ie6a48e495f2bb299d8b984e7c40363d534c7915b
2023-06-26 10:31:54 +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
512806564d Do not generate diffs for slots with identical content
When the old and new revisions have identical content in a given slot,
do not include the relevant SlotDiffRenderer in the return value of
DifferenceEngine::getSlotDiffRenderers(), so that the relevant table
prefixes and modules will be omitted.

Also:

* In TextSlotDiffRenderer::getTextDiff(), return an empty string when
  the inputs are equal, instead of invoking the diff engine. Previously,
  the inline format would produce a <tr> element in this case, causing
  the diff-empty message to be omitted.
* Clarify the doc comment up the stack, indicating SlotDiffRenderer may
  return zero <tr> tags, it doesn't have to be one or more.
* Fix the documented return type of getSlotContents() so that @var is
  not needed in the caller.
* Don't convert the return value of SlotDiffRenderer::getDiff() to
  boolean. It's always a string so compare it to the empty string.

Note that the cache key for inline empty diffs will change, because
TextSlotDiffRenderer::getExtraCacheKeys() is not called anymore for
empty diffs.

Bug: T338670
Change-Id: I0774ba0b159ac43ec214403cf2d06740f6d067cd
2023-06-21 14:46:19 +10:00
Bartosz Dziewoński
36e54eb3e6 DifferenceEngine: Fix "No difference" notice on cached diffs
Also, HTML-escape the cache key in the output. In the current
implementation it is HTML-safe, but it could change.

Bug: T228761
Change-Id: I23406266fef4906cdf0a281f7058b66b30680f0d
2023-06-13 23:54:17 +00:00
Daimona Eaytoy
4d5cd3a84f Replace deprecated MWException
Bug: T328220
Change-Id: I66be7a6dd752d6b9c254beb65f4eb5ace3c89776
2023-06-09 17:21:12 +02:00
Sam Wilson
1eb586013c diff: Add legend and tooltips to inline diff display
Add a legend at the top of the inline diff display, showing the
meanings of the colours of the inserted and deleted highlighting.
Also add the same text as tooltips on the highlighted elements.

The legend is added as part of a new area above the diff table
that can be modified via a new TextSlotDiffRendererTablePrefix
hook, so that extensions can add other buttons etc. there as
required.

This is a follow-up to the previous attempt, which added the
legend in DifferenceEngine::showDiff() and was called from
too many places. This patch moves it to be called in
DifferenceEngine::showDiffPage().

Bug: T324759
Change-Id: I2a3c67bcfa47313dee597e602a62073e4e298cd2
Follow-up: I6de30bf79eb5ac262285951792782b870d075e00
2023-05-31 15:43:28 +10:00
Samtar
2ba3afbd47
Revert "diff: Add legend and tooltips to inline diff display"
This reverts commit 19eb61de66.

Reason for revert: Reworking

Change-Id: I2bc524254d10d6612c5b0a7db95dd6af5f60ccaa
Depends-On: I5c3d7df530eb6fc09ba380d42a81b17511861308
Depends-On: I60784afa0d47e22acd9e8a981092784c84b250eb
2023-05-18 15:50:59 +01:00
Sam Wilson
2d8b724e4e diff: Only show inline legend for text slot
To avoid showing it on other content types, such
as PageSlotDiffRenderer in ProofreadPage.

Bug: T336481
Change-Id: Ibe453fc9e8f4eea5de9c66e1446286174eb3ad17
2023-05-17 07:51:24 +08:00
Sam Wilson
19eb61de66 diff: Add legend and tooltips to inline diff display
Add a legend at the top of the inline diff display, showing the
meanings of the colours of the inserted and deleted highlighting.
Also add the same text as tooltips on the highlighted elements.

The legend is added as part of a new area above the diff table
that can be modified via a new DifferenceEngineBeforeDiffTable
hook, so that extensions can add other buttons etc. there as
required.

Bug: T324759
Change-Id: I6de30bf79eb5ac262285951792782b870d075e00
2023-04-28 11:27:10 +08:00
jenkins-bot
5b272dde21 Merge "Add GENDER support for 'diff-multi-sameuser'" 2023-04-17 22:35:09 +00:00
Jon Harald Søby
20e447eb8e Add GENDER support for 'diff-multi-sameuser'
Bug: T271030
Change-Id: I8ac6ebcb34c606acd1ecb4b160508bf265ef57c6
2023-04-17 23:41:11 +02:00
MusikAnimal
4aa7adf482 ApiComparePages: expose 'difftype' param if wikidiff2 is installed
Bug: T334011
Change-Id: Ia2242d352f23588f90143d10c16fba885f64ac63
2023-04-11 19:49:11 -04:00
Sam Wilson
231849c701 Add lists of class names for dynamic diff classes
This duplicates what's done in resources/src/mediawiki.action/mediawiki.action.edit.preview.js
for easier searching.

Change-Id: Iecac1b242f461d3e10cf2b9ad8e1c0d950ef9dfa
2023-03-16 14:48:38 +08: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
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
jenkins-bot
38a241252a Merge "docs: Add missing StubUserLang type to some @param/@return" 2023-02-03 23:45:03 +00:00
jenkins-bot
3eb74515fd Merge "OutputPage: Call setSections() from addParserOutputMetadata()" 2023-01-16 22:23:22 +00:00
Umherirrender
1af3e211eb docs: Add missing StubUserLang type to some @param/@return
Change-Id: Ic1f192c7a21e529113fd7d537a79b2e4f8983b9c
2023-01-12 19:04:20 +01:00
thiemowmde
e25503c6a3 diff: Update incomplete PHPDoc type in DifferenceEngine
Change-Id: Ib1591246d20ad63f0e64756054816352d9bdede4
2023-01-10 20:37:49 +00:00
jenkins-bot
293f8dfba8 Merge "Make use of ??= in more places" 2022-12-21 00:33:46 +00:00
Bartosz Dziewoński
0945f6976c OutputPage: Call setSections() from addParserOutputMetadata()
Remove calls elsewhere which now became redundant.

Bug: T325562
Bug: T325600
Change-Id: I1611f3bdea46a729ecf9daf699d761b018d49b55
2022-12-20 01:08:23 +01: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
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
Umherirrender
f65e6bb488 Replace deprecated Linker::commentBlock/revComment
Bug: T324906
Change-Id: I8cf96c3b7a03127ce1243f7a7e849b6d5a5d3dfa
2022-12-11 01:33:56 +01:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Tim Starling
540bddfb1f When content is marked bad, show an error, don't pretend it is empty
It misrepresents the users contribution to show empty text for a
revision when in fact the revision contained some text which we later
lost.

Also, errors from SqlBlobStore::fetchBlobs() did not stop a cache entry
from being written, so a subsequent cache hit would show the bad
revision as empty.

So, in Storage:
* Add BadBlobException, which is thrown by the Storage layer to
  indicate that a revision is marked as bad.
* Have SqlBlobStore::getBlobStore() return an error for bad blobs
  instead of an empty string.
* Duplicate the check for flags=error into SqlBlobStore::expandBlob().
  This avoids an unnecessary cache fetch, and avoids making
  decompressData() throw on error, which would be a b/c break.
* In SqlBlobStore::getBlob(), suppress the cache when there was an
  error.

In Revision:
* Add BadRevisionException, to wrap BadBlobException in the Revision
  layer.
* Return null from RevisionRecord::getContent() on a broader set of
  errors. Make it mostly non-throwing.
* Add RevisionRecord::getContentOrThrow() which returns a non-nullable
  Content.
* Note that SlotRecord::getContent() returns a non-nullable Content so
  now throws in more cases.

In the UI:
* In Article::view(), catch the exception and show an error message.
* In DifferenceEngine, catch the exception and make a suitable error
  message available via getRevisionLoadErrors(). In the diff page, show
  the error message in a box.
* In ApiComparePages and the legacy rvdiffto, show a warning.
* In RawAction, show a 404 by analogy with other error cases.
* In EditPage, there was already handling for $content=null with an
  appropriate error message (missing-revision-content). But having
  $this->textbox1 = null caused PHP 8.1 deprecation warnings, so I fixed
  that.
* In EditPage undo, there was already handling for null content, but I
  improved the error message: "does not exist or was deleted" seems more
  appropriate than "conflicting intermediate edits".

Change-Id: Idd1278d6d756ef37d64addb7b5f3be30747ea603
2022-12-05 22:03:45 +00:00
Reedy
0cb2c3c106 Fix casing of class and function name usages
Bug: T253628
Change-Id: I5c64f436d3cf757390b751ce3e34bfc7872bc176
2022-12-04 19:09:30 +00:00
jenkins-bot
1f39f2892c Merge "Really drop DifferenceEngine::getDiffBodyCacheKey" 2022-11-17 14:09:34 +00:00
jenkins-bot
381c1f0822 Merge "Track reason for rendering in more detail." 2022-11-17 12:44:01 +00:00
Matěj Suchánek
755e86c8fb Really drop DifferenceEngine::getDiffBodyCacheKey
In 81f69c2, I have only removed the callers. The method is
now dead code and should have been removed as well.

Change-Id: I556ed5398435f4d3a5f400e07e4819dd16e0df06
2022-11-17 12:24:09 +00:00