Skip to content

"Show all recent topic pages" computes topic count before the forum list is built #195

Description

@avandenberghe

Summary

In core/recenttopics.php, when rt_page_number ("Show all recent topic pages") is enabled, total_topics_limit is computed via get_allowed_topics_sql() (which builds its WHERE clause from $this->forum_ids, through content_visibility::get_forums_visibility_sql()) before get_forum_list() has run. At that point $this->forum_ids is still unset/null.

content_visibility::get_forums_visibility_sql() combines two branches with OR:

  • moderator-approve forums: forum_id IN (approve_forums)
  • normal-read forums: topic_visibility = APPROVED AND forum_id IN ($forum_ids)

With $forum_ids empty/null, sql_in_set(..., array(), false, true) collapses the normal-read branch to false, so the count query silently degrades to "only forums where the user has m_approve". For a normal member (no m_approve anywhere) the count comes back 0 or matches no forums; for a moderator it returns a count scoped only to their moderated forums — unrelated to the actual Recent Topics forum set.

That wrong total_topics_limit then drives pagination, so page 1 is marked current on every page and the list renders truncated to this unrelated count.

Location

avathar/recenttopics/core/recenttopics.php:

  • total_topics_limit computed around line 338-353, calling get_allowed_topics_sql() (which reads $this->forum_ids at line ~640 via get_forums_visibility_sql())
  • get_forum_list() (which populates $this->forum_ids) is not called until line 362 — after the count above

Steps to reproduce

  1. Enable "Show all recent topic pages" (rt_page_number).
  2. Log in as a moderator with m_approve on some forum(s) but not all forums the Recent Topics block would otherwise draw from.
  3. View the Recent Topics list: the topic count / pagination reflects only the moderated forum(s), not the full set of readable forums, and page 1 is marked current regardless of the actual page shown.

Fix

Move the total_topics_limit computation after get_forum_list(), or reuse the topic count already produced inside get_topic_list() instead of running a second, separately-scoped count query beforehand.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugv3.0Version 3.0.x - maintenance releases

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions