2016-10-17 3 views
1

시맨틱 미디어 위키를 사용 중이고 다른 맞춤 확장 기능을 개발 중입니다. PHP에서 의미 론적 값을 직접 쿼리하고 싶습니다. 예 :PHP에서 직접 MediaWiki 의미 론적 가치 (SMW)를 쿼리 할 수 ​​있습니까?

SemanticMediaWiki::ask('PAGE_NAME', 'FIELD_NAME') 

그러나이 문서는 가능하지 않습니다. Ask API이 있다는 것을 알고 있습니다. 그러나이 문서는 직접적인 PHP 쿼리가 아닌 URL을 사용하여 쿼리합니다. 나는 또한 inline queries을 통해 페이지 안에 "ask"참조를 포함 할 수 있음을 알고 있습니다. 그러나, 내가하고 싶은 일은 내 사용자 지정 확장의 PHP 내부에서 쿼리 의미 값을 직접 가져 오는 것입니다.

PHP에서 의미 론적 가치를 직접 쿼리 할 수 ​​있는지 여부를 아는 사람이 있습니까? Semantic Title 확장을 수행하는 방법을보고

답변

0

, 나는 내가 필요로 무엇을 할 수있는 기능을 쓸 수 있었다 :

/** 
* Given a wiki page DB key and a Semantic MediaWiki property name, get 
* the value for that page. 
* 
* Remarks: Assumes that the property is of type "string" or "blob", and that 
* there is only one value for that page/property combination. 
* 
* @param string $dbKey The MediaWiki DB key for the page (i.e., "Test_Page") 
* @param string $propertyLabel The property label used to set the Semantic MediaWiki property 
* @return string The property value, or NULL if none exists 
*/ 
static function getSemanticProperty($dbKey, $propertyLabel) { 
    // Use Semantic MediaWiki code to properly retrieve the value 
    $page  = SMWDIWikiPage::newFromTitle(Title::newFromDBkey($dbKey)); 
    $store  = \SMW\StoreFactory::getStore(); 
    $data  = $store->getSemanticData($page); 
    $property = SMWDIProperty::newFromUserLabel($propertyLabel); 
    $values = $data->getPropertyValues($property); 

    if (count($values) > 0) { 
     $value = array_shift($values); 
     if ($value->getDIType() == SMWDataItem::TYPE_STRING || 
      $value->getDIType() == SMWDataItem::TYPE_BLOB) { 
      return $value->getString(); 
     } 
    } else { 
     return null; 
    } 
}