As described here, the mediawiki parser allows for a pre-save transform which will automatically replace wikitext with something else.
How do I create my own?
I did find this, but I can't even be sure it's relevant anymore. http://mediawiki.sourcearchive.com/documentation/1.13.3/classArticle_a0d27b9b92f688ea124b1f1c4c0b60018.html
In modern MediaWiki versions (v1.21+), one way to do this could be to:
Write your own ContentHandler classes, extending WikiTextContent and WikitextContentHandler. These could be as simple as:
In the Content subclass, override the preSaveTransform() method, e.g. like this (if you want to modify the wikitext after the normal PST pass):
Register your new ContentHandler as the handler for ordinary wiki pages using $wgContentHandlers in LocalSettings.php:
(Warning: I believe this method should work, but I have not actually tested it! Use at your own risk. Improvements and bug reports welcome.)