Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 103 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ArticleTopicsDefinition | |
0.00% |
0 / 103 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
getTopics | |
0.00% |
0 / 103 |
|
0.00% |
0 / 1 |
30 |
1 | <?php |
2 | |
3 | declare( strict_types = 1 ); |
4 | |
5 | namespace ContentTranslation; |
6 | |
7 | use MediaWiki\ResourceLoader\Context; |
8 | |
9 | class ArticleTopicsDefinition { |
10 | |
11 | /** |
12 | * Get the article topics definition, organized into groups |
13 | * with their associated ORES topics and labels. |
14 | * |
15 | * @param Context $context |
16 | * @return array |
17 | * [ |
18 | * [ |
19 | * 'groupId' => string, |
20 | * 'label' => string, |
21 | * 'topics' => [ |
22 | * [ |
23 | * 'topicId' => string, |
24 | * 'label' => string, |
25 | * 'orestopics' => string[] |
26 | * ], |
27 | * ] |
28 | * ], |
29 | * ] |
30 | */ |
31 | public static function getTopics( Context $context ) { |
32 | $groupsTopicsOrestopics = [ |
33 | 'geography' => [ |
34 | 'africa' => [ |
35 | 'africa', |
36 | 'central-africa', |
37 | 'eastern-africa', |
38 | 'northern-africa', |
39 | 'southern-africa', |
40 | 'western-africa', |
41 | ], |
42 | 'asia' => [ |
43 | 'asia', |
44 | 'central-asia', |
45 | 'east-asia', |
46 | 'south-asia', |
47 | 'southeast-asia', |
48 | 'west-asia', |
49 | ], |
50 | 'central-america', |
51 | 'north-america', |
52 | 'south-america', |
53 | 'europe' => [ |
54 | 'north-asia', // !? |
55 | 'europe', |
56 | 'eastern-europe', |
57 | 'northern-europe', |
58 | 'southern-europe', |
59 | 'western-europe', |
60 | ], |
61 | 'oceania', |
62 | ], |
63 | 'culture' => [ |
64 | 'architecture', |
65 | 'art' => 'visual-arts', |
66 | 'comics-and-anime', |
67 | 'entertainment' => [ |
68 | 'entertainment', |
69 | 'radio', |
70 | ], |
71 | 'fashion', |
72 | 'literature' => 'books', |
73 | 'music', |
74 | 'performing-arts', |
75 | 'sports', |
76 | 'tv-and-film' => [ 'films', 'television' ], |
77 | 'video-games', |
78 | ], |
79 | 'history-and-society' => [ |
80 | 'biography', |
81 | 'business-and-economics', |
82 | 'education', |
83 | 'food-and-drink', |
84 | 'history', |
85 | 'military-and-warfare', |
86 | 'philosophy-and-religion', |
87 | 'politics-and-government', |
88 | 'society', |
89 | 'transportation', |
90 | 'women', |
91 | ], |
92 | 'science-technology-and-math' => [ |
93 | 'biology', |
94 | 'chemistry', |
95 | 'computers-and-internet' => [ |
96 | 'internet-culture', |
97 | 'computing', |
98 | 'software', |
99 | ], |
100 | 'earth-and-environment' => [ |
101 | 'geographical', |
102 | 'earth-and-environment', |
103 | ], |
104 | 'engineering', |
105 | 'general-science' => 'stem', |
106 | 'mathematics', |
107 | 'medicine-and-health', |
108 | 'physics' => [ |
109 | 'physics', |
110 | 'space', |
111 | ], |
112 | 'technology', |
113 | ], |
114 | ]; |
115 | |
116 | $groupsDefinitions = []; |
117 | |
118 | foreach ( $groupsTopicsOrestopics as $groupId => $topics ) { |
119 | $topicsDefinitions = []; |
120 | |
121 | foreach ( $topics as $key => $value ) { |
122 | // If there is 1-1 match between topic and ORES topic then the |
123 | // array entry is a single value with a numeric key so |
124 | // the topic id is actually the value and the ORES topic is wrapped |
125 | // in an array for consistency. |
126 | if ( is_numeric( $key ) ) { |
127 | $topicId = $value; |
128 | $oresTopics = [ $value ]; |
129 | } else { |
130 | $topicId = $key; |
131 | $oresTopics = is_array( $value ) ? $value : [ $value ]; |
132 | } |
133 | |
134 | $topicsDefinitions[] = [ |
135 | 'topicId' => $topicId, |
136 | 'label' => $context->msg( 'cx-articletopics-topic-' . $topicId )->text(), |
137 | 'orestopics' => $oresTopics, |
138 | ]; |
139 | } |
140 | |
141 | $groupsDefinitions[] = [ |
142 | 'groupId' => $groupId, |
143 | 'label' => $context->msg( 'cx-articletopics-group-' . $groupId )->text(), |
144 | 'topics' => $topicsDefinitions, |
145 | ]; |
146 | } |
147 | |
148 | return $groupsDefinitions; |
149 | } |
150 | } |