fix / update for broken gallery sorting

adds two new functions, one to query the gallery on the admin side, and one to properly save it. also includes JS for sorting items and some general cleanup
This cap check is already done [higher up the stack](https://github.com/WordPress/WordPress/blob/master/wp-admin/post.php#L153-L154).