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:
class MyContentHandler extends WikitextContentHandler {
protected function getContentClass() {
return 'MyContent';
}
}
class MyContent extends WikitextContent {
// TODO: override preSaveTransform() here
}
In the Content subclass, override the preSaveTransform() method, e.g. like this (if you want to modify the wikitext after the normal PST pass):
public function preSaveTransform( Title $title, User $user, ParserOptions $popts ) {
$content = parent::preSaveTransform( $title, $user, $popts );
$orig = $text = $content->getNativeData();
// ...modify $text here...
return ( $orig === $text ) ? $content : new static( $text );
}
Register your new ContentHandler as the handler for ordinary wiki pages using $wgContentHandlers in LocalSettings.php:
$wgContentHandlers[CONTENT_MODEL_WIKITEXT] = 'MyContentHandler';
(Warning: I believe this method should work, but I have not actually tested it! Use at your own risk. Improvements and bug reports welcome.)