diff -r 10be6b9e55e7 -r 774ba82dca59 Utils/WikiTagUtils.php --- a/Utils/WikiTagUtils.php Fri Dec 09 06:43:49 2011 +0100 +++ b/Utils/WikiTagUtils.php Wed Dec 14 23:28:57 2011 +0100 @@ -49,6 +49,15 @@ */ public static function getWikipediaInfo($tag_label_normalized, $page_id=null) { + // get ignore_wikipedia_error parameter + $ignore_wikipedia_error = false; + + if(key_exists('kernel', $GLOBALS)) { + $kernel = $GLOBALS['kernel']; + $ignore_wikipedia_error = $kernel->getContainer()->getParameter('wiki_tag.ignore_wikipedia_error'); + } + + $params = array('action'=>'query', 'prop'=>'info|categories|langlinks', 'inprop'=>'url', 'lllimit'=>'500', 'cllimit'=>'500', 'rvprop'=>'ids', 'format'=>'json'); if($tag_label_normalized!=null){ $params['titles'] = urlencode($tag_label_normalized); @@ -60,7 +69,17 @@ return WikiTagUtils::returnNullResult(null); } - $ar = WikiTagUtils::requestWikipedia($params); + try { + $ar = WikiTagUtils::requestWikipedia($params); + } + catch(\Exception $e) { + if($ignore_wikipedia_error) { + return WikiTagUtils::returnNullResult(null); + } + else { + throw $e; + } + } $res = $ar[0]; $original_response = $res; @@ -99,7 +118,18 @@ if($status==Tag::$TAG_URL_STATUS_DICT["redirection"]) { $params['redirects'] = "true"; - $ar = WikiTagUtils::requestWikipedia($params); + try { + $ar = WikiTagUtils::requestWikipedia($params); + } + catch(\Exception $e) { + if($ignore_wikipedia_error) { + return WikiTagUtils::returnNullResult(null); + } + else { + throw $e; + } + } + $res = $ar[0]; $pages = $ar[1]; #we know that we have at least one answer @@ -144,7 +174,7 @@ 'dbpedia_uri'=>$dbpedia_uri, 'revision_id'=>$revision_id, 'response'=>$original_response); - //return $url."
RES = ".$res/*."
DUMP = ".var_dump($pages)*/."
COUNT = ".count($pages)."
page = ".var_dump($page); + return $wp_response; } @@ -172,6 +202,7 @@ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + //TODO: change curl_setopt($ch, CURLOPT_USERAGENT, 'http://www.iri.centrepompidou.fr'); curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000); $res = curl_exec($ch); @@ -180,7 +211,7 @@ curl_close($ch); if ($curl_errno > 0) { - throw new \Exception("Wikipedia request failed. cURLError #$curl_errno: $curl_error\n"); + throw new \Exception("Wikipedia request failed. cURLError #$curl_errno: $curl_error\n", $curl_errno, null); } $val = json_decode($res, true);