ImageListPager: Kill that annoying GROUP BY
The GROUP BY is broken in later comment migration stages, we just didn't
notice because it's not used when $wgMiserMode is set. Instead of trying
to fix it, yet again, let's just do the count as a subselect.
While this code is being touched, let's also use Database's aliasing
functionality properly instead of passing "foo AS bar" as integer-keyed
values in $fields (with array_search() being used to change them!), and
let's start using Database->addQuotes() for string literals instead of
hard-coding single quotes.
Bug: T212980
Change-Id: Ide7f67893f625fe03127d4a775642cf0a9cca195