Thanks for this, it's still working with the latest MG 2.2.1 and I had requests for this function.
I think XF should include this in their releases as well as default sort order options in individual categories with the Media Gallery and the Resource Manager.