--- a/Command/QueryWikipediaCommand.php Fri Nov 25 18:55:42 2011 +0100
+++ b/Command/QueryWikipediaCommand.php Sun Nov 27 22:36:21 2011 +0100
@@ -11,6 +11,7 @@
use IRI\Bundle\WikiTagBundle\Utils\WikiTagUtils;
+use IRI\Bundle\WikiTagBundle\Model\Tag;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
@@ -41,7 +42,8 @@
->setName('wikitag:query-wikipedia')
->setDescription('Query wikipedia for tags.')
->addOption("force","f",InputOption::VALUE_NONE, "Force remove tags")
- ->addOption("all","a",InputOption::VALUE_NONE, "Force remove tags")
+ ->addOption("all","a",InputOption::VALUE_NONE, "all")
+ ->addOption("redirection",null,InputOption::VALUE_NONE, "Treat redirections")
->addOption("random","r",InputOption::VALUE_NONE, "randomize query on tags")
->addOption("site","S",InputOption::VALUE_OPTIONAL, "the url for the wikipedia site", "http://fr.wikipedia.org/w/api.php")
->addOption("limit","l",InputOption::VALUE_OPTIONAL, "number of tag to process", -1)
@@ -54,6 +56,7 @@
$force = $input->getOption('force');
$all = $input->getOption('all');
$random = $input->getOption('random');
+ $redirection = $input->getOption('redirection');
$site = $input->getOption('site');
$limit = intval($input->getOption('limit'));
$start = intval($input->getOption('start'));
@@ -66,7 +69,12 @@
if(!$all)
{
- $qb->where($qb->expr()->isNull("t.urlStatus"));
+ if($redirection) {
+ $qb->where($qb->expr()->andx($qb->expr()->eq("t.urlStatus",Tag::$TAG_URL_STATUS_DICT['redirection']), $qb->expr()->isNull("t.alternativeLabel")));
+ }
+ else {
+ $qb->where($qb->expr()->isNull("t.urlStatus"));
+ }
}
if($start > 0)
@@ -86,6 +94,12 @@
$count = count($qb_count->getQuery()->getScalarResult());
$doctrine->getEntityManager()->clear();
+ if($count === 0)
+ {
+ $output->writeln("No tag to process, exit.");
+ return;
+ }
+
if(! $force && $input->isInteractive())
{
$dialog = $this->getHelper('dialog');
--- a/Controller/WikiTagController.php Fri Nov 25 18:55:42 2011 +0100
+++ b/Controller/WikiTagController.php Sun Nov 27 22:36:21 2011 +0100
@@ -45,15 +45,17 @@
/**
* Renders the little html to add the javascript
- * TODO: review why this injection in javascript, t10n?
+ *
+ * @param unknown_type $tags_list
+ * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
- public function addJavascriptAction($tags_list=FALSE)
+ public function addJavascriptAction($tags_list=false)
{
$cats = $this->getDoctrine()->getRepository('WikiTagBundle:Category')->findOrderedCategories();
// $cats is {"Label":"Créateur"},{"Label":"Datation"},...
$nbCats = count($cats);
$ar = array('' => '');
- for($i=0;$i<$nbCats;$i++){
+ for($i=0;$i<$nbCats;$i++) {
$temp = array($cats[$i]["label"] => $cats[$i]["label"]);
$ar = array_merge($ar, $temp);
}
@@ -138,8 +140,7 @@
}
/**
- *
- * TODO: Enter description here ...
+ * Action to remove a tag from a document tag list
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function removeTagFromListAction()
@@ -148,7 +149,6 @@
$id_tag = $this->getRequest()->request->get('tag_id');
// We get the DocumentTag meant to be deleted, and remove it.
$em = $this->getDoctrine()->getEntityManager();
- //TODO: use external id
$dt = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOneByDocumentExternalId($id_doc, array('tag' => $id_tag));
$em->remove($dt);
@@ -281,7 +281,6 @@
// The result is a double array. And reset(reset($newOrderAr)) is not allowed. And a string is returned.
$a1 = reset($new_order_ar);
$new_order = intval(reset($a1)) + 1;
- // TODO: use a factory that returns an DocumentTagInterface
$new_DT = new DocumentTag();
$new_DT->setDocument($this->getDoctrine()->getRepository('WikiTagBundle:Document')->findOneByExternalId($id_doc));
$new_DT->setTag($tag);
@@ -297,8 +296,8 @@
/**
+ * Action to remove the wikipedia link form a tag. This action create a copy of the original tag with all the link to wikipedia set to null.
*
- * TODO: Enter description here ...
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function removeWpLinkAction()
@@ -313,19 +312,21 @@
$un_tag_created = FALSE;
if(!$un_tag){
// Create another tag almost identical, without the W info
- // TODO: use a factory that return a TagInterface
$un_tag = new Tag();
$un_tag->setLabel($tag->getLabel());
$un_tag->setOriginalLabel($tag->getOriginalLabel());
$un_tag->setUrlStatus(Tag::$TAG_URL_STATUS_DICT['null_result']);
$un_tag->setWikipediaUrl(null);
$un_tag->setWikipediaPageId(null);
+ $un_tag->setAlternativeWikipediaUrl(null);
+ $un_tag->setAlternativeWikipediaPageId(null);
+ $un_tag->setAlternativeLabel(null);
$un_tag->setDbpediaUri(null);
$un_tag->setCategory($tag->getCategory());
$un_tag->setAlias($tag->getAlias());
$un_tag->setPopularity($tag->getPopularity());
$em->persist($un_tag);
- $un_tag_created = TRUE;
+ $un_tag_created = true;
}
if($id_doc && $id_doc!=""){
@@ -354,8 +355,8 @@
/**
- *
- * TODO: Enter description here ...
+ * Action to update a tag category.
+ * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function updateTagCategoryAction()
{
@@ -401,9 +402,8 @@
/**
- *
- * TODO : Enter description here ...
- * TODO : implement
+ * Action to update the tag alias.
+ *
* @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function updateTagAliasAction()
@@ -432,8 +432,9 @@
}
/**
- * List of all tags
- * TODO: Enter description here ...
+ * List all tags, with pagination and search.
+ *
+ * @return \Symfony\Bundle\FrameworkBundle\Controller\Response
*/
public function allTagsAction()
{
--- a/Model/Tag.php Fri Nov 25 18:55:42 2011 +0100
+++ b/Model/Tag.php Sun Nov 27 22:36:21 2011 +0100
@@ -427,12 +427,12 @@
$alternative_pageid = array_key_exists('alternative_pageid', $wikipedia_info) ? $wikipedia_info['alternative_pageid'] : null;
# We save the datas
- if($new_label!=null)
+ if(! is_null($new_label))
{
$this->setLabel($new_label);
}
- if($status!=null)
+ if(! is_null($status))
{
$this->setUrlStatus($status);
}
--- a/Utils/WikiTagUtils.php Fri Nov 25 18:55:42 2011 +0100
+++ b/Utils/WikiTagUtils.php Sun Nov 27 22:36:21 2011 +0100
@@ -22,19 +22,30 @@
}
$tag_label = trim($tag_label);//tag.strip()
$tag_label = str_replace("_", " ", $tag_label);//tag.replace("_", " ")
- $tag_label = str_replace("Œ", "oe", $tag_label);
- $tag_label = str_replace("œ", "oe", $tag_label);
- $tag_label = preg_replace('/\s+/', ' ', $tag_label);//" ".join(tag.split())
+ $tag_label = preg_replace('/\s+/u', ' ', $tag_label);//" ".join(tag.split())
$tag_label = ucfirst($tag_label);//tag[0].upper() + tag[1:]
return $tag_label;
}
/**
+ * Query wikipedia with a normalized label or a pageid
+ * return an array with the form
+ * array(
+ * 'new_label'=>$new_label,
+ * 'alternative_label'=>$alternative_label,
+ * 'status'=>$status,
+ * 'wikipedia_url'=>$url,
+ * 'wikipedia_alternative_url'=>$alternative_url,
+ * 'pageid'=>$pageid,
+ * 'alternative_pageid'=>$alternative_pageid,
+ * 'dbpedia_uri'=>$dbpedia_uri,
+ * 'revision_id'=> ,
+ * 'response'=> the original wikipedia json response
+ * )
*
- * TODO: Enter description here ...
- * @param unknown_type $tag_label_normalized
- * @param unknown_type $page_id
- * @return multitype:NULL unknown |multitype:Ambigous <NULL, unknown> multitype:number mixed Ambigous <NULL, string> Ambigous <unknown, mixed>
+ * @param string $tag_label_normalized
+ * @param bigint $page_id
+ * @return array
*/
public static function getWikipediaInfo($tag_label_normalized, $page_id=null)
{
@@ -86,7 +97,6 @@
$alternative_pageid = null;
if($status==Tag::$TAG_URL_STATUS_DICT["redirection"])
{
- //TODO: add alternative label
$params['redirects'] = "true";
$ar = WikiTagUtils::requestWikipedia($params);
$res = $ar[0];
@@ -139,10 +149,10 @@
/**
+ * build and do the request to Wikipedia.
*
- * TODO : Enter description here ...
- * @param unknown_type $params
- * @return multitype:unknown mixed
+ * @param array $params
+ * @return array
*/
private static function requestWikipedia($params)
{