Warn if stateful ParserOutput transforms are used
[lhc/web/wiklou.git] / includes / parser / LinkHolderArray.php
index 1c6f404..bc5182c 100644 (file)
@@ -264,18 +264,16 @@ class LinkHolderArray {
        /**
         * Replace <!--LINK--> link placeholders with actual links, in the buffer
         *
-        * @param string $text
+        * @param string &$text
         */
        public function replace( &$text ) {
-
                $this->replaceInternal( $text );
                $this->replaceInterwiki( $text );
-
        }
 
        /**
         * Replace internal links
-        * @param string $text
+        * @param string &$text
         */
        protected function replaceInternal( &$text ) {
                if ( !$this->internals ) {
@@ -288,9 +286,8 @@ class LinkHolderArray {
                $linkCache = LinkCache::singleton();
                $output = $this->parent->getOutput();
                $linkRenderer = $this->parent->getLinkRenderer();
-               $threshold = $linkRenderer->getStubThreshold();
 
-               $dbr = wfGetDB( DB_SLAVE );
+               $dbr = wfGetDB( DB_REPLICA );
 
                # Sort by namespace
                ksort( $this->internals );
@@ -321,7 +318,7 @@ class LinkHolderArray {
                                } else {
                                        $id = $linkCache->getGoodLinkID( $pdbk );
                                        if ( $id != 0 ) {
-                                               $colours[$pdbk] = Linker::getLinkColour( $title, $threshold );
+                                               $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
                                                $output->addLink( $title, $id );
                                                $linkcolour_ids[$id] = $pdbk;
                                        } elseif ( $linkCache->isBadLink( $pdbk ) ) {
@@ -353,7 +350,7 @@ class LinkHolderArray {
                                $pdbk = $title->getPrefixedDBkey();
                                $linkCache->addGoodLinkObjFromRow( $title, $s );
                                $output->addLink( $title, $s->page_id );
-                               $colours[$pdbk] = Linker::getLinkColour( $title, $threshold );
+                               $colours[$pdbk] = $linkRenderer->getLinkClasses( $title );
                                // add id to the extension todolist
                                $linkcolour_ids[$s->page_id] = $pdbk;
                        }
@@ -415,12 +412,11 @@ class LinkHolderArray {
                        $replacer->cb(),
                        $text
                );
-
        }
 
        /**
         * Replace interwiki links
-        * @param string $text
+        * @param string &$text
         */
        protected function replaceInterwiki( &$text ) {
                if ( empty( $this->interwikis ) ) {
@@ -448,7 +444,7 @@ class LinkHolderArray {
 
        /**
         * Modify $this->internals and $colours according to language variant linking rules
-        * @param array $colours
+        * @param array &$colours
         */
        protected function doVariants( &$colours ) {
                global $wgContLang;
@@ -456,7 +452,6 @@ class LinkHolderArray {
                $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders)
                $output = $this->parent->getOutput();
                $linkCache = LinkCache::singleton();
-               $threshold = $this->parent->getOptions()->getStubThreshold();
                $titlesToBeConverted = '';
                $titlesAttrs = [];
 
@@ -536,7 +531,7 @@ class LinkHolderArray {
 
                if ( !$linkBatch->isEmpty() ) {
                        // construct query
-                       $dbr = wfGetDB( DB_SLAVE );
+                       $dbr = wfGetDB( DB_REPLICA );
                        $fields = array_merge(
                                LinkCache::getSelectFields(),
                                [ 'page_namespace', 'page_title' ]
@@ -549,6 +544,7 @@ class LinkHolderArray {
                        );
 
                        $linkcolour_ids = [];
+                       $linkRenderer = $this->parent->getLinkRenderer();
 
                        // for each found variants, figure out link holders and replace
                        foreach ( $varRes as $s ) {
@@ -575,7 +571,7 @@ class LinkHolderArray {
                                                $entry['pdbk'] = $varPdbk;
 
                                                // set pdbk and colour
-                                               $colours[$varPdbk] = Linker::getLinkColour( $variantTitle, $threshold );
+                                               $colours[$varPdbk] = $linkRenderer->getLinkClasses( $variantTitle );
                                                $linkcolour_ids[$s->page_id] = $pdbk;
                                        }
                                }
@@ -615,10 +611,9 @@ class LinkHolderArray {
         * @return string
         */
        public function replaceText( $text ) {
-
                $text = preg_replace_callback(
                        '/<!--(LINK|IWLINK) (.*?)-->/',
-                       [ &$this, 'replaceTextCallback' ],
+                       [ $this, 'replaceTextCallback' ],
                        $text );
 
                return $text;