/** * @param OutputPage $out * * @return bool */ public function doOutputPageBeforeHtmlRegisterConfig(OutputPage $out) { if (!$this->entityNamespaceLookup->isEntityNamespace($out->getTitle()->getNamespace())) { return true; } $this->handle($out); return true; }
/** * Construct query conditions * * @since 0.4 * * @param int $lastPageSeen * * @return array */ protected function getQueryConds($lastPageSeen) { global $wgContentHandlerUseDB; $conds = array('page_namespace' => $this->entityNamespaceLookup->getEntityNamespaces(), 'page_id > ' . (int) $lastPageSeen); if ($wgContentHandlerUseDB) { $conds['page_content_model'] = $this->contentModels; } if ($this->rebuildAll === false) { $conds[] = 'epp_page_id IS NULL'; } return $conds; }
/** * @param Title $target * @param string &$html * @param array &$customAttribs * @param RequestContext $context */ public function doOnLinkBegin(Title $target, &$html, array &$customAttribs, RequestContext $context) { $out = $context->getOutput(); if (!$this->entityNamespaceLookup->isEntityNamespace($target->getNamespace())) { return; } // Only continue on pages with edit summaries (histories / diffs) or on special pages. // Don't run this code when accessing it through the api (eg. for parsing) as the title is // set to a special page dummy in api.php, see https://phabricator.wikimedia.org/T111346 if (defined('MW_API') || !$this->shouldConvert($out->getTitle(), $context)) { return; } $targetText = $target->getText(); // Handle "fake" titles for new entities as generated by // EditEntity::getContextForEditFilter(). For instance, a link to Property:NewProperty // would be replaced by a link to Special:NewProperty. This is useful in logs, // to indicate that the logged action occurred while creating an entity. if (SpecialPageFactory::exists($targetText)) { $target = Title::makeTitle(NS_SPECIAL, $targetText); $html = Linker::linkKnown($target); return; } if (!$target->exists()) { // The link points to a non-existing item. return; } // if custom link text is given, there is no point in overwriting it // but not if it is similar to the plain title if ($html !== null && $target->getFullText() !== $html) { return; } $entityId = $this->entityIdLookup->getEntityIdForTitle($target); if (!$entityId) { return; } // @todo: this re-implements the logic in LanguageFallbackLabelDescriptionLookup, // as that didn't support descriptions back when this code was written. // NOTE: keep in sync with with fallback languages in LabelPrefetchHookHandler::newFromGlobalState try { $labels = $this->termLookup->getLabels($entityId, $this->languageFallback->getFetchLanguageCodes()); $descriptions = $this->termLookup->getDescriptions($entityId, $this->languageFallback->getFetchLanguageCodes()); } catch (StorageException $ex) { // This shouldn't happen if $target->exists() return true! return; } $labelData = $this->getPreferredTerm($labels); $descriptionData = $this->getPreferredTerm($descriptions); $html = $this->getHtml($target, $labelData); $customAttribs['title'] = $this->getTitleAttribute($target, $labelData, $descriptionData); // add wikibase styles in all cases, so we can format the link properly: $out->addModuleStyles(array('wikibase.common')); }
public function testIsCoreNamespace() { $this->assertTrue(EntityNamespaceLookup::isCoreNamespace(4), '4 is a core namespace'); $this->assertFalse(EntityNamespaceLookup::isCoreNamespace(9000), '9000 is not a core namespace'); }