예제 #1
0
 /**
  * @see ValueFormatter::format
  *
  * @param StringValue $dataValue
  *
  * @throws InvalidArgumentException
  * @return string Text
  */
 public function format($dataValue)
 {
     if (!$dataValue instanceof StringValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a StringValue.');
     }
     return $dataValue->getValue();
 }
 public function descriptionProvider()
 {
     $argLists = array();
     $p1337 = new StringValue('1337prop');
     $argLists[] = array(new AnyValue(), array('objectType' => 'description', 'descriptionType' => 'anyValue', 'value' => array()));
     $argLists[] = array(new SomeProperty($p1337, new AnyValue()), array('objectType' => 'description', 'descriptionType' => 'someProperty', 'value' => array('property' => $p1337->toArray(), 'description' => array('objectType' => 'description', 'descriptionType' => 'anyValue', 'value' => array()), 'isSubProperty' => false)));
     return $argLists;
 }
 public function sortExpressionProvider()
 {
     $argLists = array();
     $p1337 = new StringValue('1337prop');
     $argLists[] = array(new PropertyValueSortExpression($p1337, SortExpression::DIRECTION_ASCENDING), array('objectType' => 'sortExpression', 'sortExpressionType' => 'propertyValue', 'value' => array('property' => $p1337->toArray(), 'direction' => SortExpression::DIRECTION_ASCENDING)));
     $argLists[] = array(new PropertyValueSortExpression($p1337, SortExpression::DIRECTION_DESCENDING), array('objectType' => 'sortExpression', 'sortExpressionType' => 'propertyValue', 'value' => array('property' => $p1337->toArray(), 'direction' => SortExpression::DIRECTION_DESCENDING)));
     return $argLists;
 }
 public function selectionRequestProvider()
 {
     $argLists = array();
     $argLists[] = array(new SubjectSelection(), array('objectType' => 'selectionRequest', 'selectionRequestType' => 'subject', 'value' => array()));
     $stringValue = new StringValue('foo');
     $argLists[] = array(new PropertySelection($stringValue), array('objectType' => 'selectionRequest', 'selectionRequestType' => 'property', 'value' => array('property' => $stringValue->toArray())));
     return $argLists;
 }
 /**
  * @see ValueFormatter::format
  *
  * Formats the given URL as an HTML link
  *
  * @param StringValue $value The URL to turn into a link
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 public function format($value)
 {
     if (!$value instanceof StringValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a StringValue.');
     }
     $url = $value->getValue();
     $attributes = array_merge($this->attributes, array('href' => $url));
     $html = Html::element('a', $attributes, $url);
     return $html;
 }
 /**
  * @see ValueFormatter::format
  *
  * Formats the given commons file name as an HTML link
  *
  * @since 0.5
  *
  * @param StringValue $value The commons file name to turn into a link
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 public function format($value)
 {
     if (!$value instanceof StringValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a StringValue.');
     }
     $fileName = $value->getValue();
     // We are using NS_MAIN only because makeTitleSafe requires a valid namespace
     // We cannot use makeTitle because it does not secureAndSplit()
     $title = Title::makeTitleSafe(NS_MAIN, $fileName);
     if ($title === null) {
         return htmlspecialchars($fileName);
     }
     $attributes = array_merge($this->attributes, array('href' => '//commons.wikimedia.org/wiki/File:' . $title->getPartialURL()));
     $html = Html::element('a', $attributes, $title->getText());
     return $html;
 }
 private function buildStringValueForSearch(PropertyId $propertyId, StringValue $stringValue)
 {
     return $propertyId->getSerialization() . '-' . $this->documentBuilder->buildSearchedStringValue($stringValue->getValue());
 }
예제 #8
0
 /**
  * @see ApiBase::getExamplesMessages
  */
 protected function getExamplesMessages()
 {
     $query = 'action=' . $this->getModuleName();
     $hello = new StringValue('hello');
     $acme = new StringValue('http://acme.org');
     return array($query . '&' . wfArrayToCgi(array('datavalue' => json_encode($hello->toArray()))) => 'apihelp-wbformatvalue-example-1', $query . '&' . wfArrayToCgi(array('datavalue' => json_encode($acme->toArray()), 'datatype' => 'url', 'generate' => 'text/html')) => 'apihelp-wbformatvalue-example-2');
 }
 public function propertyExpressionWithInvalidAttributeProvider()
 {
     $argLists = array();
     $p1337 = new StringValue('1337prop');
     $argLists[] = array(array('property' => $p1337->toArray(), 'direction' => 'hax'));
     $argLists[] = array(array('property' => null, 'direction' => SortExpression::DIRECTION_DESCENDING));
     return $argLists;
 }
 public function testValidRequests()
 {
     $argLists = array();
     $property = Property::newFromType('commonsMedia');
     $store = WikibaseRepo::getDefaultInstance()->getEntityStore();
     $store->saveEntity($property, '', $GLOBALS['wgUser'], EDIT_NEW);
     foreach ($this->getItems($property->getId()) as $item) {
         foreach ($item->getStatements()->toArray() as $statement) {
             $value = new StringValue('Kittens.png');
             $argLists[] = array('itemId' => $item->getId(), 'guid' => $statement->getGuid(), 'value' => $value->getArrayValue(), 'expectedSummary' => $this->getExpectedSummary($statement, $value));
         }
     }
     foreach ($argLists as $argList) {
         call_user_func_array(array($this, 'doTestValidRequest'), $argList);
     }
 }
 public function dataValueSerializationProvider()
 {
     $string = new StringValue('foo bar baz');
     $number = new NumberValue(42);
     return array(array($string->toArray(), 'string'), array($number->toArray(), 'number'));
 }
 protected function getExpectedSerialization(StringValue $p42, StringValue $p9001, StringValue $foo)
 {
     return array('objectType' => 'query', 'description' => array('objectType' => 'description', 'descriptionType' => 'conjunction', 'value' => array('descriptions' => array(array('objectType' => 'description', 'descriptionType' => 'someProperty', 'value' => array('property' => $p42->toArray(), 'description' => array('objectType' => 'description', 'descriptionType' => 'anyValue', 'value' => array()), 'isSubProperty' => false)), array('objectType' => 'description', 'descriptionType' => 'someProperty', 'value' => array('property' => $p9001->toArray(), 'description' => array('objectType' => 'description', 'descriptionType' => 'valueDescription', 'value' => array('value' => $foo->toArray(), 'comparator' => 'equal')), 'isSubProperty' => false))))), 'options' => array('objectType' => 'queryOptions', 'limit' => 100, 'offset' => 42, 'sort' => array('expressions' => array(array('objectType' => 'sortExpression', 'sortExpressionType' => 'propertyValue', 'value' => array('direction' => SortExpression::DIRECTION_ASCENDING, 'property' => $p42->toArray()))))), 'selectionRequests' => array(array('objectType' => 'selectionRequest', 'selectionRequestType' => 'subject', 'value' => array()), array('objectType' => 'selectionRequest', 'selectionRequestType' => 'property', 'value' => array('property' => $p42->toArray())), array('objectType' => 'selectionRequest', 'selectionRequestType' => 'property', 'value' => array('property' => $p9001->toArray()))));
 }
 /**
  * @dataProvider instanceProvider
  * @param StringValue $string
  * @param array $arguments
  */
 public function testGetValue(StringValue $string, array $arguments)
 {
     $this->assertEquals($arguments[0], $string->getValue());
 }