mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Gadgets
synced 2024-11-30 18:14:21 +00:00
Merge "Avoid persisting default gadget configs in definitions"
This commit is contained in:
commit
cc4efec689
|
@ -63,7 +63,7 @@ class GadgetDefinitionContent extends JsonContent {
|
||||||
$this->validation = $this->getData();
|
$this->validation = $this->getData();
|
||||||
} else {
|
} else {
|
||||||
$validator = new GadgetDefinitionValidator();
|
$validator = new GadgetDefinitionValidator();
|
||||||
$this->validation = $validator->validate( $this->getAssocArray() );
|
$this->validation = $validator->validate( $this->getAssocArray(), true );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->validation;
|
return $this->validation;
|
||||||
|
@ -80,7 +80,7 @@ class GadgetDefinitionContent extends JsonContent {
|
||||||
$info = wfObjectToArray( $this->getData()->getValue() );
|
$info = wfObjectToArray( $this->getData()->getValue() );
|
||||||
/** @var GadgetDefinitionContentHandler $handler */
|
/** @var GadgetDefinitionContentHandler $handler */
|
||||||
$handler = $this->getContentHandler();
|
$handler = $this->getContentHandler();
|
||||||
$info = wfArrayPlus2d( $info, $handler->getDefaultMetadata() );
|
$info = wfArrayPlus2d( $info, $handler->getEmptyDefinition() );
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,19 @@ class GadgetDefinitionContentHandler extends JsonContentHandler {
|
||||||
|
|
||||||
public function makeEmptyContent() {
|
public function makeEmptyContent() {
|
||||||
$class = $this->getContentClass();
|
$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() {
|
public function getDefaultMetadata() {
|
||||||
|
@ -95,22 +107,28 @@ class GadgetDefinitionContentHandler extends JsonContentHandler {
|
||||||
$this->makeLink( $parserOutput, $page, $title );
|
$this->makeLink( $parserOutput, $page, $title );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ( isset( $data->module->dependencies ) ) {
|
||||||
foreach ( $data->module->dependencies as &$dep ) {
|
foreach ( $data->module->dependencies as &$dep ) {
|
||||||
if ( str_starts_with( $dep, 'ext.gadget.' ) ) {
|
if ( str_starts_with( $dep, 'ext.gadget.' ) ) {
|
||||||
$gadgetId = explode( 'ext.gadget.', $dep )[1];
|
$gadgetId = explode( 'ext.gadget.', $dep )[ 1 ];
|
||||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadgetId );
|
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $gadgetId );
|
||||||
$this->makeLink( $parserOutput, $dep, $title );
|
$this->makeLink( $parserOutput, $dep, $title );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( isset( $data->module->peers ) ) {
|
||||||
foreach ( $data->module->peers as &$peer ) {
|
foreach ( $data->module->peers as &$peer ) {
|
||||||
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $peer );
|
$title = Title::makeTitleSafe( NS_GADGET_DEFINITION, $peer );
|
||||||
$this->makeLink( $parserOutput, $peer, $title );
|
$this->makeLink( $parserOutput, $peer, $title );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if ( isset( $data->module->messages ) ) {
|
||||||
foreach ( $data->module->messages as &$msg ) {
|
foreach ( $data->module->messages as &$msg ) {
|
||||||
$title = Title::makeTitleSafe( NS_MEDIAWIKI, $msg );
|
$title = Title::makeTitleSafe( NS_MEDIAWIKI, $msg );
|
||||||
$this->makeLink( $parserOutput, $msg, $title );
|
$this->makeLink( $parserOutput, $msg, $title );
|
||||||
}
|
}
|
||||||
if ( $data->settings->category ) {
|
}
|
||||||
|
if ( isset( $data->settings->category ) && $data->settings->category ) {
|
||||||
$this->makeLink(
|
$this->makeLink(
|
||||||
$parserOutput,
|
$parserOutput,
|
||||||
$data->settings->category,
|
$data->settings->category,
|
||||||
|
|
|
@ -129,7 +129,10 @@ class GadgetDefinitionNamespaceRepo extends GadgetRepo {
|
||||||
return null;
|
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 ],
|
'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