mediawiki.util: Clean up nextnode logic

Change-Id: I21469a765002897f03caca97628ad36264d49c83
Merge "mediawiki.util: Clean up nextnode logic"