Page MenuHomePhabricator

Wikitext 2017 editor emptying a page when trying to edit ro:Partidul Comunist Român
Open, Needs TriagePublicBUG REPORT

Description

I tried to fix some pages at rowiki affected by T336101, which worked fine with most of them. But when trying to make the same change at ro:Partidul Comunist Român, suddenly the page was empty when clicking „publish changes“ and/or „show preview“/„review your changes“ (which is why I didn't actually save my changes). This bug occured, regardless if I wanted to add or remove text from this article.

When I turn off the 2017 wikitext editor, everything works fine, when I turn it on, the bug appears again.

Steps to replicate the issue (include links if applicable):

What happens?:

  • Page shows empty

What should have happened instead?:

  • Only the changed text should actually change.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):
I did a screen recording of me trying to edit the page with 2017 wikitext editor enabled (bug occurs), disabled (no problem), another page with 2017 wikitext editor enabled (no problem) and the original page again with 2017 wikitext editor (bug occurs again): https://we.tl/t-VjU06e1EjJ

Event Timeline

Notably, opening the preview panel on that article causes the following error in the console:

Uncaught Error: Inserted data is trying to close the root node (at index 0)
    at writeElement (ve.dm.Document.js?3bd94:1331:13)
    at ve.dm.Document.fixupInsertion (ve.dm.Document.js?3bd94:1516:4)
    at ve.dm.TransactionBuilder.pushInsertion (ve.dm.TransactionBuilder.js?16b1f:886:22)
    at ve.dm.TransactionBuilder.static.newFromInsertion (ve.dm.TransactionBuilder.js?16b1f:53:25)
    at ve.dm.SurfaceFragment.insertContent (ve.dm.SurfaceFragment.js?8b25c:847:44)
    at ve.dm.SourceSurfaceFragment.insertContent (ve.dm.SourceSurfaceFragment.js?6225f:97:67)
    at replaceAllTextDiacritics (index.php?title=MediaWiki:Diacritice-ve.js&action=raw&ctype=text/javascript:14:15)
    at index.php?title=MediaWiki:Diacritice-ve.js&action=raw&ctype=text/javascript:2:5
    at Object.fire (load.php?...:16)
    at ve.ui.MWSaveDialog.swapPanel (ve.ui.MWSaveDialog.js?25bda:401:42)

As such, I think this is an issue with the rowiki gadget Diacritice-ve.js and something about this specific page.

Hi David, thanks for the quick investigation. I wrote that gadget a while back, but I need some help fixing this particular error.

@Strainu I'd suggest changing the gadget like this:

function replaceAllTextDiacritics(surface) {
	if (surface.getMode() === 'source') {
		var surfaceModel = surface.getModel();
		var documentModel = surfaceModel.getDocument();
		//get all document fragment
		var fragment = surfaceModel.getLinearFragment(documentModel.getDocumentRange(), true);
		var wikitext = ve.dm.sourceConverter.getSourceTextFromDataRange(fragment.getData())
		wikitext = sanitizeWikitext( wikitext );
		fragment.insertContent( ve.dm.sourceConverter.getDataFromSourceText(wikitext) );
	} else {
		replaceLetter("ş", "ș");
		replaceLetter("Ş", "Ș");
		replaceLetter("ţ", "ț");
		replaceLetter("Ţ", "Ț");
	}
	return true;
}

The key part is using getSourceTextFromDataRange/getDataFromSourceText when getting the wikitext out of the editor and when putting it back. If you don't, the editor tries to guess what you meant, and sometimes it guesses wrong. Apparently the problem on this page occurs because it starts with an empty line.

Thanks @matmarex ! I tried your solution and it seems to work, but it is slow. Even for ro:Partidul Comunist Român it takes a few seconds to process, for an article such as ro:Rezistența_anticomunistă_din_România it takes minutes on my computer (development laptop). I checked also in VE and wikitext editor 2010 and the conversion is instant.

You're right (I haven't really noticed before, but it's obvious on a big article like Rezistența_anticomunistă_din_România), but at least for me, the previous version also seems similarly slow. This seems to be the same problem as T189557 – replacing the entire article in this way hits a bad edge case in our internal data structures.

This should now (well, next week, WP:ITSTHURSDAY and all) be fixed. Big speedup for full-document replaces in source mode has landed.