Big caveat: only counts namespace 0. Ideally it should probably respect $wgNamespacesToBeSearchedDefault.