20 if(strlen($tag_label)==0){ |
20 if(strlen($tag_label)==0){ |
21 return $tag_label; |
21 return $tag_label; |
22 } |
22 } |
23 $tag_label = trim($tag_label);//tag.strip() |
23 $tag_label = trim($tag_label);//tag.strip() |
24 $tag_label = str_replace("_", " ", $tag_label);//tag.replace("_", " ") |
24 $tag_label = str_replace("_", " ", $tag_label);//tag.replace("_", " ") |
25 $tag_label = str_replace("Œ", "oe", $tag_label); |
25 $tag_label = preg_replace('/\s+/u', ' ', $tag_label);//" ".join(tag.split()) |
26 $tag_label = str_replace("œ", "oe", $tag_label); |
|
27 $tag_label = preg_replace('/\s+/', ' ', $tag_label);//" ".join(tag.split()) |
|
28 $tag_label = ucfirst($tag_label);//tag[0].upper() + tag[1:] |
26 $tag_label = ucfirst($tag_label);//tag[0].upper() + tag[1:] |
29 return $tag_label; |
27 return $tag_label; |
30 } |
28 } |
31 |
29 |
32 /** |
30 /** |
|
31 * Query wikipedia with a normalized label or a pageid |
|
32 * return an array with the form |
|
33 * array( |
|
34 * 'new_label'=>$new_label, |
|
35 * 'alternative_label'=>$alternative_label, |
|
36 * 'status'=>$status, |
|
37 * 'wikipedia_url'=>$url, |
|
38 * 'wikipedia_alternative_url'=>$alternative_url, |
|
39 * 'pageid'=>$pageid, |
|
40 * 'alternative_pageid'=>$alternative_pageid, |
|
41 * 'dbpedia_uri'=>$dbpedia_uri, |
|
42 * 'revision_id'=> , |
|
43 * 'response'=> the original wikipedia json response |
|
44 * ) |
33 * |
45 * |
34 * TODO: Enter description here ... |
46 * @param string $tag_label_normalized |
35 * @param unknown_type $tag_label_normalized |
47 * @param bigint $page_id |
36 * @param unknown_type $page_id |
48 * @return array |
37 * @return multitype:NULL unknown |multitype:Ambigous <NULL, unknown> multitype:number mixed Ambigous <NULL, string> Ambigous <unknown, mixed> |
|
38 */ |
49 */ |
39 public static function getWikipediaInfo($tag_label_normalized, $page_id=null) |
50 public static function getWikipediaInfo($tag_label_normalized, $page_id=null) |
40 { |
51 { |
41 $params = array('action'=>'query', 'prop'=>'info|categories|langlinks', 'inprop'=>'url', 'lllimit'=>'500', 'cllimit'=>'500', 'rvprop'=>'ids', 'format'=>'json'); |
52 $params = array('action'=>'query', 'prop'=>'info|categories|langlinks', 'inprop'=>'url', 'lllimit'=>'500', 'cllimit'=>'500', 'rvprop'=>'ids', 'format'=>'json'); |
42 if($tag_label_normalized!=null){ |
53 if($tag_label_normalized!=null){ |
84 $alternative_label = null; |
95 $alternative_label = null; |
85 $alternative_url = null; |
96 $alternative_url = null; |
86 $alternative_pageid = null; |
97 $alternative_pageid = null; |
87 if($status==Tag::$TAG_URL_STATUS_DICT["redirection"]) |
98 if($status==Tag::$TAG_URL_STATUS_DICT["redirection"]) |
88 { |
99 { |
89 //TODO: add alternative label |
|
90 $params['redirects'] = "true"; |
100 $params['redirects'] = "true"; |
91 $ar = WikiTagUtils::requestWikipedia($params); |
101 $ar = WikiTagUtils::requestWikipedia($params); |
92 $res = $ar[0]; |
102 $res = $ar[0]; |
93 $pages = $ar[1]; |
103 $pages = $ar[1]; |
94 #we know that we have at least one answer |
104 #we know that we have at least one answer |