Fix up multiversion to not require dba_* functions

- Copies the pure-PHP implementation from MW core with some minor
  updates to make it work outside of MW
- Should allow us to run het deploy on hhvm without waiting on dba_*
  support upstream

Bug: 56591
Change-Id: I73195536a32fc01e0fb4fa1ca376a38837868d17
Merge "Fix up multiversion to not require dba_* functions"