Initial fix for bug 49158

Initial changes to address this bug:

https://bugzilla.wikimedia.org/show_bug.cgi?id=49158

Since it's my first commit for the project, I'm trying to keep this one modest, and if it looks good, I can finish out the remaining tasks in bug 49158.