MDL-40931 useragent: separated user agent functionality into a lib

This commit moves user agent related functionality out of several
core libraries and combines it into a more manageable class.
All core uses are converted and functions deprecated in favor
of the new class.
MDL-40931 useragent: several pre-integration tidy-ups

* Fixed conflicts (rebased)
* Major version bump
* Fixed up use of set_user_device_type
* Fixed up theme/index.php
* Re-grepped everything.