aboutsummaryrefslogtreecommitdiffstats
path: root/includes/parser/LinkHolderArray.php
diff options
context:
space:
mode:
authorC. Scott Ananian <cscott@cscott.net>2020-12-10 18:39:12 -0500
committerC. Scott Ananian <cscott@cscott.net>2020-12-14 17:51:50 -0500
commitf9433de05e6d1ee8465dbd80cc322b3b0bc516c6 (patch)
treec5af3f83c5f7109c11be2d0f3df4be1578e2d2f6 /includes/parser/LinkHolderArray.php
parenta471ce8e00a3ac00ade4bb3559f3f862244e294a (diff)
downloadmediawikicore-f9433de05e6d1ee8465dbd80cc322b3b0bc516c6.tar.gz
mediawikicore-f9433de05e6d1ee8465dbd80cc322b3b0bc516c6.zip
api: Use GetLinkColours hook to export CSS classes in page info
Several important extensions (Disambiguator, ProofreadPage, and SoftRedirector) use the GetLinkColours hook to add additional CSS classes to links on article pages. Parsoid previously relied on backdoor knowledge of the way Disambiguator used the page property table to support these, but they should be exported properly from the API. Bug: T237538 Change-Id: I945940aa872541d7e01f1e543ca854231c857fe2
Diffstat (limited to 'includes/parser/LinkHolderArray.php')
-rw-r--r--includes/parser/LinkHolderArray.php50
1 files changed, 25 insertions, 25 deletions
diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php
index ec05287ad021..58cb19d9e08e 100644
--- a/includes/parser/LinkHolderArray.php
+++ b/includes/parser/LinkHolderArray.php
@@ -178,7 +178,7 @@ class LinkHolderArray {
return;
}
- $colours = [];
+ $classes = [];
$services = MediaWikiServices::getInstance();
$linkCache = $services->getLinkCache();
$output = $this->parent->getOutput();
@@ -189,7 +189,7 @@ class LinkHolderArray {
# Sort by namespace
ksort( $this->internals );
- $linkcolour_ids = [];
+ $pagemap = [];
# Generate query
$linkBatchFactory = $services->getLinkBatchFactory();
@@ -208,17 +208,17 @@ class LinkHolderArray {
# Check if it's a static known link, e.g. interwiki
if ( $title->isAlwaysKnown() ) {
- $colours[$pdbk] = '';
+ $classes[$pdbk] = '';
} elseif ( $ns == NS_SPECIAL ) {
- $colours[$pdbk] = 'new';
+ $classes[$pdbk] = 'new';
} else {
$id = $linkCache->getGoodLinkID( $pdbk );
if ( $id != 0 ) {
- $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
+ $classes[$pdbk] = $linkRenderer->getLinkClasses( $title );
$output->addLink( $title, $id );
- $linkcolour_ids[$id] = $pdbk;
+ $pagemap[$id] = $pdbk;
} elseif ( $linkCache->isBadLink( $pdbk ) ) {
- $colours[$pdbk] = 'new';
+ $classes[$pdbk] = 'new';
} else {
# Not in the link cache, add it to the query
$lb->addObj( $title );
@@ -246,20 +246,20 @@ class LinkHolderArray {
$pdbk = $title->getPrefixedDBkey();
$linkCache->addGoodLinkObjFromRow( $title, $s );
$output->addLink( $title, $s->page_id );
- $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
+ $classes[$pdbk] = $linkRenderer->getLinkClasses( $title );
// add id to the extension todolist
- $linkcolour_ids[$s->page_id] = $pdbk;
+ $pagemap[$s->page_id] = $pdbk;
}
unset( $res );
}
- if ( $linkcolour_ids !== [] ) {
+ if ( $pagemap !== [] ) {
// pass an array of page_ids to an extension
- $this->hookRunner->onGetLinkColours( $linkcolour_ids, $colours, $this->parent->getTitle() );
+ $this->hookRunner->onGetLinkColours( $pagemap, $classes, $this->parent->getTitle() );
}
# Do a second query for different language variants of links and categories
if ( $this->languageConverter->hasVariants() ) {
- $this->doVariants( $colours );
+ $this->doVariants( $classes );
}
# Construct search and replace arrays
@@ -280,10 +280,10 @@ class LinkHolderArray {
} else {
$displayText = new HtmlArmor( $displayTextHtml );
}
- if ( !isset( $colours[$pdbk] ) ) {
- $colours[$pdbk] = 'new';
+ if ( !isset( $classes[$pdbk] ) ) {
+ $classes[$pdbk] = 'new';
}
- if ( $colours[$pdbk] == 'new' ) {
+ if ( $classes[$pdbk] == 'new' ) {
$linkCache->addBadLinkObj( $title );
$output->addLink( $title, 0 );
$link = $linkRenderer->makeBrokenLink(
@@ -291,7 +291,7 @@ class LinkHolderArray {
);
} else {
$link = $linkRenderer->makePreloadedLink(
- $title, $displayText, $colours[$pdbk], [], $query
+ $title, $displayText, $classes[$pdbk], [], $query
);
}
@@ -341,10 +341,10 @@ class LinkHolderArray {
}
/**
- * Modify $this->internals and $colours according to language variant linking rules
- * @param array &$colours
+ * Modify $this->internals and $classes according to language variant linking rules
+ * @param array &$classes
*/
- protected function doVariants( &$colours ) {
+ protected function doVariants( &$classes ) {
$linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
$linkBatch = $linkBatchFactory->newLinkBatch();
$variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
@@ -362,7 +362,7 @@ class LinkHolderArray {
}
foreach ( $entries as $index => [ 'title' => $title, 'pdbk' => $pdbk ] ) {
// we only deal with new links (in its first query)
- if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
+ if ( !isset( $classes[$pdbk] ) || $classes[$pdbk] === 'new' ) {
$titlesAttrs[] = [ $index, $title ];
// separate titles with \0 because it would never appears
// in a valid title
@@ -439,7 +439,7 @@ class LinkHolderArray {
__METHOD__
);
- $linkcolour_ids = [];
+ $pagemap = [];
$linkRenderer = $this->parent->getLinkRenderer();
// for each found variants, figure out link holders and replace
@@ -461,14 +461,14 @@ class LinkHolderArray {
$entry =& $this->internals[$ns][$index];
$pdbk = $entry['pdbk'];
- if ( !isset( $colours[$pdbk] ) || $colours[$pdbk] === 'new' ) {
+ if ( !isset( $classes[$pdbk] ) || $classes[$pdbk] === 'new' ) {
// found link in some of the variants, replace the link holder data
$entry['title'] = $variantTitle;
$entry['pdbk'] = $varPdbk;
// set pdbk and colour
- $colours[$varPdbk] = $linkRenderer->getLinkClasses( $variantTitle );
- $linkcolour_ids[$s->page_id] = $pdbk;
+ $classes[$varPdbk] = $linkRenderer->getLinkClasses( $variantTitle );
+ $pagemap[$s->page_id] = $pdbk;
}
}
@@ -480,7 +480,7 @@ class LinkHolderArray {
}
}
}
- $this->hookRunner->onGetLinkColours( $linkcolour_ids, $colours, $this->parent->getTitle() );
+ $this->hookRunner->onGetLinkColours( $pagemap, $classes, $this->parent->getTitle() );
// rebuild the categories in original order (if there are replacements)
if ( $varCategories !== [] ) {