Changes
add str.replace_plain
if firstonly == 'true' or firstonly == 'yes' or firstonly == '1' then
local result = mw.ustring.gsub( source_str, pattern_plain, replace_plain, 1 );
else
local result = mw.ustring.gsub( source_str, pattern_plain, replace_plain, n );
end