wiki.techinc.nl/includes/CommentFormatter
Dreamy Jazz 05631d4fe4 Don't use RequestContext in CommentParserFactory construction
Why:
* ServiceWiring.php is documented to say that "Services MUST NOT
  vary their behaviour on the global state, especially not ...
  RequestContext ... or ... "current" user"
** However, the constructor of the CommentParserFactory calls
   `RequestContext::getMain()->getLanguage()` which is in
   violation of this rule by both using the RequestContext
   and being controlled by the state of the "current" user.
* This has caused issues with premature access to the session
  user as demonstrated in T397900.
** Specifically, the call to ::getLanguage will load the request
   user's preferences and then as part of this checks if the
   user is named (which will load the User object).
* Instead of using the incorrect method of getting the user's
  language, it should instead be fetched in
  CommentParserFactory::create.
** This will also allow the Language associated with the main
   request to change without leaving the service with an
   outdated and stale version of the user's Language object.

What:
* Update CommentParserFactory to call `RequestContext::getMain()
  ->getLanguage()` in the ::create method instead of getting it
  from the constructor.
* Remove the call to `RequestContext::getMain()->getLanguage()`
  in ServiceWiring.php as no longer needed.
* Update the unit test to instead be an integration test due to
  ::create now calling code which uses the service container.

Bug: T397900
Change-Id: I36c9d8650eb5040f94626fa50f90b8026d3c3fe9
(cherry picked from commit 536f41bce51ca67733c4879d17992ee0b0db1de8)
2025-08-19 13:01:22 +00:00
..
CommentBatch.php
CommentFormatter.php Use explicit nullable type on parameter arguments 2024-10-16 20:58:33 +02:00
CommentItem.php
CommentParser.php Use explicit nullable type on parameter arguments 2024-10-16 20:58:33 +02:00
CommentParserFactory.php Don't use RequestContext in CommentParserFactory construction 2025-08-19 13:01:22 +00:00
RevisionCommentBatch.php
RowCommentFormatter.php
RowCommentIterator.php
StringCommentIterator.php