first change for wikipedia and dbpedia lang configuration
authorcavaliet
Fri, 24 Jan 2014 17:43:38 +0100
changeset 112 14653baf4f6b
parent 111 fef492d144f4
child 113 83368005f790
first change for wikipedia and dbpedia lang configuration
Controller/WikiTagController.php
DependencyInjection/Configuration.php
DependencyInjection/WikiTagExtension.php
Model/DocumentTag.php
README.md
Resources/public/js/wikiTag.js
Resources/views/WikiTag/TagListTable.html.twig
Resources/views/WikiTag/javascript.html.twig
Resources/views/WikiTag/tagTable.html.twig
Utils/WikiTagUtils.php
--- a/Controller/WikiTagController.php	Fri Aug 24 13:16:41 2012 +0200
+++ b/Controller/WikiTagController.php	Fri Jan 24 17:43:38 2014 +0100
@@ -69,7 +69,12 @@
             $columns_array = $profile_array[$profile_name];
         }
         
-        return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', array('categories' => $categories, 'tags_list' => $tags_list, 'columns' => $columns_array, 'read_only' => $read_only));
+        return $this->render('WikiTagBundle:WikiTag:javascript.html.twig', 
+        		array('wikipedia_api_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_api"], 
+        				'categories' => $categories, 
+        				'tags_list' => $tags_list, 
+        				'columns' => $columns_array, 
+        				'read_only' => $read_only));
     }
 
     /**
@@ -109,7 +114,12 @@
         
         $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
         //$ordered_tags = null;
-        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => $columns_array, 'profile_name' => $profile_name));
+        return $this->render('WikiTagBundle:WikiTag:documentTags.html.twig', 
+        		array('ordered_tags' => $ordered_tags, 
+        				'doc_id' => $id_doc, 
+        				'columns' => $columns_array, 
+        				'profile_name' => $profile_name,
+        				'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
     }
 
     /**
@@ -398,7 +408,12 @@
             $columns_array = $profile_array[$profile_name];
         }
         $ordered_tags = $this->getDoctrine()->getRepository('WikiTagBundle:DocumentTag')->findOrderedTagsForDoc($id_doc);
-        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', array('ordered_tags' => $ordered_tags, 'doc_id' => $id_doc, 'columns' => $columns_array, 'profile_name' => $profile_name));
+        return $this->render('WikiTagBundle:WikiTag:tagTable.html.twig', 
+        		array('ordered_tags' => $ordered_tags, 
+        				'doc_id' => $id_doc, 
+        				'columns' => $columns_array, 
+        				'profile_name' => $profile_name,
+        				'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
     }
 
 
@@ -493,9 +508,21 @@
         }
         
         return $this->render('WikiTagBundle:WikiTag:TagList.html.twig',
-            array('tags' => $tags, 'searched' => $searched, 'search_def' => $search_def, 'nb_by_page' => $nb_by_page, 'sort' => $sort,
-            'start_index' => $start_index, 'end_index' => $end_index, 'nb_total' => $nb_total, 'num_page' => $num_page, 'last_page' => $last_page,
-        	'prev_page' => $prev_page, 'next_page' => $next_page, 'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
+            array('tags' => $tags, 
+            		'searched' => $searched, 
+            		'search_def' => $search_def, 
+            		'nb_by_page' => $nb_by_page, 
+            		'sort' => $sort,
+            		'start_index' => $start_index, 
+            		'end_index' => $end_index, 
+            		'nb_total' => $nb_total, 
+            		'num_page' => $num_page, 
+            		'last_page' => $last_page,
+        			'prev_page' => $prev_page, 
+            		'next_page' => $next_page, 
+            		'reverse_sort' => $reverse_sort, 
+            		'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"),
+            		'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
     }
 
     /**
@@ -605,8 +632,14 @@
         $reverse_sort = $ar[5];
         
         return $this->render('WikiTagBundle:WikiTag:TagListTable.html.twig',
-            array('tags' => $tags, 'searched' => $searched, 'nb_by_page' => $nb_by_page, 'sort' => $sort, 'num_page' => $num_page,
-        	'reverse_sort' => $reverse_sort, 'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag")));
+            array('tags' => $tags, 
+            		'searched' => $searched, 
+            		'nb_by_page' => $nb_by_page, 
+            		'sort' => $sort, 
+            		'num_page' => $num_page,
+        			'reverse_sort' => $reverse_sort, 
+            		'route_for_documents_by_tag' => $this->container->getParameter("wiki_tag.route_for_documents_by_tag"),
+            		'wikipedia_opensearch_url' => $this->container->getParameter("wiki_tag.url_templates")["wikipedia_opensearch"]));
     }
 
     /**
--- a/DependencyInjection/Configuration.php	Fri Aug 24 13:16:41 2012 +0200
+++ b/DependencyInjection/Configuration.php	Fri Jan 24 17:43:38 2014 +0100
@@ -61,6 +61,12 @@
                         ->end()
                     ->end()
                 ->end()
+                ->arrayNode('url_templates')
+                    ->treatNullLike(array())
+                    ->useAttributeAsKey('name')
+                    ->prototype('variable')
+                    ->end()
+                ->end()
                 ->arrayNode('reactive_selectors')
                     ->treatNullLike(array())
                     ->useAttributeAsKey('name')
--- a/DependencyInjection/WikiTagExtension.php	Fri Aug 24 13:16:41 2012 +0200
+++ b/DependencyInjection/WikiTagExtension.php	Fri Jan 24 17:43:38 2014 +0100
@@ -58,6 +58,7 @@
         $container->setParameter("wiki_tag.fields", $fields);
         $fields['tagsStr'] = array("type"=>"text");
         $container->setParameter("wiki_tag.fields_all", $fields);
+        $container->setParameter("wiki_tag.url_templates", $config['url_templates']);
         $container->setParameter("wiki_tag.route_for_documents_by_tag", $config['route_for_documents_by_tag']);
         $container->setParameter("wiki_tag.reactive_selectors", $config['reactive_selectors']);
         $container->setParameter("wiki_tag.document_list_profile", $config['document_list_profile']);
--- a/Model/DocumentTag.php	Fri Aug 24 13:16:41 2012 +0200
+++ b/Model/DocumentTag.php	Fri Jan 24 17:43:38 2014 +0100
@@ -214,16 +214,13 @@
     
     
     /**
-    * Get wikipedia_version_permalink
+    * Get wikipedia_version_permalink : DEPRECATED
     *
     * @return string
     */
     public function getWikipediaVersionPermalink()
     {
-        $WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = "http://fr.wikipedia.org/w/index.php?oldid=";
-        return $WIKIPEDIA_VERSION_PERMALINK_TEMPLATE.$this->wikipediaRevisionId;
-    }
-    
-    
+    	return sprintf($GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["wikipedia_permalink"], $this->wikipediaRevisionId);
+	}
     
 }
\ No newline at end of file
--- a/README.md	Fri Aug 24 13:16:41 2012 +0200
+++ b/README.md	Fri Jan 24 17:43:38 2014 +0100
@@ -74,6 +74,25 @@
     accessor: <field name or method name> : the field name in the host app's document class, or the name of the method used to access the field value. If not found it will try ta add 'get' in frint of the name. Default : the field name
     weight: <float> : the weight used for this field to calculate the score of each tag. default : 1.0 
 
+* We can configure WikiTagBundle for it to works with any wikipedia and dbpedia. Just set up the language you want with the url templates. 
+There is no default version so this configuration **has** to be set. Here is an example with german (de) endpoints :
+
+        wiki_tag:
+            [...]
+            url_templates:
+                wikipedia_api: 'http://de.wikipedia.org/w/api.php'
+                wikipedia_permalink: 'http://de.wikipedia.org/w/index.php?oldid=%s'
+                wikipedia_opensearch: 'http://de.wikipedia.org/w/index.php?search='
+                dbpedia: 'http://de.dbpedia.org/resource/%s'
+            
+The 'document_id_column' option is used to indicate the primary key column used by the host app's document class. We are currently limited to non composite primary keys.
+A field definition has the following format:
+<field name>:
+    type: <string or text> : field type. default : text 
+    length: <int> : the length of the field. ignored if field type is text
+    accessor: <field name or method name> : the field name in the host app's document class, or the name of the method used to access the field value. If not found it will try ta add 'get' in frint of the name. Default : the field name
+    weight: <float> : the weight used for this field to calculate the score of each tag. default : 1.0 
+
 * Add the WikiTag routes to your routing.yml :
 
         WikiTagBundle:
--- a/Resources/public/js/wikiTag.js	Fri Aug 24 13:16:41 2012 +0200
+++ b/Resources/public/js/wikiTag.js	Fri Jan 24 17:43:38 2014 +0100
@@ -70,7 +70,7 @@
     	autocomplete : {
 			source: function( request, response ) {
 				$.ajax({
-					url: "http://fr.wikipedia.org/w/api.php",
+					url: wikipedia_api_url,
 					dataType: "jsonp",
 					data: {
 						action: "opensearch",
@@ -189,7 +189,7 @@
     $("#wikitag_wp_search").autocomplete({
         source: function( request, response ) {
             $.ajax({
-                url: "http://fr.wikipedia.org/w/api.php",
+                url: wikipedia_api_url,
                 dataType: "jsonp",
                 data: {
                     action: "opensearch",
@@ -293,7 +293,7 @@
     $("#wikitag_wp_search_context").autocomplete({
         source: function( request, response ) {
             $.ajax({
-                url: "http://fr.wikipedia.org/w/api.php",
+                url: wikipedia_api_url,
                 dataType: "jsonp",
                 data: {
                     action: "query",
--- a/Resources/views/WikiTag/TagListTable.html.twig	Fri Aug 24 13:16:41 2012 +0200
+++ b/Resources/views/WikiTag/TagListTable.html.twig	Fri Jan 24 17:43:38 2014 +0100
@@ -65,7 +65,7 @@
           {% if tag.wikipediaurl and tag.wikipediaurl != ""  %}
             <a class="wikitag_a_icon wikitag_wp_link" href="{{tag.wikipediaurl}}" target="_blank" />
           {% else %}
-            <a class="wikitag_a_icon wikitag_wp_nolink" href="http://fr.wikipedia.org/w/index.php?search={{tag.label}}" target="_blank" />
+            <a class="wikitag_a_icon wikitag_wp_nolink" href="{{wikipedia_opensearch_url}}{{tag.label}}" target="_blank" />
           {% endif %}
         </td>
         <td class="wikitag_text_centered">
--- a/Resources/views/WikiTag/javascript.html.twig	Fri Aug 24 13:16:41 2012 +0200
+++ b/Resources/views/WikiTag/javascript.html.twig	Fri Jan 24 17:43:38 2014 +0100
@@ -20,7 +20,8 @@
 <script type="text/javascript" src="{{ asset('bundles/wikitag/js/wikiTag.js') }}" ></script>
 <script type="text/javascript">
 
-    var global_csrf_token = "{# csrf_token #}";
+    var global_csrf_token = '{# global_csrf_token #}';
+    var wikipedia_api_url = '{{ wikipedia_api_url }}';
     var static_url = "{{ asset('bundles/wikitag/') }}";
     var tag_up_down_url = "{{ url('wikitag_tag_up_down') }}";
     var remove_tag_from_list_url = "{{ url('wikitag_remove_tag_from_list') }}";
--- a/Resources/views/WikiTag/tagTable.html.twig	Fri Aug 24 13:16:41 2012 +0200
+++ b/Resources/views/WikiTag/tagTable.html.twig	Fri Jan 24 17:43:38 2014 +0100
@@ -40,7 +40,7 @@
        {% if t.tag.wikipediaurl and t.tag.wikipediaurl != ""  %}
         <a class="wikitag_a_icon wikitag_wp_link" href="{{t.tag.wikipediaurl}}" target="_blank" />
        {% else %}
-        <a class="wikitag_a_icon wikitag_wp_nolink" href="http://fr.wikipedia.org/w/index.php?search={{t.tag.label}}" target="_blank"></a>
+        <a class="wikitag_a_icon wikitag_wp_nolink" href="{{wikipedia_opensearch_url}}{{t.tag.label}}" target="_blank"></a>
        {% endif %}
       </td>
       <td class="wikitag_text_centered">
--- a/Utils/WikiTagUtils.php	Fri Aug 24 13:16:41 2012 +0200
+++ b/Utils/WikiTagUtils.php	Fri Jan 24 17:43:38 2014 +0100
@@ -13,13 +13,7 @@
 use IRI\Bundle\WikiTagBundle\Entity\Tag;
 
 class WikiTagUtils
-{
-    // Constants
-    private static $WIKIPEDIA_API_URL = "http://fr.wikipedia.org/w/api.php";
-    private static $WIKIPEDIA_VERSION_PERMALINK_TEMPLATE = "http://fr.wikipedia.org/w/index.php?oldid=%s";
-    private static $DBPEDIA_URI_TEMPLATE = "http://dbpedia.org/resource/%s";
-    
-    
+{   
     /**
      * Cleans the tag label
      */
@@ -203,7 +197,9 @@
             }
         }
         
-        $url = WikiTagUtils::$WIKIPEDIA_API_URL.'?'.$params_str;
+        //$url = WikiTagUtils::$WIKIPEDIA_API_URL.'?'.$params_str;
+        //throw new \Exception($GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates"), 1, null);
+        $url = $GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["wikipedia_api"].'?'.$params_str;
         
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, $url);
@@ -271,7 +267,7 @@
      */
     private static function getDbpediaUri($english_label)
     {
-        return sprintf(WikiTagUtils::$DBPEDIA_URI_TEMPLATE, WikiTagUtils::urlize_for_wikipedia($english_label));
+        return sprintf($GLOBALS["kernel"]->getContainer()->getParameter("wiki_tag.url_templates")["dbpedia"], WikiTagUtils::urlize_for_wikipedia($english_label));
     }
     
     /**