make it possible to select a media file in the link chooser

* make it possible to select a media file in the link chooser
* refactoring + code formatting/cleanup