/**
  * @param string $oldTypeId
  * @param string $newTypeId
  *
  * @throws InvalidArgumentException
  */
 private function assertDataTypesCompatible($oldTypeId, $newTypeId)
 {
     $oldType = $this->dataTypeFactory->getType($oldTypeId);
     $newType = $this->dataTypeFactory->getType($newTypeId);
     if ($oldType->getDataValueType() !== $newType->getDataValueType()) {
         throw new InvalidArgumentException("New and old data type must have the same data value type.");
     }
 }
 /**
  * Builds and returns the HTML representing a property entity's data type information.
  *
  * @param string $propertyType
  *
  * @return string HTML
  */
 private function getHtmlForDataType($propertyType)
 {
     $html = $this->templateFactory->render('wb-section-heading', wfMessage('wikibase-propertypage-datatype')->escaped(), 'datatype', 'wikibase-propertypage-datatype');
     try {
         $dataType = $this->dataTypeFactory->getType($propertyType);
         $html .= $this->templateFactory->render('wikibase-propertyview-datatype', htmlspecialchars($dataType->getLabel($this->language->getCode())));
     } catch (OutOfBoundsException $ex) {
         $html .= Html::rawElement('span', array('class' => 'error'), wfMessage('wikibase-propertypage-bad-datatype', $propertyType)->parse());
     }
     return $html;
 }
 /**
  * Validates the given data value using the given data type.
  *
  * @param DataValue $dataValue
  * @param string    $dataTypeId
  *
  * @return Result
  */
 public function validateDataValue(DataValue $dataValue, $dataTypeId)
 {
     try {
         $dataValueType = $this->dataTypeFactory->getType($dataTypeId)->getDataValueType();
     } catch (OutOfBoundsException $ex) {
         return Result::newError(array(Error::newError('Bad data type: ' . $dataTypeId, null, 'bad-data-type', array($dataTypeId))));
     }
     if ($dataValue instanceof UnDeserializableValue) {
         return Result::newError(array(Error::newError('Bad snak value: ' . $dataValue->getReason(), null, 'bad-value', array($dataValue->getReason()))));
     } elseif ($dataValueType != $dataValue->getType()) {
         return Result::newError(array(Error::newError('Bad value type: ' . $dataValue->getType() . ', expected ' . $dataValueType, null, 'bad-value-type', array($dataValue->getType(), $dataValueType))));
     }
     $result = Result::newSuccess();
     //XXX: DataTypeValidatorFactory should expose only one validator, which would be a CompositeValidator
     foreach ($this->validatorFactory->getValidators($dataTypeId) as $validator) {
         $subResult = $validator->validate($dataValue);
         //XXX: Some validators should be fatal and cause us to abort the loop.
         //     Others shouldn't.
         if (!$subResult->isValid()) {
             //TODO: Don't bail out immediately. Accumulate errors from all validators.
             //      We need Result::merge() for this.
             return $subResult;
         }
     }
     return $result;
 }
 private function getDataTypeFactory()
 {
     $dataTypes = array();
     $dataTypes[] = new DataType('rustydata', 'kittens');
     $dataTypes[] = new DataType('shinydata', 'kittens');
     $dataTypes[] = new DataType('otherdatatype', 'puppies');
     return DataTypeFactory::newFromTypes($dataTypes);
 }
 /**
  * @see SpecialPage::getSubpagesForPrefixSearch
  */
 protected function getSubpagesForPrefixSearch()
 {
     return $this->dataTypeFactory->getTypeIds();
 }
 /**
  * @see ApiBase::getAllowedParams
  */
 public function getAllowedParams()
 {
     return array('datatype' => array(ApiBase::PARAM_TYPE => $this->dataTypeFactory->getTypeIds(), ApiBase::PARAM_REQUIRED => false), 'parser' => array(self::PARAM_TYPE => $this->valueParserFactory->getParserIds(), self::PARAM_DEPRECATED => true, self::PARAM_REQUIRED => false), 'values' => array(self::PARAM_TYPE => 'string', self::PARAM_REQUIRED => true, self::PARAM_ISMULTI => true), 'options' => array(self::PARAM_TYPE => 'text', self::PARAM_REQUIRED => false), 'validate' => array(ApiBase::PARAM_TYPE => 'boolean'));
 }
 /**
  * Returns the expected value type for the given property data type
  *
  * @param string $dataTypeId A property data type id
  *
  * @return string A value type
  */
 private function getDataValueTypeForPropertyDataType($dataTypeId)
 {
     $dataType = $this->dataTypeFactory->getType($dataTypeId);
     return $dataType->getDataValueType();
 }