Multipartite W states for chains of atoms conveyed through an optical cavity