/**
  * @param IContextSource $context
  * @param array $pageInfo
  *
  * @return array
  */
 public function handle(IContextSource $context, array $pageInfo)
 {
     // Check if wikibase namespace is enabled
     $title = $context->getTitle();
     if ($this->namespaceChecker->isWikibaseEnabled($title->getNamespace()) && $title->exists()) {
         $pageInfo['header-basic'][] = $this->getPageInfoRow($context, $title);
     }
     return $pageInfo;
 }
 /**
  * @note in php5, $out is by passed by reference (by default, so &$out is not needed)
  *
  * @param OutputPage $out
  * @param string $actionName
  *
  * @return bool
  */
 public function addModules(OutputPage $out, $actionName)
 {
     $title = $out->getTitle();
     if (!$this->namespaceChecker->isWikibaseEnabled($title->getNamespace())) {
         return true;
     }
     $this->addStyleModules($out, $title, $actionName);
     $this->addJsModules($out, $title, $actionName);
     return true;
 }
 /**
  * @param Title $title
  * @param string $action
  * @param string[]|null $noExternalLangLinks
  *
  * @return bool
  */
 private function canHaveLink(Title $title, $action, array $noExternalLangLinks = null)
 {
     if ($action !== 'view') {
         return false;
     }
     if ($this->namespaceChecker->isWikibaseEnabled($title->getNamespace()) && $title->exists() && !$this->isSuppressed($noExternalLangLinks)) {
         return true;
     }
     return false;
 }
 /**
  * Parser function
  *
  * @since 0.5
  *
  * @param Parser &$parser
  * @param string[] $langs
  *
  * @return string
  */
 public function doHandle(&$parser, array $langs)
 {
     if (!$this->namespaceChecker->isWikibaseEnabled($parser->getTitle()->getNamespace())) {
         // shorten out
         return '';
     }
     $output = $parser->getOutput();
     $nel = array_merge(self::getNoExternalLangLinks($output), $langs);
     self::setNoExternalLangLinks($output, $nel);
     return '';
 }
 /**
  * Checks if a page have interwiki links from Wikidata repo?
  * Disabled for a page when either:
  * - Wikidata not enabled for namespace
  * - nel parser function = * (suppress all repo links)
  *
  * @since 0.1
  *
  * @param Title $title
  * @param ParserOutput $out
  *
  * @return bool
  */
 public function useRepoLinks(Title $title, ParserOutput $out)
 {
     // use repoLinks in only the namespaces specified in settings
     if ($this->namespaceChecker->isWikibaseEnabled($title->getNamespace()) === true) {
         $nel = $this->getNoExternalLangLinks($out);
         if (in_array('*', $nel)) {
             return false;
         }
         return true;
     }
     return false;
 }
 /**
  * Hook runs after internal parsing
  * @see https://www.mediawiki.org/wiki/Manual:Hooks/ContentAlterParserOutput
  *
  * @param Title $title
  * @param ParserOutput $parserOutput
  *
  * @return bool
  */
 public function doContentAlterParserOutput(Title $title, ParserOutput $parserOutput)
 {
     if (!$this->namespaceChecker->isWikibaseEnabled($title->getNamespace())) {
         // shorten out
         return true;
     }
     $useRepoLinks = $this->langLinkHandler->useRepoLinks($title, $parserOutput);
     if ($useRepoLinks) {
         // add links
         $this->langLinkHandler->addLinksFromRepository($title, $parserOutput);
     }
     $this->parserOutputDataUpdater->updateItemIdProperty($title, $parserOutput);
     $this->parserOutputDataUpdater->updateOtherProjectsLinksData($title, $parserOutput);
     $this->parserOutputDataUpdater->updateBadgesProperty($title, $parserOutput);
     if ($useRepoLinks || $this->alwaysSort) {
         $interwikiLinks = $parserOutput->getLanguageLinks();
         $sortedLinks = $this->interwikiSorter->sortLinks($interwikiLinks);
         $parserOutput->setLanguageLinks($sortedLinks);
     }
     return true;
 }
 /**
  * Adds the "other projects" section to the sidebar, if enabled project wide or
  * the user has the beta featured enabled.
  *
  * @param Skin $skin
  * @param array &$sidebar
  *
  * @return bool
  */
 public function doSidebarBeforeOutput(Skin $skin, array &$sidebar)
 {
     $outputPage = $skin->getContext()->getOutput();
     $title = $outputPage->getTitle();
     if (!$this->namespaceChecker->isWikibaseEnabled($title->getNamespace()) || !$outputPage->getProperty('wikibase_item')) {
         return true;
     }
     $betaFeatureEnabled = class_exists('\\BetaFeatures') && $this->otherProjectsLinksBeta && \BetaFeatures::isFeatureEnabled($skin->getContext()->getUser(), 'wikibase-otherprojects');
     if ($this->otherProjectsLinksDefault || $betaFeatureEnabled) {
         $otherProjectsSidebar = $outputPage->getProperty('wikibase-otherprojects-sidebar');
         // in case of stuff in cache without the other projects
         if ($otherProjectsSidebar === null) {
             $otherProjectsSidebarGenerator = $this->otherProjectsSidebarGeneratorFactory->getOtherProjectsSidebarGenerator();
             $otherProjectsSidebar = $otherProjectsSidebarGenerator->buildProjectLinkSidebar($title);
         }
         if (!empty($otherProjectsSidebar)) {
             $sidebar['wikibase-otherprojects'] = $otherProjectsSidebar;
         }
     }
     return true;
 }
 /**
  * @see NamespaceChecker::isWikibaseEnabled
  *
  * @param int $namespace
  *
  * @return bool
  */
 private function isWikibaseEnabled($namespace)
 {
     return $this->namespaceChecker->isWikibaseEnabled($namespace);
 }
 /**
  * @dataProvider wikibaseNamespacesProvider
  */
 public function testGetWikibaseNamespaces($excluded, $enabled, $expected)
 {
     $namespaceChecker = new NamespaceChecker($excluded, $enabled);
     $result = $namespaceChecker->getWikibaseNamespaces();
     $this->assertArrayEquals($expected, $result);
 }