You would need to write an extension (Or put it entirely in a javascript file like the page MediaWiki:Common.js on your wiki)