@@ -167,26 +167,25 @@ function get_links($lang, $page, $wgRequest,
167
167
for ($ i =0 ; $ i <=(count ($ links1 )/10 ); $ i ++) {
168
168
$ current_pages = array_slice ($ links1 , $ i *10 , 10 , true );
169
169
$ base = "http:// " .$ lang1 .".wikipedia.org/w/api.php?action=query&prop=langlinks&titles= " .
170
- urlencode (implode ("| " , $ current_pages ))."&lllimit=500&redirects&format=json " ;
170
+ urlencode (implode ("| " , $ current_pages ))."&lllimit=500&redirects&format=json " ;
171
171
$ cont = true ;
172
172
$ url = $ base ;
173
173
174
174
while ($ cont ) {
175
175
$ data = json_decode (file_get_contents ($ url ), true );
176
176
//populate result
177
177
foreach ($ data ["query " ]["pages " ] as $ id => $ elem ) {
178
- $ added = false ;
178
+ $ title = urlencode ( $ elem [ " title " ]) ;
179
179
if (array_key_exists ("langlinks " , $ elem )) {
180
180
foreach ($ elem ["langlinks " ] as $ ll ) {
181
181
if ($ ll ["lang " ] == $ lang2 ) {
182
- $ result [$ elem ["title " ]] = str_replace (" " , "_ " , $ ll ["* " ]);
183
- $ added = true ;
182
+ $ result [$ title ] = str_replace (" " , "_ " , $ ll ["* " ]);
184
183
break ;
185
184
}
186
185
}
187
186
}
188
- if (!$ added ) {
189
- $ result [$ elem [ " title " ] ] = str_replace (" " , "_ " , $ elem ["title " ]);
187
+ if (!array_key_exists ( $ title , $ result ) ) {
188
+ $ result [$ title ] = str_replace (" " , "_ " , $ elem ["title " ]);
190
189
}
191
190
}
192
191
@@ -228,6 +227,7 @@ function get_links($lang, $page, $wgRequest,
228
227
//check for matching links
229
228
$ match = 0 ;
230
229
foreach ($ result as $ original => $ langlink ) {
230
+ $ original = urldecode ($ original );
231
231
if (in_array ($ langlink , $ links2 )) {
232
232
if (!$ swapped ) {
233
233
$ output ["matching " ][] = array ($ original , $ langlink );
@@ -270,10 +270,16 @@ function get_links($lang, $page, $wgRequest,
270
270
271
271
$ output ["result " ] = $ res ;
272
272
$ output ["exectime " ] = $ exectime ;
273
- $ output ["l1 " ] = $ lang1 ;
274
273
$ output ["a1 " ] = $ article1 ;
275
- $ output ["l2 " ] = $ lang2 ;
276
274
$ output ["a2 " ] = $ article2 ;
275
+ if (!$ swapped ) {
276
+ $ output ["l1 " ] = $ lang1 ;
277
+ $ output ["l2 " ] = $ lang2 ;
278
+ }
279
+ else {
280
+ $ output ["l1 " ] = $ lang2 ;
281
+ $ output ["l2 " ] = $ lang1 ;
282
+ }
277
283
print_result ($ output );
278
284
279
285
?>
0 commit comments