Thread:Project:Support desk/add code if page doesn't contain it already/reply

I think you could use the attemptSave hook to do this. See these extensions for examples of how to do that.