public function testCanNotGetAnnotatedLanguageCodeThatContainsInvalidCharacter() { $value = 'Foo@en#bar'; $this->assertFalse(Localizer::getAnnotatedLanguageCodeFrom($value)); }
/** * Construct a property from a user-supplied label. The main difference * to the normal constructor of DIProperty is that it is checked * whether the label refers to a known predefined property. * Note that this function only gives access to the registry data that * DIProperty stores, but does not do further parsing of user input. * * To process wiki input, SMWPropertyValue should be used. * * @param $label string label for the property * @param $inverse boolean states if the inverse of the property is constructed * * @return DIProperty object */ public static function newFromUserLabel($label, $inverse = false, $languageCode = false) { if ($label !== '' && $label[0] == '-') { $label = substr($label, 1); $inverse = true; } // Special handling for when the user value contains a @LCODE marker if (($annotatedLanguageCode = Localizer::getAnnotatedLanguageCodeFrom($label)) !== false) { $languageCode = $annotatedLanguageCode; } $id = false; $label = str_replace('_', ' ', $label); if ($languageCode) { $id = PropertyRegistry::getInstance()->findPropertyIdFromLabelByLanguageCode($label, $languageCode); } if ($id !== false) { return new self($id, $inverse); } $id = PropertyRegistry::getInstance()->findPropertyIdByLabel($label); if ($id === false) { return new self(str_replace(' ', '_', $label), $inverse); } return new self($id, $inverse); }
private function getPropertyLink($subject, $properties, $value, $valueCaption) { // #1855 if (substr($value, 0, 3) === '@@@') { $property = end($properties); $dataValue = $this->dataValueFactory->newPropertyValueByLabel($property, $valueCaption, $subject); if (($lang = Localizer::getAnnotatedLanguageCodeFrom($value)) !== false) { $dataValue->setOption($dataValue::OPT_USER_LANGUAGE, $lang); $dataValue->setCaption($valueCaption === false ? $dataValue->getWikiValue() : $valueCaption); } return $dataValue->getShortWikitext(smwfGetLinker()); } return ''; }