/** * Returns a list of entities a given site is subscribed to. * * @param string $siteId Site ID of the client site. * @param EntityId[]|null $entityIds The entities we are interested in, or null for "any". * * @return EntityId[] a list of entity IDs the client wiki is subscribed to. * The result is limited to entity ids also present in $entityIds, if given. */ public function getSubscriptions($siteId, array $entityIds) { // NOTE: non-Item ids are ignored, since only items can be subscribed to // via sitelinks. $entityIds = $this->getItemIds($entityIds); $numericIds = array_keys($entityIds); if (empty($numericIds)) { return array(); } $links = $this->siteLinkLookup->getLinks($numericIds, array($siteId)); // collect the item IDs present in these links $linkedItems = array(); foreach ($links as $link) { list(, , $id) = $link; $linkedItems[$id] = $entityIds[$id]; } return $linkedItems; }
/** * Load the sitelink using a SiteLinkLookup. Resolves item redirects, if needed. * * @param string $site * @param ItemId $itemId * * @return array[] */ private function loadLinks($site, ItemId $itemId) { $links = $this->siteLinkLookup->getLinks(array($itemId->getNumericId()), array($site)); if (isset($links[0])) { return $links; } // Maybe the item is a redirect: Try to resolve the redirect and load // the links from there. $redirectTarget = $this->redirectLookup->getRedirectForEntityId($itemId); if ($redirectTarget instanceof ItemId) { return $this->siteLinkLookup->getLinks(array($redirectTarget->getNumericId()), array($site)); } return array(); }
/** * @see UsageLookup::getUnusedEntities * * @param EntityId[] $entityIds * * @return EntityId[] A list of elements of $entities that are unused. */ public function getUnusedEntities(array $entityIds) { if (empty($entityIds)) { return array(); } // Non-item entities are always considered unused by this implementation. $nonItemIds = array_filter($entityIds, function (EntityId $id) { return !$id instanceof ItemId; }); $numericItemIds = $this->getNumericItemIds($entityIds); $rows = $this->siteLinkLookup->getLinks($numericItemIds, array($this->clientSiteId)); $used = $this->getItemIdsFromSiteLinkRows($rows); $unusedIds = array_diff($numericItemIds, $used); return array_merge($nonItemIds, $this->makeItemIds($unusedIds)); }
/** * @param string $prefixedEntityId * * @since 0.5 * @return string|null Null if no site link found. */ public function getSiteLinkPageName($prefixedEntityId) { try { $itemId = new ItemId($prefixedEntityId); } catch (InvalidArgumentException $e) { return null; } // @fixme the SiteLinks do not contain badges! but all we want here is page name. $siteLinkRows = $this->siteLinkLookup->getLinks(array($itemId->getNumericId()), array($this->siteId)); foreach ($siteLinkRows as $siteLinkRow) { $siteLink = new SiteLink($siteLinkRow[0], $siteLinkRow[1]); $this->usageAccumulator->addTitleUsage($itemId); return $siteLink->getPageName(); } return null; }
/** * @see SiteLinkLookup::getLinks * This is uncached! * * @param int[] $numericIds Numeric (unprefixed) item ids * @param string[] $siteIds * @param string[] $pageNames * * @return array[] */ public function getLinks(array $numericIds = array(), array $siteIds = array(), array $pageNames = array()) { // Caching this would be rather complicated for little to no benefit. return $this->lookup->getLinks($numericIds, $siteIds, $pageNames); }