Fix: preg_replace /e modifier deprecation error

There was a very old code path that uses /e modifier in
preg_replace statement. On PHP5 this causes issues. The replacement
actually never gets executed, but the pattern gets still compiled and
causes error_log output. I moved it to preg_replace_callback and adjusted
the callbacks argument processing.

THIS IS A MANUAL MERGE OF https://gerrit.wikimedia.org/r/#/c/173754/

Change-Id: I04bd7ccf54c879efcaf69e801cf343160cac4bd7