Make message key parser accept more than just underscores

The best practice for message keys is to use dashes, not underscores.
This codebase is quite old and traditionally uses underscores. I
think we can make it flexible enough to work with both.

Required for Ie64f4ab.

Change-Id: I6f0584299a4f279ed929784927392eb0f72cbc80
This commit is contained in:
Thiemo Kreuz 2022-06-01 10:34:57 +02:00
parent bb62d762ab
commit 11255770c5
2 changed files with 4 additions and 4 deletions

View file

@ -68,7 +68,7 @@ class ErrorReporter {
$language = $this->getInterfaceLanguageAndSplitCache( $parser );
$msg = $this->messageLocalizer->msg( $key, ...$params )->inLanguage( $language );
[ $type, ] = $this->parseTypeAndIdFromMessageKey( $msg->getKey() );
[ $type ] = $this->parseTypeAndIdFromMessageKey( $msg->getKey() );
if ( $type === 'error' ) {
// Take care; this is a sideeffect that might not belong to this class.
@ -124,10 +124,10 @@ class ErrorReporter {
/**
* @param string $messageKey Expected to be a message key like "cite_error_ref_too_many_keys"
*
* @return string[]
* @return string[] Two elements, e.g. "error" and "ref_too_many_keys"
*/
private function parseTypeAndIdFromMessageKey( string $messageKey ): array {
return array_slice( explode( '_', $messageKey, 3 ), 1 );
return array_slice( explode( '_', str_replace( '-', '_', $messageKey ), 3 ), 1 );
}
}

View file

@ -14,7 +14,7 @@ use Wikimedia\TestingAccessWrapper;
*/
class AnchorFormatterTest extends \MediaWikiUnitTestCase {
public function setUp(): void {
protected function setUp(): void {
parent::setUp();
global $wgFragmentMode;