The median function on distributive semilattices