mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-27 16:50:00 +00:00
Avoid persisting default gadget configs in definitions
Bug: T331222 Change-Id: I022a66267fd01efdfdc86cf0b21d3a0aaf7e5950
This commit is contained in:
parent
0c61a5a468
commit
05cc93b9be
|
@ -63,7 +63,7 @@ class GadgetDefinitionContent extends JsonContent {
|
|||
$this->validation = $this->getData();
|
||||
} else {
|
||||
$validator = new GadgetDefinitionValidator();
|
||||
$this->validation = $validator->validate( $this->getAssocArray() );
|
||||
$this->validation = $validator->validate( $this->getAssocArray(), true );
|
||||
}
|
||||
}
|
||||
return $this->validation;
|
||||
|
@ -80,7 +80,7 @@ class GadgetDefinitionContent extends JsonContent {
|
|||
$info = wfObjectToArray( $this->getData()->getValue() );
|
||||
/** @var GadgetDefinitionContentHandler $handler */
|
||||
$handler = $this->getContentHandler();
|
||||
$info = wfArrayPlus2d( $info, $handler->getDefaultMetadata() );
|
||||
$info = wfArrayPlus2d( $info, $handler->getEmptyDefinition() );
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,19 @@ class GadgetDefinitionContentHandler extends JsonContentHandler {
|
|||
|
||||
public function makeEmptyContent() {
|
||||
$class = $this->getContentClass();
|
||||
return new $class( FormatJson::encode( $this->getDefaultMetadata(), "\t" ) );
|
||||
return new $class( FormatJson::encode( $this->getEmptyDefinition(), "\t" ) );
|
||||
}
|
||||
|
||||
public function getEmptyDefinition() {
|
||||
return [
|
||||
'settings' => [
|
||||
'category' => '',
|
||||
],
|
||||
'module' => [
|
||||
'pages' => [],
|
||||
'dependencies' => [],
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function getDefaultMetadata() {
|
||||
|
@ -95,22 +107,28 @@ class GadgetDefinitionContentHandler extends JsonContentHandler {
|
|||
$this->makeLink( $parserOutput, $page, $title );
|
||||
}
|
||||
}
|
||||
foreach ( $data->module->dependencies as &$dep ) {
|
||||
if ( str_starts_with( $dep, 'ext.gadget.' ) ) {
|
||||
$gadgetId = explode( 'ext.gadget.', $dep )[1];
|
||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadgetId );
|
||||
$this->makeLink( $parserOutput, $dep, $title );
|
||||
if ( isset( $data->module->dependencies ) ) {
|
||||
foreach ( $data->module->dependencies as &$dep ) {
|
||||
if ( str_starts_with( $dep, 'ext.gadget.' ) ) {
|
||||
$gadgetId = explode( 'ext.gadget.', $dep )[ 1 ];
|
||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadgetId );
|
||||
$this->makeLink( $parserOutput, $dep, $title );
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ( $data->module->peers as &$peer ) {
|
||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $peer );
|
||||
$this->makeLink( $parserOutput, $peer, $title );
|
||||
if ( isset( $data->module->peers ) ) {
|
||||
foreach ( $data->module->peers as &$peer ) {
|
||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $peer );
|
||||
$this->makeLink( $parserOutput, $peer, $title );
|
||||
}
|
||||
}
|
||||
foreach ( $data->module->messages as &$msg ) {
|
||||
$title = Title::makeTitleSafe( NS_MEDIAWIKI, $msg );
|
||||
$this->makeLink( $parserOutput, $msg, $title );
|
||||
if ( isset( $data->module->messages ) ) {
|
||||
foreach ( $data->module->messages as &$msg ) {
|
||||
$title = Title::makeTitleSafe( NS_MEDIAWIKI, $msg );
|
||||
$this->makeLink( $parserOutput, $msg, $title );
|
||||
}
|
||||
}
|
||||
if ( $data->settings->category ) {
|
||||
if ( isset( $data->settings->category ) && $data->settings->category ) {
|
||||
$this->makeLink(
|
||||
$parserOutput,
|
||||
$data->settings->category,
|
||||
|
|
|
@ -129,7 +129,10 @@ class GadgetDefinitionNamespaceRepo extends GadgetRepo {
|
|||
return null;
|
||||
}
|
||||
|
||||
return Gadget::serializeDefinition( $id, $content->getAssocArray() );
|
||||
$handler = $content->getContentHandler();
|
||||
'@phan-var \MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContentHandler $handler';
|
||||
$data = wfArrayPlus2d( $content->getAssocArray(), $handler->getDefaultMetadata() );
|
||||
return Gadget::serializeDefinition( $id, $data );
|
||||
},
|
||||
[
|
||||
'checkKeys' => [ $key ],
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace phpunit\integration;
|
||||
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use MediaWikiIntegrationTestCase;
|
||||
|
||||
/**
|
||||
* @covers \MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContentHandler
|
||||
* @covers \MediaWiki\Extension\Gadgets\Content\GadgetDefinitionContent
|
||||
* @group Gadgets
|
||||
* @group Database
|
||||
*/
|
||||
class GadgetDefinitionContentHandlerTest extends MediaWikiIntegrationTestCase {
|
||||
|
||||
public function testHandler() {
|
||||
$status = $this->editPage( 'Gadget definition:X1', '{}' );
|
||||
/** @var RevisionRecord $rev */
|
||||
$rev = $status->getValue()['revision-record'];
|
||||
$revText = $rev->getContent( SlotRecord::MAIN )->serialize();
|
||||
$handler = $this->getServiceContainer()->getContentHandlerFactory()->getContentHandler( 'GadgetDefinition' );
|
||||
$this->assertEquals( $handler->makeEmptyContent()->serialize(), $revText );
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue