/**
  * @see UsageLookup::getUsagesForPage
  *
  * @param int $pageId
  *
  * @return EntityUsage[]
  * @throws UsageTrackerException
  */
 public function getUsagesForPage($pageId)
 {
     $usages = array();
     $title = $this->titleFactory->newFromID($pageId);
     $id = $this->siteLinkLookup->getItemIdForLink($this->clientSiteId, $title->getPrefixedText());
     if ($id !== null) {
         $usages[] = new EntityUsage($id, EntityUsage::SITELINK_USAGE);
     }
     return $usages;
 }
 /**
  * Get entity id from page title.
  *
  * @since 0.5
  *
  * @param string $pageTitle
  *
  * @return string|null
  */
 public function getEntityId($pageTitle)
 {
     $id = $this->siteLinkLookup->getItemIdForLink($this->siteId, $pageTitle);
     if (!$id) {
         return null;
     }
     $this->usageAccumulator->addTitleUsage($id);
     return $id->getSerialization();
 }
Example #3
0
 /**
  * @param string $site
  * @param string $title
  *
  * @throws UsageException If no such entity is found.
  * @return EntityId The ID of the entity connected to $title on $site.
  */
 protected function getEntityIdFromSiteTitleCombination($site, $title)
 {
     // FIXME: Normalization missing, see T47282.
     $itemId = $this->siteLinkLookup->getItemIdForLink($site, $title);
     if ($itemId === null) {
         $this->errorReporter->dieError('No entity found matching site link ' . $site . ':' . $title, 'no-such-entity-link');
     }
     return $itemId;
 }
 /**
  * Finds the corresponding item on the repository and returns the item's site links.
  *
  * @since 0.1
  *
  * @param Title $title
  *
  * @return SiteLink[] A map of SiteLinks, indexed by global site id.
  */
 public function getEntityLinks(Title $title)
 {
     $links = array();
     $itemId = $this->siteLinkLookup->getItemIdForLink($this->siteId, $title->getPrefixedText());
     if ($itemId !== null) {
         //NOTE: SiteLinks we could get from $this->siteLinkLookup do not contain badges,
         //      so we have to fetch the links from the Item.
         /* @var Item $item */
         $item = $this->entityLookup->getEntity($itemId);
         if ($item) {
             $links = iterator_to_array($item->getSiteLinkList());
             $links = $this->indexLinksBySiteId($links);
         } else {
             wfLogWarning(__METHOD__ . ": Could not load item " . $itemId->getSerialization() . " for " . $title->getPrefixedText());
         }
     }
     return $links;
 }
 /**
  * @see SpecialWikibasePage::execute
  *
  * @since 0.1
  *
  * @param string|null $subPage
  */
 public function execute($subPage)
 {
     parent::execute($subPage);
     // Setup
     $request = $this->getRequest();
     $parts = $subPage === '' ? array() : explode('/', $subPage, 2);
     $site = trim($request->getVal('site', isset($parts[0]) ? $parts[0] : ''));
     $page = trim($request->getVal('page', isset($parts[1]) ? $parts[1] : ''));
     $itemContent = null;
     // If there are enough data, then try to lookup the item content
     if ($site !== '' && $page !== '') {
         // FIXME: This code is duplicated in ItemByTitleHelper::getItemId!
         // Try to get a item content
         $siteId = $this->stringNormalizer->trimToNFC($site);
         // no stripping of underscores here!
         $pageName = $this->stringNormalizer->trimToNFC($page);
         if (!$this->sites->getSite($siteId)) {
             // HACK: If the site ID isn't known, add "wiki" to it; this allows the wikipedia
             // subdomains to be used to refer to wikipedias, instead of requiring their
             // full global id to be used.
             // @todo: Ideally, if the site can't be looked up by global ID, we
             // should try to look it up by local navigation ID.
             // Support for this depends on bug T50934.
             $siteId .= 'wiki';
         }
         /* @var ItemHandler $itemHandler */
         $itemId = $this->siteLinkLookup->getItemIdForLink($siteId, $pageName);
         // Do we have an item content, and if not can we try harder?
         if ($itemId === null) {
             // Try harder by requesting normalization on the external site
             $siteObj = $this->sites->getSite($siteId);
             if ($siteObj instanceof Site) {
                 $pageName = $siteObj->normalizePageName($page);
                 $itemId = $this->siteLinkLookup->getItemIdForLink($siteId, $pageName);
             }
         }
         // Redirect to the item page if we found its content
         if ($itemId !== null) {
             $title = $this->titleLookup->getTitleForId($itemId);
             $query = $request->getValues();
             unset($query['title']);
             unset($query['site']);
             unset($query['page']);
             $itemUrl = $title->getFullUrl($query);
             $this->getOutput()->redirect($itemUrl);
             return;
         }
     }
     // If there is no item content post the switch form
     $this->switchForm($site, $page);
 }
 /**
  * Tries to find item id for given siteId and title combination
  *
  * @param string $siteId
  * @param string $title
  * @param bool $normalize
  *
  * @return ItemId|null
  */
 private function getItemId($siteId, $title, $normalize)
 {
     // FIXME: This code is duplicated in SpecialItemByTitle::execute!
     $title = $this->stringNormalizer->trimToNFC($title);
     $id = $this->siteLinkLookup->getItemIdForLink($siteId, $title);
     // Try harder by requesting normalization on the external site.
     if ($id === null && $normalize === true) {
         $siteObj = $this->siteStore->getSite($siteId);
         //XXX: this passes the normalized title back into $title by reference...
         $this->normalizeTitle($title, $siteObj);
         $id = $this->siteLinkLookup->getItemIdForLink($siteObj->getGlobalId(), $title);
     }
     return $id;
 }
 /**
  * @param string $globalSiteId
  * @param string $pageTitle
  *
  * @return ItemId|null
  */
 private function getAndCacheItemIdForLink($globalSiteId, $pageTitle)
 {
     $itemId = $this->lookup->getItemIdForLink($globalSiteId, $pageTitle);
     $this->cache->set($this->getByPageCacheKey($globalSiteId, $pageTitle), $itemId instanceof ItemId ? $itemId->getSerialization() : null, $this->cacheDuration);
     return $itemId;
 }
 /**
  * @param Title $title
  *
  * @return ItemId|null
  */
 private function getItemIdForTitle(Title $title)
 {
     return $this->siteLinkLookup->getItemIdForLink($this->siteId, $title->getPrefixedText());
 }