We would like to have some easy and efficient API for manipulating VE document globally problematically.
Background/Motivation;
Various popular scripts in Wikipedia manipulate the underlying data using wikitext for example:
- fawiki - https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%8C:Gadget-Extra-Editbuttons-persianwikitools.js
- hewiki - https://he.wikipedia.org/wiki/מדיה_ויקי:Gadget-Checkty.js (process_page)
- rowiki - https://ro.wikipedia.org/wiki/MediaWiki:Diacritice.js
- ruwiki - https://ru.wikipedia.org/wiki/MediaWiki:Gadget-wfTypos.js
(and there are many more...)
VE currently supports basic manipulations using surface.change( transaction ) or to do replacements similar to FindAndReplace dialog (e.g documentModel.findText & foreach
fragment insertContent) . but it has some gaps:
- Not intuitive/no interface for replacements - Some scripts use different tricks for doing replacements (https://en.wikipedia.org/wiki/User:%D7%A2%D7%A8%D7%9F/veReplace.js [ugly!], https://ro.wikipedia.org/wiki/Utilizator:Strainu/ve.js) and a standard and easy method for doing it would make it easier for future maintenance and for supporting those usages.
- Global replacements aren't supported - Going global replacements similar to hewiki/fawiki scripts isn't possible with the current model, and even if it is it would be inefficient (hewiki runs ~850 regex replacements on the whole document see full replacement dictionary https://he.wikipedia.org/wiki/%D7%95%D7%99%D7%A7%D7%99%D7%A4%D7%93%D7%99%D7%94:%D7%91%D7%95%D7%98/%D7%91%D7%95%D7%98_%D7%94%D7%97%D7%9C%D7%A4%D7%95%D7%AA/%D7%A8%D7%A9%D7%99%D7%9E%D7%AA_%D7%94%D7%97%D7%9C%D7%A4%D7%95%D7%AA_%D7%A0%D7%95%D7%9B%D7%97%D7%99%D7%AA )
- Replacement that keep annotations aren't possible (at least in a simple way)[?]
What most of the scripts needs are:
- A utility function for doing replacement (similar to ve.dm.Document.prototype.findText maybe ve.dm.Document.prototype.replaceText)
- The replacement should be able to keep the annotations
- Advance use: sometimes (as you can see in fawiki) replacements are context aware. It may be too far to support such complex replacements within ve itself, but providing documentation how to do it would be great.