[3.0] Don't treat a new topic as an unapproved topic - #9320
Open
albertlast wants to merge 1 commit into
Open
Conversation
Post2::submit() marked a post as unapproved whenever Topic::$info->is_approved was empty. When starting a new topic there is no topic yet, so Topic::$info is null and empty() reports it as an unapproved topic. Every non-approver who started a topic therefore got $_SESSION['becomesUnapproved'] set, and was greeted with "Your message was not approved because it was posted in an unapproved topic" even though the topic was in fact approved. The post itself was unaffected, because prepareNewTopic() resets $becomes_approved afterwards. Only the message was wrong. In 2.1 this block lived inside "if (!empty($topic))". Restores that guard, which was lost when the code was moved into Post2. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Jul 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
This change was produced by an LLM. The code, the commit message and this
description were all written by Claude (Anthropic), driven by @albertlast. It has
not yet had human code review.
Everything stated below was verified by actually running it against a PostgreSQL
install of this branch, rather than only reasoned about. Even so, please review it
as untrusted work: the diagnosis may be right while the fix is not what SMF would
prefer stylistically or architecturally.
Description
An ordinary member who starts a new topic is told, on the page they land on
afterwards:
The topic is in fact approved.
Post2::submit()decides this before it knows whichkind of post it is dealing with:
When a new topic is being started there is no topic yet.
Post2::execute()onlyloads one when there is something to load:
So
Topic::$infoisnull,empty(null->is_approved)istrueunderempty()'sisset semantics, and every non-approver who starts a topic gets
$_SESSION['becomesUnapproved']set.MessageIndexandDisplaypick that up onthe next page and show the notice.
The post itself is unaffected —
prepareNewTopic()runs immediately afterwards andsets
$becomes_approved = trueagain — so this is purely a bogus message. It alsofires with post moderation switched off entirely, since the check never consults
postmod_active.In 2.1 the whole block sat inside
if (!empty($topic))(Sources/Post.php, ~1789),so it only ever applied to replies. That guard was lost when the code moved into
Post2. This restores it in the formPost2uses to express the same thing, whichis
$this->intent !== self::INTENT_NEW_TOPIC.How this was verified
PostgreSQL 17 / PHP 8.4.23, as an ordinary member with no moderation permissions.
Worth noting up front: the test install has post moderation entirely off —
postmod_activeis not even present insmf_settings— which is what shows thecheck is misfiring rather than doing its job.
"posted in an unapproved topic" notice is shown. Meanwhile the database has
topics.approved = 1andmessages.approved = 1for what was just posted, so themessage contradicts what actually happened.
then replied to it as the same member. The notice is still shown and the reply
is stored with
approved = 0, so genuine replies to unapproved topics behaveexactly as before.
php -lclean.Relationship to other PRs
Sources/Actions/Post2.phpis not touched by any of the other open PRs(#9310–#9317), so this one stands alone.
Issues References (Fixes|Related|Closes)