Page MenuHomePhabricator

Find and replace does not preserve replacements inside gallery
Closed, ResolvedPublicBUG REPORT

Description

Steps to Reproduce:

  1. Edit the following sample wikitext with visual editor:
[[File:Zeiss U Boath Periscope 1943.png|thumb|right|Foo Bar Foo]]

<gallery>
File:Zeiss U Boath Periscope 1943.png|Foo Bar Foo
File:Attack periscope.png|Foo Bar Foo
</gallery>
  1. Use the find and replace tool and replace all "Bar" with "Baz".
  2. Check the diff or switch to wikitext editor.

Actual Results:

  • Only the replacement in the image caption was preserved, gallery captions still contain "Bar".

Expected Results:
One of:

  • All replacements are preserved.
  • Find and replace skips (does not search) galleries (and possibly other embedded elements).

I found T110543 but I am not sure if it has anything to do with this.

Event Timeline

If you make any changes to the gallery using the normal dialog (either before or after doing the find-and-replace), then the find-and-replace changes will be preserved.

I figured out why this happens: Parsoid has two "modes" for gallery editing, we can submit the modified page using either the wikitext markup for everything inside <gallery>, or the HTML markup similar to what we show in the editor (and in read mode). When both are included, the wikitext "wins", and Parsoid's output includes both. That means we have to explicitly get rid of the wikitext to make any changes. This happens in this function:

modules/ve-mw/ui/dialogs/ve.ui.MWGalleryDialog.js
ve.ui.MWGalleryDialog.prototype.updateMwData = function ( mwData ) {
	...

	// Need to do this, otherwise mwData.body.extsrc will override all attribute changes
	mwData.body = {};

	...
};

But doing a find-and-replace doesn't call that code (it's part of the dialog for inserting/changing galleries).

There are two ways we could possibly fix this:

  • Get rid of the wikitext whenever doing a find-and-replace affecting a gallery. I guess T110543 is kind of relevant here, galleries could have a special "replace handler" or something.
  • Get rid of the wikitext when loading the page. This would be easy, but it would likely cause dirty diffs in existing galleries even when they're not changed.

This has been fixed by the work on T329662!