public function getEntityTitleProvider()
 {
     $itemId = ItemId::newFromNumber(388);
     $propertyId = PropertyId::newFromNumber(472);
     $settings = $this->getRepoSettings();
     return array(array('Q388', $settings[0], $itemId), array('Item:Q388', $settings[2], $itemId), array('Property:P472', $settings[0], $propertyId));
 }
 private function parseItemList(array $itemNumericIds)
 {
     $itemIds = [];
     foreach ($itemNumericIds as $itemNumericId) {
         $itemIds[] = ItemId::newFromNumber($itemNumericId);
     }
     return $itemIds;
 }
 /**
  * @param string $entityType
  * @param int|float|string $numericId
  *
  * @return EntityId
  * @throws InvalidArgumentException
  */
 public static function newIdFromTypeAndNumber($entityType, $numericId)
 {
     if ($entityType === 'item') {
         return ItemId::newFromNumber($numericId);
     } elseif ($entityType === 'property') {
         return PropertyId::newFromNumber($numericId);
     }
     throw new InvalidArgumentException('Invalid entityType ' . $entityType);
 }
Beispiel #4
0
 /**
  * Can be integer since 0.1.
  * Can be ItemId since 0.5.
  * Can be null since 1.0.
  *
  * @param ItemId|int|null $id
  *
  * @throws InvalidArgumentException
  */
 public function setId($id)
 {
     if ($id === null || $id instanceof ItemId) {
         $this->id = $id;
     } elseif (is_int($id)) {
         $this->id = ItemId::newFromNumber($id);
     } else {
         throw new InvalidArgumentException('$id must be an instance of ItemId, an integer,' . ' or null');
     }
 }
 /**
  * Get Message for a conflict
  *
  * @param array $conflict A record as returned by SiteLinkConflictLookup::getConflictsForItem()
  *
  * @return Error
  */
 private function getConflictError(array $conflict)
 {
     $entityId = ItemId::newFromNumber($conflict['itemId']);
     return new UniquenessViolation($entityId, 'SiteLink conflict', 'sitelink-conflict', array(new SiteLink($conflict['siteId'], $conflict['sitePage']), $entityId));
 }
 /**
  * @param ResultWrapper $res A result set with the ips_item_id and ips_site_id fields
  *        set for each row.
  * @param array &$continuation Single item ID => site ID pair or empty.
  *
  * @return array[] An associative array mapping item IDs to lists of site IDs.
  */
 private function getSubscriptionsPerItemFromRows(ResultWrapper $res, &$continuation = array())
 {
     $subscriptionsPerItem = array();
     $currentItemId = 0;
     $itemId = null;
     foreach ($res as $row) {
         if ($row->ips_item_id != $currentItemId) {
             $currentItemId = $row->ips_item_id;
             $itemId = ItemId::newFromNumber($currentItemId)->getSerialization();
         }
         $subscriptionsPerItem[$itemId][] = $row->ips_site_id;
         $continuation = array($currentItemId, $row->ips_row_id);
     }
     return $subscriptionsPerItem;
 }
 public function provideIds()
 {
     return array(array('Q1'), array(ItemId::newFromNumber(1)));
 }
 protected function getItemIdsFromRows($rows)
 {
     $itemIds = array();
     foreach ($rows as $row) {
         $itemIds[] = ItemId::newFromNumber((int) $row->entity_id);
     }
     return $itemIds;
 }
 /**
  * @see SiteLinkLookup::getItemIdForLink
  *
  * @todo may want to deprecate this or change it to always return entity id object only
  *
  * @param string $globalSiteId
  * @param string $pageTitle
  *
  * @return ItemId|null
  */
 public function getItemIdForLink($globalSiteId, $pageTitle)
 {
     // We store page titles with spaces instead of underscores
     $pageTitle = str_replace('_', ' ', $pageTitle);
     $db = $this->getConnection(DB_SLAVE);
     $result = $db->selectRow($this->table, array('ips_item_id'), array('ips_site_id' => $globalSiteId, 'ips_site_page' => $pageTitle));
     $this->releaseConnection($db);
     return $result === false ? null : ItemId::newFromNumber((int) $result->ips_item_id);
 }
Beispiel #10
0
 /**
  * @dataProvider invalidNumericIdProvider
  */
 public function testNewFromNumberWithInvalidNumericId($number)
 {
     $this->setExpectedException('InvalidArgumentException');
     ItemId::newFromNumber($number);
 }
 /**
  * @param int[] $numericIds
  *
  * @return ItemId[]
  */
 private function makeItemIds(array $numericIds)
 {
     return array_map(function ($numericId) {
         return ItemId::newFromNumber($numericId);
     }, $numericIds);
 }
 private function itemInfoToItemListElement(ItemInfo $itemInfo) : ItemListElement
 {
     $id = ItemId::newFromNumber($itemInfo->getNumericItemId());
     return (new ItemListElement())->setItemId($id)->setLabel($itemInfo->getEnglishLabel())->setLastUpdate($itemInfo->getRevisionTime())->setQueryrApiUrl($this->urlBuilder->getApiItemUrl($id))->setWikidataPageUrl($this->urlBuilder->getWdEntityUrl($id))->setWikipediaPageUrl($this->urlBuilder->getSiteLinkBasedRerirectUrl('enwiki', $id));
 }