r53813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r53812‎ | r53813 | r53814 >
Date:16:25, 27 July 2009
Author:mkroetzsch
Status:deferred
Tags:
Comment:
include category information in JSON
Modified paths:
  • /trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMediaWiki/includes/SMW_QP_JSONlink.php
@@ -68,6 +68,7 @@
6969 $prefixedtext = $value->getPrefixedText();
7070 }
7171 $valuestack[] = 'label: "'.$values.'"';
 72+ $label = $values;
7273 } else {
7374 $values = array();
7475 $finalvalues = '';
@@ -98,6 +99,21 @@
99100 $count++;
100101 }
101102 $valuestack[] = '"uri" : "'.$wgServer.$wgScriptPath.'/index.php?title='.$prefixedtext.'"';
 103+
 104+ //try to determine type/category
 105+ $catlist = array();
 106+ $dbr = &wfGetDB(DB_SLAVE);
 107+ $cl = $dbr->tableName('categorylinks');
 108+ $arttitle = Title::newFromText($label);
 109+ if($arttitle instanceof Title){
 110+ $catid = $arttitle->getArticleID();
 111+ $catres = $dbr->select($cl, 'cl_to', "cl_from = $catid", __METHOD__, array('ORDER BY' => 'cl_sortkey'));
 112+ while ($catrow = $dbr->fetchRow($catres)) $catlist[] = $catrow[0];
 113+ $dbr->freeResult($catres);
 114+ if(sizeof($catlist) > 0) $valuestack[] = '"type" : "'.$catlist[0].'"';
 115+ }
 116+
 117+ //create property list of item
102118 $itemstack[] = "\t{\n\t\t\t".implode(",\n\t\t\t",$valuestack)."\n\t\t}";
103119 $row = $res->getNext();
104120 }

Status & tagging log