Wikibase
MediaWiki Wikibase extension
Wikibase\Client\Hooks\LangLinkHandler Class Reference

Public Member Functions

 __construct (LanguageLinkBadgeDisplay $badgeDisplay, NamespaceChecker $namespaceChecker, SiteLinksForDisplayLookup $siteLinkForDisplayLookup, SiteLookup $siteLookup, $siteId, $siteGroup)
 
 useRepoLinks (Title $title, ParserOutput $out)
 Checks if a page have interwiki links from Wikidata repo? Disabled for a page when either: More...
 
 suppressRepoLinks (ParserOutput $out, array $repoLinks)
 Returns a filtered version of $repoLinks, containing only links that should be considered for combining with the local inter-language links. More...
 
 filterRepoLinksByGroup (array $repoLinks, array $allowedGroups)
 Filters the given list of links by site group: Any links pointing to a site that is not in $allowedGroups will be removed. More...
 
 getNoExternalLangLinks (ParserOutput $out)
 Get the noexternallanglinks page property from the ParserOutput, which is set by the {{#noexternallanglinks}} parser function. More...
 
 getEffectiveRepoLinks (Title $title, ParserOutput $out)
 Look up sitelinks for the given title on the repository and filter them taking into account any applicable configuration and any use of the {{#noexternallanglinks}} function on the page. More...
 
 addLinksFromRepository (Title $title, ParserOutput $out)
 Look up sitelinks for the given title on the repository and add them to the ParserOutput object, taking into account any applicable configuration and any use of the {{#noexternallanglinks}} function on the page. More...
 
 getInterwikiCodeFromSite (Site $site)
 Extracts the local interwiki code, which in case of the wikimedia site groups, is always the global id's prefix. More...
 

Private Member Functions

 indexLinksByInterwiki (array $links)
 
 localLinksToArray (array $flatLinks)
 Converts a list of interwiki links into an associative array that maps global site IDs to the respective target pages on the designated wikis. More...
 
 addLinksToOutput (array $links, ParserOutput $out)
 Adds the given SiteLinks to the given ParserOutput. More...
 

Private Attributes

 $badgeDisplay
 
 $namespaceChecker
 
 $siteLinksForDisplayLookup
 
 $siteLookup
 
 $siteId
 
 $siteGroup
 

Detailed Description

Todo:
split this up and find a better home for stuff that adds parser output properties and extension data.
Author
Nikola Smolenski smole.nosp@m.nsk@.nosp@m.eunet.nosp@m..rs
Daniel Kinzler
Katie Filbert < aude..nosp@m.wiki.nosp@m.@gmai.nosp@m.l.co.nosp@m.m >

Constructor & Destructor Documentation

◆ __construct()

Wikibase\Client\Hooks\LangLinkHandler::__construct ( LanguageLinkBadgeDisplay  $badgeDisplay,
NamespaceChecker  $namespaceChecker,
SiteLinksForDisplayLookup  $siteLinkForDisplayLookup,
SiteLookup  $siteLookup,
  $siteId,
  $siteGroup 
)
Parameters
LanguageLinkBadgeDisplay$badgeDisplay
NamespaceChecker$namespaceCheckerdetermines which namespaces wikibase is enabled on
SiteLinksForDisplayLookup$siteLinkForDisplayLookup
SiteLookup$siteLookup
string$siteIdThe global site ID for the local wiki
string$siteGroupThe ID of the site group to use for showing language links.

Member Function Documentation

◆ addLinksFromRepository()

Wikibase\Client\Hooks\LangLinkHandler::addLinksFromRepository ( Title  $title,
ParserOutput  $out 
)

Look up sitelinks for the given title on the repository and add them to the ParserOutput object, taking into account any applicable configuration and any use of the {{#noexternallanglinks}} function on the page.

The language links are not sorted, call sortLanguageLinks() to do that.

Parameters
Title$titleThe page's title
ParserOutput$outParsed representation of the page

◆ addLinksToOutput()

Wikibase\Client\Hooks\LangLinkHandler::addLinksToOutput ( array  $links,
ParserOutput  $out 
)
private

Adds the given SiteLinks to the given ParserOutput.

Parameters
SiteLink[]$links
ParserOutput$out

◆ filterRepoLinksByGroup()

Wikibase\Client\Hooks\LangLinkHandler::filterRepoLinksByGroup ( array  $repoLinks,
array  $allowedGroups 
)

Filters the given list of links by site group: Any links pointing to a site that is not in $allowedGroups will be removed.

Parameters
array$repoLinksAn array that uses global site IDs as keys.
string[]$allowedGroupsA list of allowed site groups
Returns
array A filtered copy of $repoLinks, retaining only the links pointing to a site in an allowed group.

◆ getEffectiveRepoLinks()

Wikibase\Client\Hooks\LangLinkHandler::getEffectiveRepoLinks ( Title  $title,
ParserOutput  $out 
)

Look up sitelinks for the given title on the repository and filter them taking into account any applicable configuration and any use of the {{#noexternallanglinks}} function on the page.

The result is an associative array of links that should be added to the current page, excluding any target sites for which there already is a link on the page.

Parameters
Title$titleThe page's title
ParserOutput$outParsed representation of the page
Returns
SiteLink[] An associative array, using site IDs for keys and the target pages in the respective languages as the associated value.

◆ getInterwikiCodeFromSite()

Wikibase\Client\Hooks\LangLinkHandler::getInterwikiCodeFromSite ( Site  $site)

Extracts the local interwiki code, which in case of the wikimedia site groups, is always the global id's prefix.

@fixme put somewhere more sane and use site identifiers data, so that this works in non-wikimedia cases where the assumption is not true.

Parameters
Site$site
Returns
string

◆ getNoExternalLangLinks()

Wikibase\Client\Hooks\LangLinkHandler::getNoExternalLangLinks ( ParserOutput  $out)

Get the noexternallanglinks page property from the ParserOutput, which is set by the {{#noexternallanglinks}} parser function.

See also
NoLangLinkHandler::getNoExternalLangLinks
Parameters
ParserOutput$out
Returns
string[] A list of language codes, identifying which repository links to ignore. Empty if {{#noexternallanglinks}} was not used on the page.

◆ indexLinksByInterwiki()

Wikibase\Client\Hooks\LangLinkHandler::indexLinksByInterwiki ( array  $links)
private
Parameters
SiteLink[]$links
Returns
SiteLink[] The SiteLinks in $links, indexed by interwiki prefix.

◆ localLinksToArray()

Wikibase\Client\Hooks\LangLinkHandler::localLinksToArray ( array  $flatLinks)
private

Converts a list of interwiki links into an associative array that maps global site IDs to the respective target pages on the designated wikis.

Parameters
string[]$flatLinks
Returns
string[] An associative array, using site IDs for keys and the target pages on the respective wiki as the associated value.

◆ suppressRepoLinks()

Wikibase\Client\Hooks\LangLinkHandler::suppressRepoLinks ( ParserOutput  $out,
array  $repoLinks 
)

Returns a filtered version of $repoLinks, containing only links that should be considered for combining with the local inter-language links.

This takes into account the {{#noexternallanglinks}} parser function, and also removed any link to this wiki itself.

This function does not remove links to wikis for which there is already an inter-language link defined in the local wikitext. This is done later by getEffectiveRepoLinks().

Parameters
ParserOutput$out
array$repoLinksAn array that uses global site IDs as keys.
Returns
SiteLink[] A filtered copy of $repoLinks, with any inappropriate entries removed.

◆ useRepoLinks()

Wikibase\Client\Hooks\LangLinkHandler::useRepoLinks ( Title  $title,
ParserOutput  $out 
)

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)
Parameters
Title$title
ParserOutput$out
Returns
bool

Member Data Documentation

◆ $badgeDisplay

Wikibase\Client\Hooks\LangLinkHandler::$badgeDisplay
private

◆ $namespaceChecker

Wikibase\Client\Hooks\LangLinkHandler::$namespaceChecker
private

◆ $siteGroup

Wikibase\Client\Hooks\LangLinkHandler::$siteGroup
private

◆ $siteId

Wikibase\Client\Hooks\LangLinkHandler::$siteId
private

◆ $siteLinksForDisplayLookup

Wikibase\Client\Hooks\LangLinkHandler::$siteLinksForDisplayLookup
private

◆ $siteLookup

Wikibase\Client\Hooks\LangLinkHandler::$siteLookup
private

The documentation for this class was generated from the following file: