mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/TemplateData
synced 2024-11-23 23:43:54 +00:00
Merge "Pull dependency on global MediaWikiServices up one level"
This commit is contained in:
commit
d3d9871528
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Extension\TemplateData;
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Status\Status;
|
||||
use stdClass;
|
||||
|
@ -28,10 +29,11 @@ class TemplateDataBlob {
|
|||
* @return TemplateDataBlob
|
||||
*/
|
||||
public static function newFromJSON( IReadableDatabase $db, string $json ): TemplateDataBlob {
|
||||
$lang = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::LanguageCode );
|
||||
if ( $db->getType() === 'mysql' ) {
|
||||
$tdb = new TemplateDataCompressedBlob( $json );
|
||||
$tdb = new TemplateDataCompressedBlob( $json, $lang );
|
||||
} else {
|
||||
$tdb = new TemplateDataBlob( $json );
|
||||
$tdb = new TemplateDataBlob( $json, $lang );
|
||||
}
|
||||
return $tdb;
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ class TemplateDataBlob {
|
|||
return self::newFromJSON( $db, $json );
|
||||
}
|
||||
|
||||
protected function __construct( string $json ) {
|
||||
protected function __construct( string $json, string $lang ) {
|
||||
$deprecatedTypes = array_keys( TemplateDataNormalizer::DEPRECATED_PARAMETER_TYPES );
|
||||
$validator = new TemplateDataValidator( $deprecatedTypes );
|
||||
$this->status = $validator->validate( json_decode( $json ) );
|
||||
|
@ -62,8 +64,7 @@ class TemplateDataBlob {
|
|||
// we don't end up with invalid data in the database.
|
||||
$value = $this->status->getValue() ?? (object)[ 'params' => (object)[] ];
|
||||
|
||||
$lang = MediaWikiServices::getInstance()->getContentLanguage();
|
||||
$normalizer = new TemplateDataNormalizer( $lang->getCode() );
|
||||
$normalizer = new TemplateDataNormalizer( $lang );
|
||||
$normalizer->normalize( $value );
|
||||
|
||||
// Don't bother storing the decoded object, it will always be cloned anyway
|
||||
|
|
|
@ -25,8 +25,8 @@ class TemplateDataCompressedBlob extends TemplateDataBlob {
|
|||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function __construct( string $json ) {
|
||||
parent::__construct( $json );
|
||||
protected function __construct( string $json, string $lang ) {
|
||||
parent::__construct( $json, $lang );
|
||||
$this->jsonDB = gzencode( $this->json );
|
||||
|
||||
$length = strlen( $this->jsonDB );
|
||||
|
|
|
@ -5,6 +5,7 @@ use MediaWiki\Extension\TemplateData\TemplateDataBlob;
|
|||
use MediaWiki\Extension\TemplateData\TemplateDataHtmlFormatter;
|
||||
use MediaWiki\Extension\TemplateData\TemplateDataValidator;
|
||||
use MediaWiki\Language\RawMessage;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\Parser\Sanitizer;
|
||||
use MediaWiki\Status\Status;
|
||||
use MediaWiki\Title\Title;
|
||||
|
@ -1141,7 +1142,7 @@ class TemplateDataBlobTest extends MediaWikiIntegrationTestCase {
|
|||
public function testGetDataInLanguage( array $case ) {
|
||||
// Change content-language to be non-English so we can distinguish between the
|
||||
// last 'en' fallback and the content language in our tests
|
||||
$this->setContentLang( 'nl' );
|
||||
$this->overrideConfigValue( MainConfigNames::LanguageCode, 'nl' );
|
||||
|
||||
$t = TemplateDataBlob::newFromJSON( $this->db, $case['input'] );
|
||||
$status = $t->getStatus();
|
||||
|
|
Loading…
Reference in a new issue