Page MenuHomePhabricator

Various hooks that process messages get incorrect global context via ParserOutput
Closed, ResolvedPublic

Description

Observed in CI mw-debug-www.log, when investigating unrelated issues relating to T300069.

GrowthExperiments HelpPanelHooks
[GlobalTitleFail] RequestContext::getTitle called with no title set.
#0 /workspace/src/includes/parser/ParserOutput.php(469): RequestContext->getTitle()
#1 /workspace/src/includes/language/Message.php(1445): ParserOutput->getText(array)
#2 /workspace/src/includes/language/Message.php(997): Message->parseText(string)
#3 /workspace/src/includes/language/Message.php(1055): Message->format(string)
#4 /workspace/src/extensions/GrowthExperiments/includes/HelpPanelHooks.php(204): Message->parse()
#5 /workspace/src/includes/resourceloader/ResourceLoaderFileModule.php(1312): GrowthExperiments\HelpPanelHooks::getModuleData(ResourceLoaderContext, GlobalVarConfig, NULL)
#6 /workspace/src/includes/resourceloader/ResourceLoaderFileModule.php(635): ResourceLoaderFileModule->expandPackageFiles(ResourceLoaderContext)
#7 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(908): ResourceLoaderFileModule->getDefinitionSummary(ResourceLoaderContext)
#8 /workspace/src/includes/resourceloader/ResourceLoaderStartUpModule.php(220): ResourceLoaderModule->getVersionHash(ResourceLoaderContext)
#9 /workspace/src/includes/resourceloader/ResourceLoaderStartUpModule.php(421): ResourceLoaderStartUpModule->getModuleRegistrations(ResourceLoaderContext)
#10 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(796): ResourceLoaderStartUpModule->getScript(ResourceLoaderContext)
#11 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(765): ResourceLoaderModule->buildContent(ResourceLoaderContext)
#12 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(905): ResourceLoaderModule->getModuleContent(ResourceLoaderContext)
#13 /workspace/src/includes/resourceloader/ResourceLoader.php(718): ResourceLoaderModule->getVersionHash(ResourceLoaderContext)
#14 [internal function]: ResourceLoader->{closure}(string)
#15 /workspace/src/includes/resourceloader/ResourceLoader.php(732): array_map(Closure, array)
#16 /workspace/src/includes/resourceloader/ResourceLoader.php(821): ResourceLoader->getCombinedVersion(ResourceLoaderContext, array)
#17 /workspace/src/load.php(52): ResourceLoader->respond(ResourceLoaderContext)
#18 /workspace/src/load.php(38): wfLoadMain()
CheckUser ToolLinksMessages
[GlobalTitleFail] RequestContext::getTitle called with no title set.
#0 /workspace/src/includes/parser/ParserOutput.php(469): RequestContext->getTitle()
#1 /workspace/src/includes/language/Message.php(1445): ParserOutput->getText(array)
#2 /workspace/src/includes/language/Message.php(997): Message->parseText(string)
#3 /workspace/src/includes/language/Message.php(1055): Message->format(string)
#4 /workspace/src/extensions/CheckUser/src/ToolLinksMessages.php(15): Message->parse()
#5 /workspace/src/includes/resourceloader/ResourceLoaderFileModule.php(1312): MediaWiki\CheckUser\ToolLinksMessages::getParsedMessage(ResourceLoaderContext, GlobalVarConfig, string)
#6 /workspace/src/includes/resourceloader/ResourceLoaderFileModule.php(635): ResourceLoaderFileModule->expandPackageFiles(ResourceLoaderContext)
#7 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(908): ResourceLoaderFileModule->getDefinitionSummary(ResourceLoaderContext)
#8 /workspace/src/includes/resourceloader/ResourceLoaderStartUpModule.php(220): ResourceLoaderModule->getVersionHash(ResourceLoaderContext)
#9 /workspace/src/includes/resourceloader/ResourceLoaderStartUpModule.php(421): ResourceLoaderStartUpModule->getModuleRegistrations(ResourceLoaderContext)
#10 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(796): ResourceLoaderStartUpModule->getScript(ResourceLoaderContext)
#11 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(765): ResourceLoaderModule->buildContent(ResourceLoaderContext)
#12 /workspace/src/includes/resourceloader/ResourceLoaderModule.php(905): ResourceLoaderModule->getModuleContent(ResourceLoaderContext)
#13 /workspace/src/includes/resourceloader/ResourceLoader.php(718): ResourceLoaderModule->getVersionHash(ResourceLoaderContext)
#14 [internal function]: ResourceLoader->{closure}(string)
#15 /workspace/src/includes/resourceloader/ResourceLoader.php(732): array_map(Closure, array)
#16 /workspace/src/includes/resourceloader/ResourceLoader.php(821): ResourceLoader->getCombinedVersion(ResourceLoaderContext, array)
#17 /workspace/src/load.php(52): ResourceLoader->respond(ResourceLoaderContext)
#18 /workspace/src/load.php(38): wfLoadMain()
#19 {main}

https://integration.wikimedia.org/ci/job/wmf-quibble-selenium-php72-docker/139590/artifact/log/

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
Krinkle added subscribers: matmarex, ssastry.

As found by @matmarex, this appears to be fallout from T287767, T295187 and related changes which as of last week (change 764112) introduced completely unchecked global state into one of the most central and context-sensitive code paths, namely ParserOutput.

class ParserOutput {
  function getText() {
    $title = RequestContext::getMain()->getTitle();
  }
}

Together with the dozen XXX and FIXME notes in the same hacky code, it seems like all involved knew this wasn't meant to last.

Krinkle renamed this task from HelpPanelHooks::getModuleData uses incorrect context to HelpPanelHooks::getModuleData messages get incorrect context via ParserOutput.Mar 8 2022, 1:44 AM
Krinkle renamed this task from HelpPanelHooks::getModuleData messages get incorrect context via ParserOutput to Various hooks that process messages get incorrect global context via ParserOutput.Mar 8 2022, 1:47 AM
Krinkle added a project: CheckUser.
Krinkle updated the task description. (Show Details)

Change 768850 had a related patch set uploaded (by Func; author: Func):

[mediawiki/core@master] parser: Parse ToC along with page contents

https://gerrit.wikimedia.org/r/768850

kostajh subscribed.

Is there some action needed from Growth-Team or is this going to be handled by Parsing-Active-Work / https://gerrit.wikimedia.org/r/768850?

Sorry, this is my fault: I should have reviewed an C-1'ed change 764112. I was responsible for the dozen FIXME comments -- we had a regression in production and I implemented the "quick fix for 99% of the cases" necessary to fix T295187, and then the followup work dropped off my radar because the corner cases seemed to be uncommon enough that no one was complaining about them. But it's definitely something I want to have fixed properly for 1.38.

As obvious in change 764112, fixing this "just" in getText is impossible because the information needed isn't available in the ParserOutput. So what needs to happen is some additional information needs to be recorded in the ParserOutput from the Parser, at parse time, in order to allow the conversion to occur "properly" in ParserOutput::getText(). I'll get those patches written.

Sorry, this is my fault: I should have reviewed an C-1'ed change 764112. I was responsible for the dozen FIXME comments -- we had a regression in production and I implemented the "quick fix for 99% of the cases" necessary to fix T295187, and then the followup work dropped off my radar because the corner cases seemed to be uncommon enough that no one was complaining about them. But it's definitely something I want to have fixed properly for 1.38.

As obvious in change 764112, fixing this "just" in getText is impossible because the information needed isn't available in the ParserOutput. So what needs to happen is some additional information needs to be recorded in the ParserOutput from the Parser, at parse time, in order to allow the conversion to occur "properly" in ParserOutput::getText(). I'll get those patches written.

I found the conversion of ToC should be done along with page contents due to multiple reasons (or the generation of ToC should be refactored), so I uploaded change 768850 and explained them in the commit message, could you please review it? Thanks.

Change 769115 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] Revert "ParserOutput: Use page language instead of site content language for conversion"

https://gerrit.wikimedia.org/r/769115

Change 769116 had a related patch set uploaded (by C. Scott Ananian; author: C. Scott Ananian):

[mediawiki/core@master] Ensure that ToC is converted into the proper target language

https://gerrit.wikimedia.org/r/769116

Change 768850 abandoned by Func:

[mediawiki/core@master] parser: Parse ToC along with page contents

Reason:

https://gerrit.wikimedia.org/r/768850

Change 769115 merged by jenkins-bot:

[mediawiki/core@master] Revert "ParserOutput: Use page language instead of site content language for conversion"

https://gerrit.wikimedia.org/r/769115

Change 769116 merged by jenkins-bot:

[mediawiki/core@master] Ensure that ToC is converted into the proper target language

https://gerrit.wikimedia.org/r/769116

Func claimed this task.
Func reassigned this task from Func to cscott.