Revision: 53813
Author:   mkroetzsch
Date:     2009-07-27 16:25:28 +0000 (Mon, 27 Jul 2009)

Log Message:
-----------
include category information in JSON

Modified Paths:
--------------
    trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php

Modified: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php
===================================================================
--- trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php     
2009-07-27 15:24:14 UTC (rev 53812)
+++ trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php     
2009-07-27 16:25:28 UTC (rev 53813)
@@ -68,6 +68,7 @@
                                                        $prefixedtext = 
$value->getPrefixedText();
                                                }
                                                $valuestack[] = 'label: 
"'.$values.'"';
+                                               $label = $values;
                                        } else {
                                                $values = array();
                                                $finalvalues = '';
@@ -98,6 +99,21 @@
                                        $count++;
                                }
                                $valuestack[] = '"uri" : 
"'.$wgServer.$wgScriptPath.'/index.php?title='.$prefixedtext.'"';
+                               
+                               //try to determine type/category
+                               $catlist = array();
+                               $dbr  = &wfGetDB(DB_SLAVE);
+                               $cl   = $dbr->tableName('categorylinks');
+                               $arttitle   = Title::newFromText($label);
+                               if($arttitle instanceof Title){
+                                       $catid = $arttitle->getArticleID();
+                                       $catres  = $dbr->select($cl, 'cl_to', 
"cl_from = $catid", __METHOD__, array('ORDER BY' => 'cl_sortkey'));
+                                       while ($catrow = 
$dbr->fetchRow($catres)) $catlist[] = $catrow[0];
+                                       $dbr->freeResult($catres);
+                                       if(sizeof($catlist) > 0) $valuestack[] 
= '"type" : "'.$catlist[0].'"';
+                               }
+
+                               //create property list of item
                                $itemstack[] = 
"\t{\n\t\t\t".implode(",\n\t\t\t",$valuestack)."\n\t\t}";
                                $row = $res->getNext();
                        }



_______________________________________________
MediaWiki-CVS mailing list
MediaWiki-CVS@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to