Пример #1
0
 /**
  * Returns the HTML which is added to $wgOut after the article text.
  *
  * @return string
  */
 protected function getHtml()
 {
     if ($this->limit > 0) {
         // limit==0: configuration setting to disable this completely
         $store = StoreFactory::getStore();
         $concept = $store->getConceptCacheStatus($this->getDataItem());
         $description = new ConceptDescription($this->getDataItem());
         $query = SMWPageLister::getQuery($description, $this->limit, $this->from, $this->until);
         $queryResult = $store->getQueryResult($query);
         $diWikiPages = $queryResult->getResults();
         if ($this->until !== '') {
             $diWikiPages = array_reverse($diWikiPages);
         }
         $errors = $queryResult->getErrors();
     } else {
         $diWikiPages = array();
         $errors = array();
     }
     $pageLister = new SMWPageLister($diWikiPages, null, $this->limit, $this->from, $this->until);
     $this->mTitle->setFragment('#SMWResults');
     // Make navigation point to the result list.
     $navigation = $pageLister->getNavigationLinks($this->mTitle);
     $titleText = htmlspecialchars($this->mTitle->getText());
     $resultNumber = min($this->limit, count($diWikiPages));
     // Concept cache information
     if ($concept instanceof DIConcept && $concept->getCacheStatus() === 'full') {
         $cacheInformation = Html::element('span', array('class' => 'smw-concept-cache-information'), ' ' . $this->getContext()->msg('smw-concept-cache-text', $this->getContext()->getLanguage()->formatNum($concept->getCacheCount()), $this->getContext()->getLanguage()->date($concept->getCacheDate()), $this->getContext()->getLanguage()->time($concept->getCacheDate()))->text());
     } else {
         $cacheInformation = '';
     }
     return Html::element('br', array('id' => 'smwfootbr')) . Html::element('a', array('name' => 'SMWResults'), null) . Html::rawElement('div', array('id' => 'mw-pages'), Html::rawElement('h2', array(), $this->getContext()->msg('smw_concept_header', $titleText)->text()) . Html::element('span', array(), $this->getContext()->msg('smw_conceptarticlecount', $resultNumber)->parse()) . smwfEncodeMessages($errors) . ' ' . $navigation . $cacheInformation . $pageLister->formatList());
 }
Пример #2
0
 /**
  * Method for handling the subobject parser function.
  *
  * @since 1.7
  *
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     self::$m_errors = array();
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     $subobjectName = str_replace(' ', '_', trim(array_shift($params)));
     $mainSemanticData = SMWParseData::getSMWData($parser);
     $subject = $mainSemanticData->getSubject();
     $diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName);
     $semanticData = new SMWContainerSemanticData($diSubWikiPage);
     foreach ($params as $param) {
         $parts = explode('=', trim($param), 2);
         // Only add the property when there is both a name
         // and a non-empty value.
         if (count($parts) == 2 && $parts[1] != '') {
             self::addPropertyValueToSemanticData($parts[0], $parts[1], $semanticData);
         } else {
             //self::$m_errors[] = wfMsgForContent( 'smw_noinvannot' );
         }
     }
     $propertyDi = new SMWDIProperty('_SOBJ');
     $subObjectDi = new SMWDIContainer($semanticData);
     SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
     return smwfEncodeMessages(self::$m_errors);
 }
Пример #3
0
 /**
  * Returns the HTML which is added to $wgOut after the article text.
  *
  * @return string
  */
 protected function getHtml()
 {
     wfProfileIn(__METHOD__ . ' (SMW)');
     if ($this->limit > 0) {
         // limit==0: configuration setting to disable this completely
         $store = smwfGetStore();
         $description = new SMWConceptDescription($this->getDataItem());
         $query = SMWPageLister::getQuery($description, $this->limit, $this->from, $this->until);
         $queryResult = $store->getQueryResult($query);
         $diWikiPages = $queryResult->getResults();
         if ($this->until !== '') {
             $diWikiPages = array_reverse($diWikiPages);
         }
         $errors = $queryResult->getErrors();
     } else {
         $diWikiPages = array();
         $errors = array();
     }
     $pageLister = new SMWPageLister($diWikiPages, null, $this->limit, $this->from, $this->until);
     $this->mTitle->setFragment('#SMWResults');
     // Make navigation point to the result list.
     $navigation = $pageLister->getNavigationLinks($this->mTitle);
     $titleText = htmlspecialchars($this->mTitle->getText());
     $resultNumber = min($this->limit, count($diWikiPages));
     $result = "<a name=\"SMWResults\"></a><div id=\"mw-pages\">\n" . '<h2>' . wfMsg('smw_concept_header', $titleText) . "</h2>\n" . wfMsgExt('smw_conceptarticlecount', array('parsemag'), $resultNumber) . smwfEncodeMessages($errors) . "\n" . $navigation . $pageLister->formatList() . $navigation . "</div>\n";
     wfProfileOut(__METHOD__ . ' (SMW)');
     return $result;
 }
Пример #4
0
 /**
  * Method for handling the subobject parser function.
  *
  * @since 1.7
  *
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     self::$m_errors = array();
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     $subobjectName = str_replace(' ', '_', trim(array_shift($params)));
     // For objects that don't come with there own idenifier, use a value
     // dependant md4 hash key
     if ($subobjectName === '' || $subobjectName === '-') {
         $subobjectName = '_' . hash('md4', implode('|', $params), false);
     }
     $mainSemanticData = SMWParseData::getSMWData($parser);
     $subject = $mainSemanticData->getSubject();
     $diSubWikiPage = new SMWDIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subobjectName);
     $semanticData = new SMWContainerSemanticData($diSubWikiPage);
     $previousPropertyDi = null;
     foreach ($params as $param) {
         $parts = explode('=', trim($param), 2);
         // Only add the property when there is both a name
         // and a non-empty value.
         if (count($parts) == 2 && $parts[1] != '') {
             $previousPropertyDi = self::addPropertyValueToSemanticData($parts[0], $parts[1], $semanticData);
         } elseif (count($parts) == 1 && !is_null($previousPropertyDi)) {
             self::addPropertyDiValueToSemanticData($previousPropertyDi, $parts[0], $semanticData);
         } else {
             //self::$m_errors[] = wfMessage( 'smw_noinvannot' )->inContentLanguage()->text();
         }
     }
     $propertyDi = new SMWDIProperty('_SOBJ');
     $subObjectDi = new SMWDIContainer($semanticData);
     SMWParseData::getSMWData($parser)->addPropertyObjectValue($propertyDi, $subObjectDi);
     return smwfEncodeMessages(self::$m_errors);
 }
Пример #5
0
 /**
  * Returns the HTML which is added to $wgOut after the article text.
  *
  * @return string
  */
 protected function getHtml()
 {
     global $smwgConceptPagingLimit, $wgRequest;
     if ($this->limit > 0) {
         // limit==0: configuration setting to disable this completely
         $description = new ConceptDescription($this->getDataItem());
         $query = SMWPageLister::getQuery($description, $this->limit, $this->from, $this->until);
         $query->setLimit($wgRequest->getVal('limit', $smwgConceptPagingLimit));
         $query->setOffset($wgRequest->getVal('offset', '0'));
         $queryResult = ApplicationFactory::getInstance()->getStore()->getQueryResult($query);
         $diWikiPages = $queryResult->getResults();
         if ($this->until !== '') {
             $diWikiPages = array_reverse($diWikiPages);
         }
         $errors = $queryResult->getErrors();
     } else {
         $diWikiPages = array();
         $errors = array();
     }
     $pageLister = new SMWPageLister($diWikiPages, null, $this->limit, $this->from, $this->until);
     $this->mTitle->setFragment('#SMWResults');
     // Make navigation point to the result list.
     $titleText = htmlspecialchars($this->mTitle->getText());
     return Html::element('br', array('id' => 'smwfootbr')) . Html::element('a', array('name' => 'SMWResults'), null) . Html::rawElement('div', array('id' => 'mw-pages'), $this->getCacheInformation() . Html::rawElement('h2', array(), $this->getContext()->msg('smw_concept_header', $titleText)->text()) . $this->getNavigationLinks('smw_conceptarticlecount', $diWikiPages, $smwgConceptPagingLimit) . smwfEncodeMessages($errors) . ' ' . $this->getFormattedColumns($diWikiPages));
 }
 /**
  * @covers ::smwfEncodeMessages
  * @test smwfEncodeMessages
  * @dataProvider getEncodeMessagesDataProvider
  *
  * @param $message
  * @param $type
  * @param $separator
  * @param $escape
  */
 public function testSmwfEncodeMessages($message, $type, $separator, $escape)
 {
     $results = smwfEncodeMessages($message);
     $this->assertFalse(is_null($results));
     $this->assertTrue(is_string($results));
     $results = smwfEncodeMessages($message, $type);
     $this->assertFalse(is_null($results));
     $this->assertTrue(is_string($results));
     $results = smwfEncodeMessages($message, $type, $separator);
     $this->assertFalse(is_null($results));
     $this->assertTrue(is_string($results));
     $results = smwfEncodeMessages($message, $type, $separator, $escape);
     $this->assertFalse(is_null($results));
     $this->assertTrue(is_string($results));
 }
Пример #7
0
 /**
  * Renders and returns the output.
  * @see ParserHook::render
  * 
  * @since 1.7
  * 
  * @param array $parameters
  * 
  * @return string
  */
 public function render(array $parameters)
 {
     /**
      * Non-escaping is safe bacause a user's message is passed through parser, which will
      * handle unsafe HTM elements.
      */
     $result = smwfEncodeMessages(array($parameters['message']), $parameters['icon'], ' <!--br-->', false);
     if (!is_null($this->parser->getTitle()) && $this->parser->getTitle()->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($this->parser);
     }
     return $result;
 }
 function formatResult($skin, $result)
 {
     $linker = smwfGetLinker();
     $proplink = $linker->link($result->getDiWikiPage()->getTitle(), $result->getLabel());
     $types = smwfGetStore()->getPropertyValues($result->getDiWikiPage(), new SMWDIProperty('_TYPE'));
     $errors = array();
     if (count($types) >= 1) {
         $typestring = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'))->getLongHTMLText($linker);
     } else {
         $type = SMWTypesValue::newFromTypeId('_wpg');
         $typestring = $type->getLongHTMLText($linker);
         $errors[] = wfMsg('smw_propertylackstype', $type->getLongHTMLText());
     }
     return wfMsg('smw_unusedproperty_template', $proplink, $typestring) . ' ' . smwfEncodeMessages($errors);
 }
Пример #9
0
 /**
  * @param Parser $parser
  * @param ProcessingResult $result
  *
  * @return mixed
  */
 public function handle(Parser $parser, ProcessingResult $result)
 {
     $parameters = $result->getParameters();
     /**
      * Non-escaping is safe bacause a user's message is passed through parser, which will
      * handle unsafe HTM elements.
      */
     $result = smwfEncodeMessages(array($parameters['message']->getValue()), $parameters['icon']->getValue(), ' <!--br-->', false);
     if (!is_null($parser->getTitle()) && $parser->getTitle()->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
Пример #10
0
 /**
  * Handler for the #compound_query parser function.
  * 
  * @param Parser $parser
  * 
  * @return string
  */
 public static function doCompoundQuery(Parser &$parser)
 {
     global $smwgQEnabled, $smwgIQRunningNumber;
     if (!$smwgQEnabled) {
         return smwfEncodeMessages(array(wfMsgForContent('smw_iq_disabled')));
     }
     $smwgIQRunningNumber++;
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser.
     $other_params = array();
     $results = array();
     $printRequests = array();
     $queryParams = array();
     foreach ($params as $param) {
         // Very primitive heuristic - if the parameter
         // includes a square bracket, then it's a
         // sub-query; otherwise it's a regular parameter.
         if (strpos($param, '[') !== false) {
             $queryParams[] = $param;
         } else {
             $parts = explode('=', $param, 2);
             if (count($parts) >= 2) {
                 $other_params[strtolower(trim($parts[0]))] = $parts[1];
                 // don't trim here, some params care for " "
             }
         }
     }
     foreach ($queryParams as $param) {
         $subQueryParams = self::getSubParams($param);
         if (array_key_exists('format', $other_params) && !array_key_exists('format', $subQueryParams)) {
             $subQueryParams['format'] = $other_params['format'];
         }
         $next_result = self::getQueryResultFromFunctionParams($subQueryParams, SMW_OUTPUT_WIKI);
         $results = self::mergeSMWQueryResults($results, $next_result->getResults());
         $printRequests = self::mergeSMWPrintRequests($printRequests, $next_result->getPrintRequests());
     }
     // Sort results so that they'll show up by page name
     uasort($results, array('SCQQueryProcessor', 'compareQueryResults'));
     $query_result = new SCQQueryResult($printRequests, new SMWQuery(), $results, smwfGetStore());
     if (version_compare(SMW_VERSION, '1.6.1', '>')) {
         SMWQueryProcessor::addThisPrintout($printRequests, $other_params);
         $other_params = parent::getProcessedParams($other_params, $printRequests);
     }
     return self::getResultFromQueryResult($query_result, $other_params, SMW_OUTPUT_WIKI);
 }
Пример #11
0
 /**
  * Method for handling the ask concept function.
  * 
  * @todo The possible use of this in an HTML or Specal page context needs to be revisited. The code mentions it, but can this actually happen?
  * @todo The escaping of symbols in concept queries needs to be revisited.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     global $wgContLang, $wgTitle;
     $title = $parser->getTitle();
     $pconc = new SMWDIProperty('_CONC');
     if ($title->getNamespace() != SMW_NS_CONCEPT) {
         $result = smwfEncodeMessages(array(wfMsgForContent('smw_no_concept_namespace')));
         SMWOutputs::commitToParser($parser);
         return $result;
     } elseif (count(SMWParseData::getSMWdata($parser)->getPropertyValues($pconc)) > 0) {
         $result = smwfEncodeMessages(array(wfMsgForContent('smw_multiple_concepts')));
         SMWOutputs::commitToParser($parser);
         return $result;
     }
     // process input:
     $params = func_get_args();
     array_shift($params);
     // We already know the $parser ...
     // Use first parameter as concept (query) string.
     $concept_input = str_replace(array('&gt;', '&lt;'), array('>', '<'), array_shift($params));
     // second parameter, if any, might be a description
     $concept_docu = array_shift($params);
     // NOTE: the str_replace above is required in MediaWiki 1.11, but not in MediaWiki 1.14
     $query = SMWQueryProcessor::createQuery($concept_input, SMWQueryProcessor::getProcessedParams(array('limit' => 20, 'format' => 'list')), SMWQueryProcessor::CONCEPT_DESC);
     $concept_text = $query->getDescription()->getQueryString();
     if (!is_null(SMWParseData::getSMWData($parser))) {
         $diConcept = new SMWDIConcept($concept_text, $concept_docu, $query->getDescription()->getQueryFeatures(), $query->getDescription()->getSize(), $query->getDescription()->getDepth());
         SMWParseData::getSMWData($parser)->addPropertyObjectValue($pconc, $diConcept);
     }
     // display concept box:
     $rdflink = SMWInfolink::newInternalLink(wfMsgForContent('smw_viewasrdf'), $wgContLang->getNsText(NS_SPECIAL) . ':ExportRDF/' . $title->getPrefixedText(), 'rdflink');
     SMWOutputs::requireResource('ext.smw.style');
     // TODO: escape output, preferably via Html or Xml class.
     $result = '<div class="smwfact"><span class="smwfactboxhead">' . wfMsgForContent('smw_concept_description', $title->getText()) . (count($query->getErrors()) > 0 ? ' ' . smwfEncodeMessages($query->getErrors()) : '') . '</span>' . '<span class="smwrdflink">' . $rdflink->getWikiText() . '</span>' . '<br />' . ($concept_docu ? "<p>{$concept_docu}</p>" : '') . '<pre>' . str_replace('[', '&#x005B;', $concept_text) . "</pre>\n</div>";
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
Пример #12
0
 /**
  * Method for handling the ask parser function.
  * 
  * @since 1.5.3
  * 
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     global $smwgQEnabled, $smwgIQRunningNumber, $wgTitle;
     if ($smwgQEnabled) {
         $smwgIQRunningNumber++;
         $params = func_get_args();
         array_shift($params);
         // We already know the $parser ...
         $result = SMWQueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI);
     } else {
         $result = smwfEncodeMessages(array(wfMessage('smw_iq_disabled')->inContentLanguage()->text()));
     }
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
Пример #13
0
 /**
  * Method for handling the show parser function.
  *
  * @since 1.5.3
  *
  * @param Parser $parser
  */
 public static function render(Parser &$parser)
 {
     global $smwgQEnabled, $smwgIQRunningNumber, $wgTitle;
     if ($smwgQEnabled) {
         $smwgIQRunningNumber++;
         $rawParams = func_get_args();
         array_shift($rawParams);
         // We already know the $parser ...
         list($query, $params) = SMWQueryProcessor::getQueryAndParamsFromFunctionParams($rawParams, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY, true);
         $result = SMWQueryProcessor::getResultFromQuery($query, $params, SMW_OUTPUT_WIKI, SMWQueryProcessor::INLINE_QUERY);
         $queryKey = hash('md4', implode('|', $rawParams), false);
         SMWAsk::addQueryData($queryKey, $query, $params, $parser);
     } else {
         $result = smwfEncodeMessages(array(wfMessage('smw_iq_disabled')->inContentLanguage()->text()));
     }
     if (!is_null($wgTitle) && $wgTitle->isSpecialPage()) {
         global $wgOut;
         SMWOutputs::commitToOutputPage($wgOut);
     } else {
         SMWOutputs::commitToParser($parser);
     }
     return $result;
 }
function materializePF_render(&$parser)
{
    $parameters = materializePF_getParameters(func_get_args());
    if ($parser->OutputType() == 2) {
        if (!($parameters["update"] === "false" && $parameters["materialized"] != null || $parameters["update"] === "both")) {
            $parameters["materialized"] = $parser->replaceVariables("{{subst:" . substr($parameters["call"], 2));
        }
        if ($parameters["update"] != "final") {
            $parameters["call"] = str_replace("{", "##mcoll##", $parameters["call"]);
            $parameters["call"] = str_replace("}", "##mcolr##", $parameters["call"]);
            $parameters["call"] = str_replace("|", "##pipe##", $parameters["call"]);
            $output = "{{#materialize:" . $parameters["call"] . "\n";
            $output .= "| update = " . $parameters["update"] . "\n";
            $output .= "| materialized = \n" . $parameters["materialized"];
            $output .= "\n}}";
        } else {
            $output = $parameters["materialized"];
        }
    } else {
        global $wgsmwRememberedMaterializations;
        $dbAccess = SMWMaterializationStorageAccess::getInstance();
        $db = $dbAccess->getDatabase();
        $pageId = $parser->getTitle()->getArticleID();
        $callHash = SMWHashProcessor::generateHashValue($parameters["call"]);
        $materialized = null;
        $sourceHash = $db->getMaterializationHash($pageId, $callHash);
        if ($sourceHash == null) {
            $materialized = trim($parser->replaceVariables($parameters["call"]));
            $materializationHash = SMWHashProcessor::generateHashValue($materialized);
            $db->addMaterializationHash($pageId, $callHash, $materializationHash);
        } else {
            if ($parameters["update"] == "true") {
                $materialized = trim($parser->replaceVariables($parameters["call"]));
                $materializationHash = SMWHashProcessor::generateHashValue($materialized);
                $db->deleteMaterializationHash($pageId, $callHash);
                $db->addMaterializationHash($pageId, $callHash, $materializationHash);
            }
        }
        $wgsmwRememberedMaterializations[$callHash] = null;
        $output = $parameters["materialized"];
        if ($parameters["update"] == "both") {
            if ($sourceHash) {
                $materialized = trim($parser->replaceVariables($parameters["call"]));
                if (!SMWHashProcessor::isHashValueEqual(SMWHashProcessor::generateHashValue($materialized), $sourceHash)) {
                    $output .= "<br/>" . $materialized;
                }
            }
        } else {
            if ($parameters["update"] == "false") {
                $output = $parameters["materialized"];
                if ($sourceHash) {
                    $materialized = trim($parser->replaceVariables($parameters["call"]));
                    if (!SMWHashProcessor::isHashValueEqual(SMWHashProcessor::generateHashValue($materialized), $sourceHash)) {
                        $output .= smwfEncodeMessages(array(wfMsg('smw_wwsm_update_msg')));
                    }
                }
            }
        }
    }
    return $output;
}
Пример #15
0
 /**
  * Provides a simple formatted string of all the error messages that occurred.
  * Can be used if not specific error formatting is desired. Compatible with HTML
  * and Wiki.
  *
  * @param SMWQueryResult $res
  *
  * @return string
  */
 protected function getErrorString(SMWQueryResult $res)
 {
     return $this->mShowErrors ? smwfEncodeMessages(array_merge($this->mErrors, $res->getErrors())) : '';
 }
Пример #16
0
 /**
  * Function for handling the {{\#fromcodepoint }} parser function.
  */
 public static function doFromCodepoint($parser, $codepoint, $base = 10)
 {
     if (!is_numeric($base)) {
         $base = 10;
     }
     $value = intval($codepoint, $base);
     if ($value < 1) {
         $error_msg = array('Invalid codepoint', $codepoint);
         return smwfEncodeMessages($error_msg);
     }
     return unichr($value);
 }
 function formatResult($skin, $result)
 {
     global $wgLang;
     $linker = smwfGetLinker();
     list($property, $useCount) = $result;
     $errors = array();
     $diWikiPage = $property->getDiWikiPage();
     $title = !is_null($diWikiPage) ? $diWikiPage->getTitle() : null;
     if ($property->isUserDefined()) {
         if ($title === null) {
             return '';
         }
         if ($useCount <= 5) {
             $errors[] = wfMessage('smw_propertyhardlyused')->escaped();
         }
         // User defined types default to Page
         global $smwgPDefaultType;
         $typeDataValue = SMWTypesValue::newFromTypeId($smwgPDefaultType);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $label = htmlspecialchars($property->getLabel());
         if ($title->exists()) {
             $typeProperty = new SMWDIProperty('_TYPE');
             $types = smwfGetStore()->getPropertyValues($diWikiPage, $typeProperty);
             if (count($types) >= 1) {
                 $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), $typeProperty);
                 $typestring = $typeDataValue->getLongHTMLText($linker);
             } else {
                 $errors[] = wfMessage('smw_propertylackstype')->rawParams($typestring)->escaped();
             }
             $proplink = $linker->link($title, $label);
         } else {
             $errors[] = wfMessage('smw_propertylackspage')->escaped();
             $proplink = $linker->link($title, $label, array(), array('action' => 'view'));
         }
     } else {
         // predefined property
         $typeid = $property->findPropertyTypeID();
         $typeDataValue = SMWTypesValue::newFromTypeId($typeid);
         $typestring = $typeDataValue->getLongHTMLText($linker);
         $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
         $proplink = $propertyDataValue->getShortHtmlText($linker);
     }
     $warnings = smwfEncodeMessages($errors, 'warning', '', false);
     $useCount = $wgLang->formatNum($useCount);
     if ($typestring === '') {
         // Builtins have no type
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template_notype')->rawParams($proplink)->params($useCount)->text() . ' ' . $warnings;
     } else {
         // @todo Should use numParams for $useCount?
         return wfMessage('smw_property_template')->rawParams($proplink, $typestring)->params($useCount)->escaped() . ' ' . $warnings;
     }
 }
Пример #18
0
 /**
  * TODO: document
  * 
  * @param SMWQuery $query
  * @param array $params These need to be the result of a list fed to getProcessedParams
  * @param $extraprintouts
  * @param $outputmode
  * @param $context
  * @param $format
  * 
  * @return string
  */
 public static function getResultFromQuery(SMWQuery $query, array $params, $extraprintouts, $outputmode, $context = self::INLINE_QUERY, $format = '')
 {
     wfProfileIn('SMWQueryProcessor::getResultFromQuery (SMW)');
     // Query routing allows extensions to provide alternative stores as data sources
     // The while feature is experimental and is not properly integrated with most of SMW's architecture. For instance, some query printers just fetch their own store.
     // @todo FIXME: case-insensitive
     global $smwgQuerySources;
     if (array_key_exists('source', $params) && array_key_exists($params['source'], $smwgQuerySources)) {
         $store = new $smwgQuerySources[$params['source']]();
         $query->params = $params;
         // this is a hack
     } else {
         $store = smwfGetStore();
         // default store
     }
     $res = $store->getQueryResult($query);
     if ($query->querymode == SMWQuery::MODE_INSTANCES || $query->querymode == SMWQuery::MODE_NONE) {
         wfProfileIn('SMWQueryProcessor::getResultFromQuery-printout (SMW)');
         if ($format === '') {
             $format = self::getResultFormat($params);
         }
         $printer = self::getResultPrinter($format, $context, $res);
         $result = $printer->getResult($res, $params, $outputmode);
         wfProfileOut('SMWQueryProcessor::getResultFromQuery-printout (SMW)');
         wfProfileOut('SMWQueryProcessor::getResultFromQuery (SMW)');
         return $result;
     } else {
         // result for counting or debugging is just a string or number
         if (is_numeric($res)) {
             $res = strval($res);
         }
         if (is_string($res)) {
             if (array_key_exists('intro', $params)) {
                 $res = str_replace('_', ' ', $params['intro']) . $res;
             }
             if (array_key_exists('outro', $params)) {
                 $res .= str_replace('_', ' ', $params['outro']);
             }
             $result = $res . smwfEncodeMessages($query->getErrors());
         } else {
             // When no valid result was obtained, $res will be a SMWQueryResult.
             $result = smwfEncodeMessages($query->getErrors());
         }
         wfProfileOut('SMWQueryProcessor::getResultFromQuery (SMW)');
         return $result;
     }
 }
 /**
  * TODO: document
  * 
  * @param SMWQuery $query
  * @param array $params These need to be the result of a list fed to getProcessedParams
  * @param $outputMode
  * @param $context
  *
  * @return string
  */
 protected static function getResultFromQuery(SMWQuery $query, array $params, $outputMode, $context = self::INLINE_QUERY)
 {
     wfProfileIn('SMWQueryProcessor::getResultFromQuery (SMW)');
     $res = $params['source']->getValue()->getQueryResult($query);
     if ($query->querymode == SMWQuery::MODE_INSTANCES || $query->querymode == SMWQuery::MODE_NONE) {
         wfProfileIn('SMWQueryProcessor::getResultFromQuery-printout (SMW)');
         $printer = self::getResultPrinter($params['format']->getValue(), $context, $res);
         $result = $printer->getResult($res, $params, $outputMode);
         wfProfileOut('SMWQueryProcessor::getResultFromQuery-printout (SMW)');
         wfProfileOut('SMWQueryProcessor::getResultFromQuery (SMW)');
         return $result;
     } else {
         // result for counting or debugging is just a string or number
         if (is_numeric($res)) {
             $res = strval($res);
         }
         if (is_string($res)) {
             $result = str_replace('_', ' ', $params['intro']->getValue()) . $res . str_replace('_', ' ', $params['outro']->getValue()) . smwfEncodeMessages($query->getErrors());
         } else {
             // When no valid result was obtained, $res will be a SMWQueryResult.
             $result = smwfEncodeMessages($query->getErrors());
         }
         wfProfileOut('SMWQueryProcessor::getResultFromQuery (SMW)');
         return $result;
     }
 }
Пример #20
0
 /**
  * Return error message or empty string if no error occurred.
  *
  * @return string
  */
 public function getErrorString()
 {
     return smwfEncodeMessages($this->errorMessages);
 }
Пример #21
0
 /**
  * format the ws result in the given result format
  */
 public static function formatWSResult($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode = false)
 {
     //deal with error messages
     if (is_string($wsResults)) {
         return self::formatErrorMsgAsResult($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
     }
     //handle erroneous wwsds
     foreach ($wsResults as $key => $wsResult) {
         if (is_string($wsResult)) {
         } else {
             if (is_array($wsResult)) {
                 foreach ($wsResult as $subKey => $subWsResult) {
                     if (is_string($subWsResult) || is_numeric($subWsResult)) {
                     } else {
                         if ($subWsResult != "") {
                             $wsResults[$key][$subKey] = smwfEncodeMessages(array(wfMsg('smw_wsuse_type_mismatch'))) . print_r($subWsResult, true) . $subKey;
                         }
                     }
                 }
             } else {
                 $wsResults[$key] = smwfEncodeMessages(array(wfMsg('smw_wsuse_type_mismatch'))) . print_r($wsResult, true) . $key;
             }
         }
     }
     $stripTags = array_key_exists('striptags', $configArgs) ? $configArgs['striptags'] : false;
     $wsResults = self::getReadyToPrintResult($wsResults, $stripTags);
     return self::formatWSResultWithSMWQPs($wsResults, $configArgs, $wsParameters, $wsReturnValues, $smwQueryMode);
 }
 /**
  * Produce a formatted string representation for showing a property in
  * the list of unused properties.
  *
  * @since 1.8
  *
  * @param SMWDIProperty $property
  * @return string
  */
 protected function formatPropertyItem(SMWDIProperty $property)
 {
     $linker = smwfGetLinker();
     $errors = array();
     if ($property->isUserDefined()) {
         $proplink = $linker->link($property->getDiWikiPage()->getTitle(), $property->getLabel());
         $types = smwfGetStore()->getPropertyValues($property->getDiWikiPage(), new SMWDIProperty('_TYPE'));
         if (count($types) >= 1) {
             $typeDataValue = SMWDataValueFactory::newDataItemValue(current($types), new SMWDIProperty('_TYPE'));
         } else {
             $typeDataValue = SMWTypesValue::newFromTypeId('_wpg');
             $errors[] = wfMessage('smw_propertylackstype', $typeDataValue->getLongHTMLText())->text();
         }
         $typeString = $typeDataValue->getLongHTMLText($linker);
     } else {
         $typeid = $property->findPropertyTypeID();
         $typeDataValue = SMWTypesValue::newFromTypeId($typeid);
         $typeString = $typeDataValue->getLongHTMLText($linker);
         $propertyDataValue = SMWDataValueFactory::newDataItemValue($property, null);
         $proplink = $propertyDataValue->getShortHtmlText($linker);
     }
     return wfMessage('smw_unusedproperty_template', $proplink, $typeString)->text() . ' ' . smwfEncodeMessages($errors);
 }
 /**
  * Return a string that displays all error messages as a tooltip, or
  * an empty string if no errors happened.
  *
  * @return string
  */
 public function getErrorText()
 {
     return smwfEncodeMessages($this->mErrors);
 }
	/**
	 * Return a string that displays all error messages as a tooltip, or
	 * an empty string if no errors happened.
	 */
	public function getErrorText() {
		if ( defined( 'SMW_VERSION' ) )
			return smwfEncodeMessages( $this->mErrors );

		return $this->mErrors;
	}
Пример #25
0
 function formatResult($skin, $result)
 {
     global $wgLang, $wgExtraNamespaces, $wgRequest;
     $type = $wgRequest->getVal("type") == NULL ? 0 : $wgRequest->getVal("type") + 0;
     // The attribute title is in value, see getSQL().
     $errors = array();
     if ($result[5] <= 5) {
         $errors[] = wfMsg('smw_propertyhardlyused');
     }
     if ($type == 2) {
         // n-ary
         $attrtitle = Title::makeTitle(SMW_NS_PROPERTY, $result[2]);
         if (!$attrtitle->exists()) {
             $errors[] = wfMsg('smw_propertylackspage');
         }
         $attrlink = $skin->makeLinkObj($attrtitle, $attrtitle->getText());
         $store = smwfGetStore();
         $hasTypeDV = SMWPropertyValue::makeProperty("_LIST");
         $typeValues = $store->getPropertyValues($attrtitle, $hasTypeDV);
         $typelink = array();
         foreach ($typeValues as $tv) {
             $typelink[] = $tv->getLongHTMLText($skin);
         }
         if (count($typelink) == 0) {
             // no type defined
             $errors[] = wfMsg('smw_propertylackstype', "Type:Page");
             $typelink[] = "Page";
             // default
         }
         return "{$attrlink} (" . $result[5] . ")" . wfMsg('smw_attr_type_join', implode(";", $typelink)) . ' ' . smwfEncodeMessages($errors);
     }
     if ($type == 1) {
         $attrtitle = Title::makeTitle(SMW_NS_PROPERTY, $result[2]);
         if (!$attrtitle->exists()) {
             $errors[] = wfMsg('smw_propertylackspage');
         }
         $attrlink = $skin->makeLinkObj($attrtitle, $attrtitle->getText());
         if ($result[3] != NULL) {
             $objecttitle = Title::newFromText($result[3]);
             $objectlink = $skin->makeLinkObj($objecttitle);
         } else {
             $objectlink = '*range not defined*';
         }
         return "{$attrlink} (" . $result[5] . ")" . wfMsg('smw_attr_type_join', $objectlink) . ' ' . smwfEncodeMessages($errors);
     } else {
         $attrtitle = Title::makeTitle(SMW_NS_PROPERTY, $result[2]);
         if (!$attrtitle->exists()) {
             $errors[] = wfMsg('smw_propertylackspage');
         }
         $attrlink = $skin->makeLinkObj($attrtitle, $attrtitle->getText());
         $hasTypeDV = SMWPropertyValue::makeProperty("_TYPE");
         $typetitle = smwfGetStore()->getPropertyValues($attrtitle, $hasTypeDV);
         if (count($typetitle) == 0) {
             $typelink = "Page";
             // default
         } else {
             $typelink = $typetitle[0]->getLongHTMLText($skin);
         }
         return "{$attrlink} (" . $result[5] . ")" . wfMsg('smw_attr_type_join', $typelink) . ' ' . smwfEncodeMessages($errors);
     }
 }
Пример #26
0
 /**
  * Create a fully formatted result string from a query and its
  * parameters. The method takes care of processing various types of
  * query result. Most cases are handled by printers, but counting and
  * debugging uses special code.
  *
  * @param SMWQuery $query
  * @param array $params These need to be the result of a list fed to getProcessedParams
  * @param integer $outputMode
  * @param integer $context
  * @since before 1.7, but public only since 1.8
  *
  * @return string
  */
 public static function getResultFromQuery(SMWQuery $query, array $params, $outputMode, $context)
 {
     $res = self::getStoreFromParams($params)->getQueryResult($query);
     if ($query->querymode == SMWQuery::MODE_INSTANCES || $query->querymode == SMWQuery::MODE_NONE) {
         $printer = self::getResultPrinter($params['format']->getValue(), $context);
         $result = $printer->getResult($res, $params, $outputMode);
         return $result;
     } else {
         // result for counting or debugging is just a string or number
         if ($res instanceof SMWQueryResult) {
             $res = $res->getCountValue();
         }
         if (is_numeric($res)) {
             $res = strval($res);
         }
         if (is_string($res)) {
             $result = str_replace('_', ' ', $params['intro']->getValue()) . $res . str_replace('_', ' ', $params['outro']->getValue()) . smwfEncodeMessages($query->getErrors());
         } else {
             // When no valid result was obtained, $res will be a SMWQueryResult.
             $result = smwfEncodeMessages($query->getErrors());
         }
         return $result;
     }
 }
Пример #27
0
/**
 * The {{#sparql }} parser function processing part.
 */
function smwfProcessSPARQLInlineQueryParserFunction(&$parser)
{
    global $smwgWebserviceEndpoint;
    if (isset($smwgWebserviceEndpoint)) {
        global $smwgIQRunningNumber;
        $smwgIQRunningNumber++;
        $params = func_get_args();
        array_shift($params);
        // we already know the $parser ...
        return SMWSPARQLQueryProcessor::getResultFromFunctionParams($params, SMW_OUTPUT_WIKI);
    } else {
        return smwfEncodeMessages(array(wfMsgForContent('smw_sparql_disabled')));
    }
}