Skip to content

Commit 5a840f3

Browse files
committed
arabic character issue fixed
1 parent bce85ba commit 5a840f3

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

php/api_comparison.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,26 +167,25 @@ function get_links($lang, $page, $wgRequest,
167167
for ($i=0; $i<=(count($links1)/10); $i++) {
168168
$current_pages = array_slice($links1, $i*10, 10, true);
169169
$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";
171171
$cont = true;
172172
$url = $base;
173173

174174
while ($cont) {
175175
$data = json_decode(file_get_contents($url), true);
176176
//populate result
177177
foreach ($data["query"]["pages"] as $id => $elem) {
178-
$added = false;
178+
$title = urlencode($elem["title"]);
179179
if (array_key_exists("langlinks", $elem)) {
180180
foreach ($elem["langlinks"] as $ll) {
181181
if ($ll["lang"] == $lang2) {
182-
$result[$elem["title"]] = str_replace(" ", "_", $ll["*"]);
183-
$added = true;
182+
$result[$title] = str_replace(" ", "_", $ll["*"]);
184183
break;
185184
}
186185
}
187186
}
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"]);
190189
}
191190
}
192191

@@ -228,6 +227,7 @@ function get_links($lang, $page, $wgRequest,
228227
//check for matching links
229228
$match = 0;
230229
foreach ($result as $original => $langlink) {
230+
$original = urldecode($original);
231231
if (in_array($langlink, $links2)) {
232232
if (!$swapped) {
233233
$output["matching"][] = array($original, $langlink);
@@ -270,10 +270,16 @@ function get_links($lang, $page, $wgRequest,
270270

271271
$output["result"] = $res;
272272
$output["exectime"] = $exectime;
273-
$output["l1"] = $lang1;
274273
$output["a1"] = $article1;
275-
$output["l2"] = $lang2;
276274
$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+
}
277283
print_result($output);
278284

279285
?>

0 commit comments

Comments
 (0)