Merge "Schema change for reading ct_tag_id instead of ct_tag"
[lhc/web/wiklou.git] / includes / parser / LinkHolderArray.php
index 939fe73..f4856be 100644 (file)
@@ -282,8 +282,6 @@ class LinkHolderArray {
                        return;
                }
 
-               global $wgContLang;
-
                $colours = [];
                $linkCache = MediaWikiServices::getInstance()->getLinkCache();
                $output = $this->parent->getOutput();
@@ -360,11 +358,11 @@ class LinkHolderArray {
                }
                if ( count( $linkcolour_ids ) ) {
                        // pass an array of page_ids to an extension
-                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
+                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
                }
 
                # Do a second query for different language variants of links and categories
-               if ( $wgContLang->hasVariants() ) {
+               if ( $this->parent->getContentLanguage()->hasVariants() ) {
                        $this->doVariants( $colours );
                }
 
@@ -406,12 +404,13 @@ class LinkHolderArray {
                                $replacePairs[$searchkey] = $link;
                        }
                }
-               $replacer = new HashtableReplacer( $replacePairs, 1 );
 
                # Do the thing
                $text = preg_replace_callback(
                        '/(<!--LINK\'" .*?-->)/',
-                       $replacer->cb(),
+                       function ( array $matches ) use ( $replacePairs ) {
+                               return $replacePairs[$matches[1]];
+                       },
                        $text
                );
        }
@@ -436,12 +435,14 @@ class LinkHolderArray {
                        );
                        $output->addInterwikiLink( $link['title'] );
                }
-               $replacer = new HashtableReplacer( $replacePairs, 1 );
 
                $text = preg_replace_callback(
                        '/<!--IWLINK\'" (.*?)-->/',
-                       $replacer->cb(),
-                       $text );
+                       function ( array $matches ) use ( $replacePairs ) {
+                               return $replacePairs[$matches[1]];
+                       },
+                       $text
+               );
        }
 
        /**
@@ -449,7 +450,6 @@ class LinkHolderArray {
         * @param array &$colours
         */
        protected function doVariants( &$colours ) {
-               global $wgContLang;
                $linkBatch = new LinkBatch();
                $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
                $output = $this->parent->getOutput();
@@ -477,7 +477,8 @@ class LinkHolderArray {
                }
 
                // Now do the conversion and explode string to text of titles
-               $titlesAllVariants = $wgContLang->autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
+               $titlesAllVariants = $this->parent->getContentLanguage()->
+                       autoConvertToAllVariants( rtrim( $titlesToBeConverted, "\0" ) );
                $allVariantsName = array_keys( $titlesAllVariants );
                foreach ( $titlesAllVariants as &$titlesVariant ) {
                        $titlesVariant = explode( "\0", $titlesVariant );
@@ -518,7 +519,7 @@ class LinkHolderArray {
                foreach ( $output->getCategoryLinks() as $category ) {
                        $categoryTitle = Title::makeTitleSafe( NS_CATEGORY, $category );
                        $linkBatch->addObj( $categoryTitle );
-                       $variants = $wgContLang->autoConvertToAllVariants( $category );
+                       $variants = $this->parent->getContentLanguage()->autoConvertToAllVariants( $category );
                        foreach ( $variants as $variant ) {
                                if ( $variant !== $category ) {
                                        $variantTitle = Title::makeTitleSafe( NS_CATEGORY, $variant );
@@ -586,7 +587,7 @@ class LinkHolderArray {
                                        }
                                }
                        }
-                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours ] );
+                       Hooks::run( 'GetLinkColours', [ $linkcolour_ids, &$colours, $this->parent->getTitle() ] );
 
                        // rebuild the categories in original order (if there are replacements)
                        if ( count( $varCategories ) > 0 ) {