Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ArticleTopicsDefinition | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| getTopics | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare( strict_types = 1 ); |
| 4 | |
| 5 | namespace ContentTranslation; |
| 6 | |
| 7 | use MediaWiki\Extension\WikimediaMessages\ArticleTopicFiltersRegistry; |
| 8 | use MediaWiki\ResourceLoader\Context; |
| 9 | |
| 10 | class ArticleTopicsDefinition { |
| 11 | |
| 12 | /** |
| 13 | * Get the article topic filters definition, organized into groups |
| 14 | * with their associated articletopics and labels. |
| 15 | * |
| 16 | * @param Context $context |
| 17 | * @return array |
| 18 | * [ |
| 19 | * [ |
| 20 | * 'groupId' => string, |
| 21 | * 'label' => string, |
| 22 | * 'topics' => [ |
| 23 | * [ |
| 24 | * 'topicId' => string, |
| 25 | * 'label' => string, |
| 26 | * 'articletopics' => string[] |
| 27 | * ], |
| 28 | * ] |
| 29 | * ], |
| 30 | * ] |
| 31 | */ |
| 32 | public static function getTopics( Context $context ) { |
| 33 | $groupedTopics = ArticleTopicFiltersRegistry::getGroupedTopics(); |
| 34 | |
| 35 | $groupsDefinitions = []; |
| 36 | |
| 37 | foreach ( $groupedTopics as $topicGroup ) { |
| 38 | if ( $topicGroup['groupId'] === 'geography' ) { |
| 39 | // Skip the group since we're using articlecountry instead |
| 40 | continue; |
| 41 | } |
| 42 | $topicsDefinitions = []; |
| 43 | |
| 44 | foreach ( $topicGroup['topics'] as $topicData ) { |
| 45 | $topicsDefinitions[] = [ |
| 46 | 'topicId' => $topicData['topicId'], |
| 47 | 'label' => $context->msg( $topicData['msgKey'] )->text(), |
| 48 | 'articletopics' => $topicData['articleTopics'], |
| 49 | ]; |
| 50 | } |
| 51 | |
| 52 | usort( |
| 53 | $topicsDefinitions, |
| 54 | static fn ( array $a, array $b ) => strnatcasecmp( $a['label'], $b['label'] ) |
| 55 | ); |
| 56 | |
| 57 | $groupsDefinitions[] = [ |
| 58 | 'groupId' => $topicGroup['groupId'], |
| 59 | 'label' => $context->msg( $topicGroup['msgKey'] )->text(), |
| 60 | 'topics' => $topicsDefinitions, |
| 61 | ]; |
| 62 | } |
| 63 | |
| 64 | return $groupsDefinitions; |
| 65 | } |
| 66 | } |