wiki.techinc.nl/includes/language/FormatterFactory.php
Máté Szabó a5049b481f status: Log getMessage()/getWikiText() calls on good Statuses
Why:

- Calling getMessage()/getWikiText() with a good Status is a logic error
  that converts the Status being operated on into a fatal one.
- However, this error is never logged anywhere, which can make it
  difficult to diagnose such cases, as seen in
  I17166e988bf389a5b03d4a74f539f7bec7f5997f.

What:

- Add a warning-level log for the case when getMessage() or
  getWikiText() is invoked with a good Status.

Bug: T374436
Change-Id: I3efae5c4c336156924f1c9b4186fa9142aaed9ca
2024-10-04 18:32:24 +02:00

59 lines
1.6 KiB
PHP

<?php
namespace MediaWiki\Language;
use MediaWiki\Block\BlockErrorFormatter;
use MediaWiki\HookContainer\HookContainer;
use MediaWiki\Languages\LanguageFactory;
use MediaWiki\Status\StatusFormatter;
use MediaWiki\Title\TitleFormatter;
use MediaWiki\User\UserIdentityUtils;
use MessageCache;
use MessageLocalizer;
use Psr\Log\LoggerInterface;
/**
* Factory for formatters of common complex objects
*
* @since 1.42
*/
class FormatterFactory {
private MessageCache $messageCache;
private TitleFormatter $titleFormatter;
private HookContainer $hookContainer;
private UserIdentityUtils $userIdentityUtils;
private LanguageFactory $languageFactory;
private LoggerInterface $logger;
public function __construct(
MessageCache $messageCache,
TitleFormatter $titleFormatter,
HookContainer $hookContainer,
UserIdentityUtils $userIdentityUtils,
LanguageFactory $languageFactory,
LoggerInterface $logger
) {
$this->messageCache = $messageCache;
$this->titleFormatter = $titleFormatter;
$this->hookContainer = $hookContainer;
$this->userIdentityUtils = $userIdentityUtils;
$this->languageFactory = $languageFactory;
$this->logger = $logger;
}
public function getStatusFormatter( MessageLocalizer $messageLocalizer ): StatusFormatter {
return new StatusFormatter( $messageLocalizer, $this->messageCache, $this->logger );
}
public function getBlockErrorFormatter( LocalizationContext $context ): BlockErrorFormatter {
return new BlockErrorFormatter(
$this->titleFormatter,
$this->hookContainer,
$this->userIdentityUtils,
$this->languageFactory,
$context
);
}
}