Facile one-step synthesis of magnesium-doped ZnO nanoparticles: optical properties and their device applications