|
6 | 6 | use GrowthExperiments\NewcomerTasks\TaskType\TaskTypeHandlerRegistry;
|
7 | 7 | use GrowthExperiments\NewcomerTasks\TaskType\TemplateBasedTaskTypeHandler;
|
8 | 8 | use GrowthExperiments\NewcomerTasks\Topic\CampaignTopic;
|
| 9 | +use GrowthExperiments\NewcomerTasks\Topic\ITopicRegistry; |
9 | 10 | use GrowthExperiments\NewcomerTasks\Topic\OresBasedTopic;
|
10 | 11 | use GrowthExperiments\NewcomerTasks\Topic\Topic;
|
| 12 | +use GrowthExperiments\NewcomerTasks\Topic\WikimediaTopicRegistry; |
11 | 13 | use InvalidArgumentException;
|
12 | 14 | use LogicException;
|
| 15 | +use MediaWiki\Language\RawMessage; |
13 | 16 | use MediaWiki\Message\Message;
|
14 | 17 | use StatusValue;
|
15 | 18 |
|
@@ -55,19 +58,23 @@ abstract class AbstractDataConfigurationLoader implements ConfigurationLoader {
|
55 | 58 |
|
56 | 59 | /** @var TaskType[]|null */
|
57 | 60 | private ?array $disabledTaskTypes = null;
|
| 61 | + private ITopicRegistry $topicRegistry; |
58 | 62 |
|
59 | 63 | /**
|
60 | 64 | * @param ConfigurationValidator $configurationValidator
|
61 | 65 | * @param TaskTypeHandlerRegistry $taskTypeHandlerRegistry
|
62 | 66 | * @param string $topicType One of the PageConfigurationLoader::CONFIGURATION_TYPE constants.
|
| 67 | + * @param ITopicRegistry $topicRegistry |
63 | 68 | */
|
64 | 69 | public function __construct(
|
65 | 70 | ConfigurationValidator $configurationValidator,
|
66 | 71 | TaskTypeHandlerRegistry $taskTypeHandlerRegistry,
|
67 |
| - string $topicType |
| 72 | + string $topicType, |
| 73 | + ITopicRegistry $topicRegistry |
68 | 74 | ) {
|
69 | 75 | $this->configurationValidator = $configurationValidator;
|
70 | 76 | $this->taskTypeHandlerRegistry = $taskTypeHandlerRegistry;
|
| 77 | + $this->topicRegistry = $topicRegistry; |
71 | 78 | $this->topicType = $topicType;
|
72 | 79 |
|
73 | 80 | if ( !in_array( $this->topicType, self::VALID_TOPIC_TYPES, true ) ) {
|
@@ -156,11 +163,15 @@ public function loadTopics() {
|
156 | 163 | return $this->topics;
|
157 | 164 | }
|
158 | 165 |
|
159 |
| - $config = $this->loadTopicsConfig(); |
160 |
| - if ( $config instanceof StatusValue ) { |
161 |
| - $topics = $config; |
162 |
| - } else { |
163 |
| - $topics = $this->parseTopicsFromConfig( $config ); |
| 166 | + $topics = []; |
| 167 | + // T386018: Handle this more gracefully. Do not allow changing ORES-based topic definitions per wiki. |
| 168 | + if ( $this->topicRegistry instanceof WikimediaTopicRegistry ) { |
| 169 | + $config = $this->loadTopicsConfig(); |
| 170 | + if ( $config instanceof StatusValue ) { |
| 171 | + $topics = $config; |
| 172 | + } else { |
| 173 | + $topics = $this->parseTopicsFromConfig( $config ); |
| 174 | + } |
164 | 175 | }
|
165 | 176 |
|
166 | 177 | $this->topics = $topics;
|
@@ -234,8 +245,13 @@ private function parseTopicsFromConfig( $config ) {
|
234 | 245 | $config = $config['topics'];
|
235 | 246 | }
|
236 | 247 |
|
| 248 | + $validORESTopics = $this->topicRegistry->getAllTopics(); |
237 | 249 | foreach ( $config as $topicId => $topicConfiguration ) {
|
238 | 250 | $status->merge( $this->configurationValidator->validateIdentifier( $topicId ) );
|
| 251 | + if ( !in_array( $topicId, $validORESTopics, true ) ) { |
| 252 | + // T386018: Handle this more gracefully. Do not allow changing ORES-based topic definitions via config. |
| 253 | + $status->fatal( new RawMessage( "'$topicId' is not a valid topic ID." ) ); |
| 254 | + } |
239 | 255 | $requiredFields = [
|
240 | 256 | self::CONFIGURATION_TYPE_ORES => [ 'group', 'oresTopics' ],
|
241 | 257 | ][$this->topicType];
|
|
0 commit comments