Moved $wgQueryPages stuff out of the global scope and into a function

Change-Id: Ica034bdad89133bfce0b4238d62ed00865936644
Merge "Moved $wgQueryPages stuff out of the global scope and into a function"