Ported r112366 from 1.19wmf branch indefinitely.