Validate inputmethod ids while constructing menu

See https://bugzilla.wikimedia.org/show_bug.cgi?id=55701