protected function parseUserValue($value) { global $wgContLang; if ($this->m_caption === false) { $this->m_caption = $value; } $valueParts = explode(':', $value, 2); if (count($valueParts) > 1) { $namespace = smwfNormalTitleText($valueParts[0]); $value = $valueParts[1]; $typeNamespace = $wgContLang->getNsText(SMW_NS_TYPE); if ($namespace != $typeNamespace) { $this->addError(wfMsgForContent('smw_wrong_namespace', $typeNamespace)); } } $this->m_givenLabel = smwfNormalTitleText($value); $this->m_typeId = SMWDataValueFactory::findTypeID($this->m_givenLabel); if ($this->m_typeId === '') { $this->addError(wfMsgForContent('smw_unknowntype', $this->m_givenLabel)); $this->m_realLabel = $this->m_givenLabel; } else { $this->m_realLabel = SMWDataValueFactory::findTypeLabel($this->m_typeId); } $this->m_isAlias = $this->m_realLabel === $this->m_givenLabel ? false : true; try { $this->m_dataitem = self::getTypeUriFromTypeId($this->m_typeId); } catch (SMWDataItemException $e) { $this->m_dataitem = self::getTypeUriFromTypeId('notype'); $this->addError(wfMsgForContent('smw_parseerror')); } }
protected function parseUserValue($value) { global $wgContLang; $this->m_diProperties = array(); $stringValue = ''; $valueList = preg_split('/[\\s]*;[\\s]*/u', trim($value)); foreach ($valueList as $propertyName) { $propertyNameParts = explode(':', $propertyName, 2); if (count($propertyNameParts) > 1) { $namespace = smwfNormalTitleText($propertyNameParts[0]); $propertyName = $propertyNameParts[1]; $propertyNamespace = $wgContLang->getNsText(SMW_NS_PROPERTY); if ($namespace != $propertyNamespace) { $this->addError(wfMessage('smw_wrong_namespace', $propertyNamespace)->inContentLanguage()->text()); } } $propertyName = smwfNormalTitleText($propertyName); try { $diProperty = SMWDIProperty::newFromUserLabel($propertyName); } catch (SMWDataItemException $e) { $diProperty = new SMWDIProperty('Error'); $this->addError(wfMessage('smw_noproperty', $propertyName)->inContentLanguage()->text()); } $this->m_diProperties[] = $diProperty; $stringValue .= ($stringValue ? ';' : '') . $diProperty->getKey(); } $this->m_dataitem = new SMWDIBlob($stringValue); }
protected function parseUserValue($value) { global $wgContLang, $smwgHistoricTypeNamespace; if ($this->m_caption === false) { $this->m_caption = $value; } $valueParts = explode(':', $value, 2); if ($smwgHistoricTypeNamespace && count($valueParts) > 1) { $namespace = smwfNormalTitleText($valueParts[0]); $value = $valueParts[1]; $typeNamespace = $wgContLang->getNsText(SMW_NS_TYPE); if ($namespace != $typeNamespace) { $this->addError(wfMessage('smw_wrong_namespace', $typeNamespace)->inContentLanguage()->text()); } } if ($value[0] === '_') { $this->m_typeId = $value; } else { $this->m_givenLabel = smwfNormalTitleText($value); $this->m_typeId = DataTypeRegistry::getInstance()->findTypeId($this->m_givenLabel); } if ($this->m_typeId === '') { $this->addError(wfMessage('smw_unknowntype', $this->m_givenLabel)->inContentLanguage()->text()); $this->m_realLabel = $this->m_givenLabel; } else { $this->m_realLabel = DataTypeRegistry::getInstance()->findTypeLabel($this->m_typeId); } $this->m_isAlias = $this->m_realLabel === $this->m_givenLabel ? false : true; try { $this->m_dataitem = self::getTypeUriFromTypeId($this->m_typeId); } catch (SMWDataItemException $e) { $this->m_dataitem = self::getTypeUriFromTypeId('notype'); $this->addError(wfMessage('smw_parseerror')->inContentLanguage()->text()); } }
protected function parseUserValue($value) { global $smwgHistoricTypeNamespace; if ($this->m_caption === false) { $this->m_caption = $value; } $valueParts = explode(':', $value, 2); $contentLanguage = $this->getOptionBy(self::OPT_CONTENT_LANGUAGE); if ($smwgHistoricTypeNamespace && count($valueParts) > 1) { $namespace = smwfNormalTitleText($valueParts[0]); $value = $valueParts[1]; $typeNamespace = Localizer::getInstance()->getLanguage($contentLanguage)->getNsText(SMW_NS_TYPE); if ($namespace != $typeNamespace) { $this->addErrorMsg(array('smw_wrong_namespace', $typeNamespace)); } } if ($value !== '' && $value[0] === '_') { $this->m_typeId = $value; } else { $this->m_givenLabel = smwfNormalTitleText($value); $this->m_typeId = DataTypeRegistry::getInstance()->findTypeIdByLanguage($this->m_givenLabel, $contentLanguage); } if ($this->m_typeId === '') { $this->addErrorMsg(array('smw_unknowntype', $this->m_givenLabel)); $this->m_realLabel = $this->m_givenLabel; } else { $this->m_realLabel = DataTypeRegistry::getInstance()->findTypeLabel($this->m_typeId); } $this->m_isAlias = $this->m_realLabel === $this->m_givenLabel ? false : true; try { $this->m_dataitem = self::getTypeUriFromTypeId($this->m_typeId); } catch (SMWDataItemException $e) { $this->m_dataitem = self::getTypeUriFromTypeId('notype'); $this->addErrorMsg(array('smw-datavalue-type-invalid-typeuri', $this->m_typeId)); } }
/** * Compute an SMWDescription for current part of a query, which should * be the content of "[[ ... ]]". Returns NULL upon error. * * Parameters $setNS has the same use as in getSubqueryDescription(). */ private function getLinkDescription(&$setNS) { // This method is called when we encountered an opening '[['. The following // block could be a Category-statement, fixed object, or property statement. $chunk = $this->readChunk('', true, false); // NOTE: untrimmed, initial " " escapes prop. chains if (in_array(smwfNormalTitleText($chunk), array($this->categoryPrefix, $this->conceptPrefix, $this->categoryPrefixCannonical, $this->conceptPrefixCannonical))) { return $this->getClassDescription($setNS, smwfNormalTitleText($chunk) == $this->categoryPrefix || smwfNormalTitleText($chunk) == $this->categoryPrefixCannonical); } else { // fixed subject, namespace restriction, property query, or subquery $sep = $this->readChunk('', false); // do not consume hit, "look ahead" if ($sep == '::' || $sep == ':=') { if ($chunk[0] != ':') { // property statement return $this->getPropertyDescription($chunk, $setNS); } else { // escaped article description, read part after :: to get full contents $chunk .= $this->readChunk('\\[\\[|\\]\\]|\\|\\||\\|'); return $this->getArticleDescription(trim($chunk), $setNS); } } else { // Fixed article/namespace restriction. $sep should be ]] or || return $this->getArticleDescription(trim($chunk), $setNS); } } }
protected function getLinkDescription( &$setNS, &$label, &$relatedArticles ) { // This method is called when we encountered an opening '[['. The following // block could be a Category-statement, fixed object, property statements, // or according print statements. $chunk = $this->readChunk( '', true, false ); // NOTE: untrimmed, initial " " escapes prop. chains if ( ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) || // category statement or ( smwfNormalTitleText( $chunk ) == $this->m_conceptprefix ) ) { // concept statement return $this->getClassDescription( $setNS, $label, $relatedArticles, ( smwfNormalTitleText( $chunk ) == $this->m_categoryprefix ) ); } else { // fixed subject, namespace restriction, property query, or subquery $sep = $this->readChunk( '', false ); // do not consume hit, "look ahead" if ( ( $sep == '::' ) || ( $sep == ':=' ) ) { if ( $chunk { 0 } != ':' ) { // property statement return $this->getPropertyDescription( $chunk, $setNS, $label, $relatedArticles ); } else { // escaped article description, read part after :: to get full contents $chunk .= $this->readChunk( '\[\[|\]\]|\|\||\|' ); return $this->getArticleDescription( trim( $chunk ), $setNS, $label, $relatedArticles ); } } else { // Fixed article/namespace restriction. $sep should be ]] or || return $this->getArticleDescription( trim( $chunk ), $setNS, $label, $relatedArticles ); } } }
/** * Extended parsing function to first check whether value refers to pre-defined * property, resolve aliases, and set internal property id accordingly. * @todo Accept/enforce property namespace. */ protected function parseUserValue($value) { $this->mPropTypeValue = null; $this->m_wikipage = null; if ($this->m_caption === false) { // always use this as caption $this->m_caption = $value; } $propertyName = smwfNormalTitleText(ltrim(rtrim($value, ' ]'), ' [')); // slightly normalise label $inverse = false; if ($propertyName !== '' && $propertyName[0] == '-') { // property refers to an inverse $propertyName = smwfNormalTitleText((string) substr($value, 1)); /// NOTE The cast is necessary at least in PHP 5.3.3 to get string '' instead of boolean false. /// NOTE It is necessary to normalize again here, since normalization may uppercase the first letter. $inverse = true; } try { $this->m_dataitem = SMWDIProperty::newFromUserLabel($propertyName, $inverse, $this->m_typeid); } catch (SMWDataItemException $e) { // happens, e.g., when trying to sort queries by property "-" $this->addError(wfMessage('smw_noproperty', $value)->inContentLanguage()->text()); $this->m_dataitem = new SMWDIProperty('ERROR', false); // just to have something } }
private function doNormalizeUserValue($value) { if (($pos = strpos($value, '#')) !== false && strlen($value) > 1 || ($pos = strpos($value, '[')) !== false) { $this->addErrorMsg(array('smw-datavalue-property-invalid-name', $value, substr($value, $pos, 1))); $this->m_dataitem = new DIProperty('ERROR', false); } // #1727 <Foo> or <Foo-<Bar> are not permitted but // Foo-<Bar will be converted to Foo- $value = strip_tags(htmlspecialchars_decode($value)); $inverse = false; // Enforce upper case for the first character on annotations that are used // within the property namespace in order to avoid confusion when // $wgCapitalLinks setting is disabled if ($this->getContextPage() !== null && $this->getContextPage()->getNamespace() === SMW_NS_PROPERTY) { // ucfirst is not utf-8 safe hence the reliance on mb_strtoupper $value = mb_strtoupper(mb_substr($value, 0, 1)) . mb_substr($value, 1); } // slightly normalise label $propertyName = smwfNormalTitleText(ltrim(rtrim($value, ' ]'), ' [')); if ($propertyName !== '' && $propertyName[0] == '-') { // property refers to an inverse $propertyName = smwfNormalTitleText((string) substr($value, 1)); /// NOTE The cast is necessary at least in PHP 5.3.3 to get string '' instead of boolean false. /// NOTE It is necessary to normalize again here, since normalization may uppercase the first letter. $inverse = true; } return array($propertyName, $inverse); }