コード例 #1
0
function smwf_wsu_processStep2($name)
{
    global $smwgDIIP;
    require_once $smwgDIIP . '/specials/WebServices/SMW_WebService.php';
    require_once $smwgDIIP . '/specials/WebServices/SMW_WSStorage.php';
    $webService = WebService::newFromName($name);
    $results = new SimpleXMLElement("<p>" . $webService->getResult() . "</p>");
    $response = "";
    foreach ($results->children() as $result) {
        foreach ($result->children() as $part) {
            if (($part->attributes()->property != DI_ALL_SUBJECTS || $part->attributes()->name != DI_ALL_SUBJECTS_ALIAS) && ($part->attributes()->property != DI_ALL_PROPERTIES || $part->attributes()->name != DI_ALL_PROPERTIES_ALIAS) && ($part->attributes()->property != DI_ALL_OBJECTS || $part->attributes()->name != DI_ALL_OBJECTS_ALIAS)) {
                if (strlen('' . $part->attributes()->name) > 0) {
                    //this is for ignoring namespace definitions
                    $response .= $result->attributes()->name;
                    $response .= "." . $part->attributes()->name;
                    $response .= ";";
                }
            }
        }
    }
    return $response;
}
コード例 #2
0
 /**
  * Parses the {{ ws: }} syntax and returns the resulting wikitext
  *
  * @param $parser : a parser object if called by mediawiki or
  * 					a string if called by the preview function
  * @param $preview : boolean
  * @return string
  * 		the rendered wikitext
  */
 public static function processCall(&$parser, $parameters, $preview = false, $smwQueryMode = false, $rawResults = false)
 {
     global $wgsmwRememberedWSUsages, $purgePage, $wgsmwRememberedWSTriplifications;
     $purgePage = true;
     //parse web service call parameters
     list($wsParameters, $wsReturnValues, $configArgs) = self::parseWSCallParameters($parameters);
     $configArgs['webservice'] = trim($parameters[1]);
     $wsTriplify = array_key_exists('triplify', $configArgs) ? true : false;
     $displayTripleSubjects = array_key_exists('displaytriplesubjects', $configArgs) ? $configArgs['displaytriplesubjects'] : false;
     // the name of the ws must be the first parameter of the parser function
     $wsName = trim($parameters[1]);
     $ws = WebService::newFromName($wsName);
     if (!$ws) {
         $errorMSG = wfMsg('smw_wsuse_wwsd_not_existing', $wsName);
         return self::formatWSResult($errorMSG, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
     }
     $wsId = $ws->getArticleID();
     //get article id
     if (!$preview && !$smwQueryMode) {
         $articleId = $parser->getTitle()->getArticleID();
     } else {
         $articleId = 0;
         if (strlen($parser) > 0) {
             $t = Title::makeTitleSafe(0, $parser);
             $articleId = $t->getArticleID();
         }
     }
     $allAliases = WebService::newFromID($wsId)->getAllResultPartAliases();
     //process triplification instructions
     if ($wsTriplify || $displayTripleSubjects) {
         if (!defined('LOD_LINKEDDATA_VERSION') && $wsTriplify) {
             //ld extension not installed
             $errorMSG = wfMsg('smw_wsuse_missing_ld_extension');
             return self::formatWSResult($errorMSG, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
         }
         //get subject creation pattern from wwsd if necessary
         $triplificationSubject = $ws->getTriplificationSubject();
         if (strlen($triplificationSubject) == 0) {
             //no subject creation pattern defind
             $errorMSG = wfMsg('smw_wsuse_missing_triplification_subject');
             return self::formatWSResult($errorMSG, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
         }
         //add triplification subject aliases to result parts if necessary and
         //remember those special result parts
         $subjectCreationPatternParts = array();
         foreach ($allAliases as $alias => $dc) {
             if (strpos(strtolower($triplificationSubject), "?" . $alias . "?") !== false) {
                 $alias = explode('.', $alias);
                 if (!array_key_exists($alias[0] . "." . $alias[1], $wsReturnValues) && !array_key_exists($alias[0], $wsReturnValues)) {
                     $wsReturnValues[$alias[0] . "." . $alias[1]] = "";
                     $subjectCreationPatternParts[] = $alias[1];
                 }
             }
         }
     }
     //validate ws call parameters
     list($messages, $wsParameters) = self::validateWSUsage($wsId, $wsReturnValues, $wsParameters);
     if (sizeof($messages) > 0) {
         $errorMSG = implode(' ', $messages);
         return self::formatWSResult($errorMSG, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
     }
     $parameterSetId = WSStorage::getDatabase()->storeParameterset($wsParameters);
     //check if parameter set id must be removed
     //afterwards if preview or smwquerymode
     $removeParameterSetForRemove = true;
     if (strpos($parameterSetId, "#") === 0) {
         $parameterSetId = substr($parameterSetId, 1);
         $removeParameterSetForRemove = false;
     }
     $wsResults = self::getWSResultsFromCache($ws, $wsReturnValues, $parameterSetId);
     if (is_string($wsResults)) {
         //todo: remove parameter sets and so on
         $wsResults = self::formatWSResult($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
     } else {
         if ($rawResults) {
             return $wsResults;
         }
         //process triplification instructions
         if (($wsTriplify || $displayTripleSubjects) && !is_string($wsResults)) {
             $wsResultsForTriplification = $wsResults;
             foreach ($subjectCreationPatternParts as $p) {
                 if (array_key_exists(strtolower($p), $wsResults)) {
                     unset($wsResults[strtolower($p)]);
                     unset($wsReturnValues['result.' . $p]);
                 }
             }
             //only triplify if this is not for the preview
             if (!$preview && !$smwQueryMode || $displayTripleSubjects) {
                 if (!is_array($wgsmwRememberedWSTriplifications)) {
                     $wgsmwRememberedWSTriplifications = array();
                 }
                 $dropGraph = false;
                 if (!array_key_exists($wsId, $wgsmwRememberedWSTriplifications)) {
                     $wgsmwRememberedWSTriplifications[$wsId] = null;
                     $dropGraph = true;
                 }
                 $tmp = $wsResultsForTriplification;
                 $wsResultsForTriplification = array();
                 foreach ($allAliases as $alias => $dontCare) {
                     $alias = substr($alias, strpos($alias, '.') + 1);
                     if (array_key_exists(strtolower($alias), $tmp)) {
                         $results = $tmp[strtolower(strtolower($alias))];
                         $wsResultsForTriplification[$alias] = $results;
                     }
                 }
                 $subjects[$displayTripleSubjects] = WSTriplifier::getInstance()->triplify($wsResultsForTriplification, $triplificationSubject, $wsId, $wsTriplify && !$preview && !$smwQueryMode, $articleId, $dropGraph, $subjectCreationPatternParts, $parser);
             }
         }
         if ($displayTripleSubjects) {
             $wsResults = array_merge($subjects, $wsResults);
             $wsReturnValues = array_merge(array('result.' . $displayTripleSubjects => ''), $wsReturnValues);
         }
         foreach ($allAliases as $alias => $dontCare) {
             if (array_key_exists(strtolower($alias), $wsReturnValues) && strlen($wsReturnValues[strtolower($alias)]) == 0) {
                 $wsReturnValues[strtolower($alias)] = substr($alias, strpos($alias, '.') + 1);
             }
         }
         $wsResults = self::formatWSResult($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
     }
     //handle cache issues for previews
     if (!$preview && !$smwQueryMode) {
         $tmp = array_keys($wsReturnValues);
         $wgsmwRememberedWSUsages[] = array($wsId, $parameterSetId, "", array_pop($tmp));
     } else {
         WebServiceCache::removeWSParameterPair($wsId, $parameterSetId);
         if ($removeParameterSetForRemove) {
             WSStorage::getDatabase()->removeParameterSet($parameterSetId);
         }
     }
     if ($preview) {
         global $wgParser;
         $t = Title::makeTitleSafe(0, $parser);
         $parser = $wgParser;
         $popts = new ParserOptions();
         $parser->startExternalParse($t, $popts, Parser::OT_HTML);
         $wsResults = $parser->internalParse($wsResults);
         $wsResults = $parser->doBlockLevels($wsResults, true);
         return $wsResults;
     }
     if (!$smwQueryMode) {
         //todo: Is this still necessary?
         $wsResults = $parser->replaceVariables($wsResults);
     }
     return $wsResults;
 }