Revert "removed hack queries, changed intval calls to (int) and extracted what could be extracted outside the loop"; it broke Special:Follwing by adding empty section

This reverts commit fe8af6255543a3bf7fcaac0525f7fa4c831bd7ac.