Merge "Parser: Hard deprecate getConverterLanguage" into REL1_34
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 9ec5834..7f3bb23 100644 (file)
@@ -162,7 +162,7 @@ class Parser {
         */
        public $mFirstCall = true;
 
-       # Initialised by initialiseVariables()
+       # Initialised by initializeVariables()
 
        /**
         * @var MagicWordArray
@@ -228,7 +228,11 @@ class Parser {
        public $mOptions;
 
        /**
-        * @var Title
+        * Since 1.34, leaving `mTitle` uninitialized or setting `mTitle` to
+        * `null` is deprecated.
+        *
+        * @internal
+        * @var Title|null
         */
        public $mTitle;        # Title context, used for self-link rendering and similar things
        public $mOutputType;   # Output type, one of the OT_xxx constants
@@ -465,7 +469,7 @@ class Parser {
 
                CoreParserFunctions::register( $this );
                CoreTagHooks::register( $this );
-               $this->initialiseVariables();
+               $this->initializeVariables();
 
                // Avoid PHP 7.1 warning from passing $this by reference
                $parser = $this;
@@ -906,9 +910,9 @@ class Parser {
        /**
         * Set the context title
         *
-        * @param Title $t
+        * @param Title|null $t
         */
-       public function setTitle( $t ) {
+       public function setTitle( Title $t = null ) {
                if ( !$t ) {
                        $t = Title::makeTitle( NS_SPECIAL, 'Badtitle/Parser' );
                }
@@ -924,9 +928,14 @@ class Parser {
        /**
         * Accessor for the Title object
         *
+        * Since 1.34, leaving `mTitle` uninitialized as `null` is deprecated.
+        *
         * @return Title|null
         */
-       public function getTitle() {
+       public function getTitle() : ?Title {
+               if ( $this->mTitle === null ) {
+                       wfDeprecated( 'Parser title should never be null', '1.34' );
+               }
                return $this->mTitle;
        }
 
@@ -934,9 +943,9 @@ class Parser {
         * Accessor/mutator for the Title object
         *
         * @param Title|null $x Title object or null to just get the current one
-        * @return Title
+        * @return Title|null
         */
-       public function Title( $x = null ) {
+       public function Title( Title $x = null ) : ?Title {
                return wfSetVar( $this->mTitle, $x );
        }
 
@@ -1042,9 +1051,10 @@ class Parser {
        /**
         * Get the language object for language conversion
         * @deprecated since 1.32, just use getTargetLanguage()
-        * @return Language|null
+        * @return Language
         */
        public function getConverterLanguage() {
+               wfDeprecated( __METHOD__, '1.32' );
                return $this->getTargetLanguage();
        }
 
@@ -1224,13 +1234,25 @@ class Parser {
        }
 
        /**
-        * parse the wiki syntax used to render tables
+        * Parse the wiki syntax used to render tables.
         *
         * @private
         * @param string $text
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function doTableStuff( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleTables( $text );
+       }
+
+       /**
+        * Parse the wiki syntax used to render tables.
+        *
+        * @param string $text
+        * @return string
+        */
+       private function handleTables( $text ) {
                $lines = StringUtils::explode( "\n", $text );
                $out = '';
                $td_history = []; # Is currently a td tag open?
@@ -1482,23 +1504,23 @@ class Parser {
                # properly; putting them before other transformations should keep
                # exciting things like link expansions from showing up in surprising
                # places.
-               $text = $this->doTableStuff( $text );
+               $text = $this->handleTables( $text );
 
                $text = preg_replace( '/(^|\n)-----*/', '\\1<hr />', $text );
 
-               $text = $this->doDoubleUnderscore( $text );
+               $text = $this->handleDoubleUnderscore( $text );
 
-               $text = $this->doHeadings( $text );
-               $text = $this->replaceInternalLinks( $text );
-               $text = $this->doAllQuotes( $text );
-               $text = $this->replaceExternalLinks( $text );
+               $text = $this->handleHeadings( $text );
+               $text = $this->handleInternalLinks( $text );
+               $text = $this->handleAllQuotes( $text );
+               $text = $this->handleExternalLinks( $text );
 
-               # replaceInternalLinks may sometimes leave behind
-               # absolute URLs, which have to be masked to hide them from replaceExternalLinks
+               # handleInternalLinks may sometimes leave behind
+               # absolute URLs, which have to be masked to hide them from handleExternalLinks
                $text = str_replace( self::MARKER_PREFIX . 'NOPARSE', '', $text );
 
-               $text = $this->doMagicLinks( $text );
-               $text = $this->formatHeadings( $text, $origText, $isMain );
+               $text = $this->handleMagicLinks( $text );
+               $text = $this->finalizeHeadings( $text, $origText, $isMain );
 
                return $text;
        }
@@ -1527,7 +1549,7 @@ class Parser {
 
                $text = $this->doBlockLevels( $text, $linestart );
 
-               $this->replaceLinkHolders( $text );
+               $this->replaceLinkHoldersPrivate( $text );
 
                /**
                 * The input doesn't get language converted if
@@ -1604,12 +1626,26 @@ class Parser {
         *
         * DML
         * @private
+        * @param string $text
+        * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
+        */
+       public function doMagicLinks( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleMagicLinks( $text );
+       }
+
+       /**
+        * Replace special strings like "ISBN xxx" and "RFC xxx" with
+        * magic external links.
+        *
+        * DML
         *
         * @param string $text
         *
         * @return string
         */
-       public function doMagicLinks( $text ) {
+       private function handleMagicLinks( $text ) {
                $prots = wfUrlProtocolsWithoutProtRel();
                $urlChar = self::EXT_LINK_URL_CLASS;
                $addr = self::EXT_LINK_ADDR;
@@ -1779,15 +1815,25 @@ class Parser {
        }
 
        /**
-        * Parse headers and return html
+        * Parse headers and return html.
         *
         * @private
-        *
         * @param string $text
-        *
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function doHeadings( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleHeadings( $text );
+       }
+
+       /**
+        * Parse headers and return html
+        *
+        * @param string $text
+        * @return string
+        */
+       private function handleHeadings( $text ) {
                for ( $i = 6; $i >= 1; --$i ) {
                        $h = str_repeat( '=', $i );
                        // Trim non-newline whitespace from headings
@@ -1804,8 +1850,21 @@ class Parser {
         * @param string $text
         *
         * @return string The altered text
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function doAllQuotes( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleAllQuotes( $text );
+       }
+
+       /**
+        * Replace single quotes with HTML markup
+        *
+        * @param string $text
+        *
+        * @return string The altered text
+        */
+       private function handleAllQuotes( $text ) {
                $outtext = '';
                $lines = StringUtils::explode( "\n", $text );
                foreach ( $lines as $line ) {
@@ -1821,6 +1880,7 @@ class Parser {
         * @param string $text
         *
         * @return string
+        * @internal
         */
        public function doQuotes( $text ) {
                $arr = preg_split( "/(''+)/", $text, -1, PREG_SPLIT_DELIM_CAPTURE );
@@ -2009,6 +2069,21 @@ class Parser {
         * @return string
         */
        public function replaceExternalLinks( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleExternalLinks( $text );
+       }
+
+       /**
+        * Replace external links (REL)
+        *
+        * Note: this is all very hackish and the order of execution matters a lot.
+        * Make sure to run tests/parser/parserTests.php if you change this code.
+        *
+        * @param string $text
+        * @throws MWException
+        * @return string
+        */
+       private function handleExternalLinks( $text ) {
                $bits = preg_split( $this->mExtLinkBracketedRegex, $text, -1, PREG_SPLIT_DELIM_CAPTURE );
                // @phan-suppress-next-line PhanTypeComparisonFromArray See phan issue #3161
                if ( $bits === false ) {
@@ -2082,6 +2157,7 @@ class Parser {
         * Get the rel attribute for a particular external link.
         *
         * @since 1.21
+        * @internal
         * @param string|bool $url Optional URL, to extract the domain from for rel =>
         *   nofollow if appropriate
         * @param LinkTarget|null $title Optional LinkTarget, for wgNoFollowNsExceptions lookups
@@ -2104,6 +2180,7 @@ class Parser {
         * (depending on configuration, namespace, and the URL's domain) and/or a
         * target attribute (depending on configuration).
         *
+        * @internal
         * @param string $url URL to extract the domain from for rel =>
         *   nofollow if appropriate
         * @return array Associative array of HTML attributes
@@ -2135,6 +2212,7 @@ class Parser {
         * This generally follows the syntax defined in RFC 3986, with special
         * consideration for HTTP query strings.
         *
+        * @internal
         * @param string $url
         * @return string
         */
@@ -2272,26 +2350,51 @@ class Parser {
        /**
         * Process [[ ]] wikilinks
         *
-        * @param string $s
+        * @param string $text
         *
         * @return string Processed text
         *
         * @private
+        * @deprecated since 1.34; should not be used outside parser class.
         */
-       public function replaceInternalLinks( $s ) {
-               $this->mLinkHolders->merge( $this->replaceInternalLinks2( $s ) );
-               return $s;
+       public function replaceInternalLinks( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleInternalLinks( $text );
+       }
+
+       /**
+        * Process [[ ]] wikilinks
+        *
+        * @param string $text
+        *
+        * @return string Processed text
+        */
+       private function handleInternalLinks( $text ) {
+               $this->mLinkHolders->merge( $this->handleInternalLinks2( $text ) );
+               return $text;
        }
 
        /**
         * Process [[ ]] wikilinks (RIL)
-        * @param string &$s
+        * @param string &$text
         * @throws MWException
         * @return LinkHolderArray
         *
         * @private
+        * @deprecated since 1.34; should not be used outside parser class.
         */
-       public function replaceInternalLinks2( &$s ) {
+       public function replaceInternalLinks2( &$text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleInternalLinks2( $text );
+       }
+
+       /**
+        * Process [[ ]] wikilinks (RIL)
+        * @param string &$s
+        * @throws MWException
+        * @return LinkHolderArray
+        */
+       private function handleInternalLinks2( &$s ) {
                static $tc = false, $e1, $e1_img;
                # the % is needed to support urlencoded titles as well
                if ( !$tc ) {
@@ -2334,7 +2437,10 @@ class Parser {
                        $prefix = '';
                }
 
-               $useSubpages = $this->areSubpagesAllowed();
+               # Some namespaces don't allow subpages
+               $useSubpages = $this->nsInfo->hasSubpages(
+                       $this->mTitle->getNamespace()
+               );
 
                # Loop for each link
                for ( ; $line !== false && $line !== null; $a->next(), $line = $a->current() ) {
@@ -2373,7 +2479,7 @@ class Parser {
                                        && substr( $m[3], 0, 1 ) === ']'
                                        && strpos( $text, '[' ) !== false
                                ) {
-                                       $text .= ']'; # so that replaceExternalLinks($text) works later
+                                       $text .= ']'; # so that handleExternalLinks($text) works later
                                        $m[3] = substr( $m[3], 1 );
                                }
                                # fix up urlencoded title texts
@@ -2407,7 +2513,9 @@ class Parser {
 
                        # Make subpage if necessary
                        if ( $useSubpages ) {
-                               $link = $this->maybeDoSubpageLink( $origLink, $text );
+                               $link = Linker::normalizeSubpageLink(
+                                       $this->mTitle, $origLink, $text
+                               );
                        } else {
                                $link = $origLink;
                        }
@@ -2459,7 +2567,7 @@ class Parser {
                                        if ( !$found ) {
                                                # we couldn't find the end of this imageLink, so output it raw
                                                # but don't ignore what might be perfectly normal links in the text we've examined
-                                               $holders->merge( $this->replaceInternalLinks2( $text ) );
+                                               $holders->merge( $this->handleInternalLinks2( $text ) );
                                                $s .= "{$prefix}[[$link|$text";
                                                # note: no $trail, because without an end, there *is* no trail
                                                continue;
@@ -2520,11 +2628,11 @@ class Parser {
                                                        # recursively parse links inside the image caption
                                                        # actually, this will parse them in any other parameters, too,
                                                        # but it might be hard to fix that, and it doesn't matter ATM
-                                                       $text = $this->replaceExternalLinks( $text );
-                                                       $holders->merge( $this->replaceInternalLinks2( $text ) );
+                                                       $text = $this->handleExternalLinks( $text );
+                                                       $holders->merge( $this->handleInternalLinks2( $text ) );
                                                }
-                                               # cloak any absolute URLs inside the image markup, so replaceExternalLinks() won't touch them
-                                               $s .= $prefix . $this->armorLinks(
+                                               # cloak any absolute URLs inside the image markup, so handleExternalLinks() won't touch them
+                                               $s .= $prefix . $this->armorLinksPrivate(
                                                        $this->makeImage( $nt, $text, $holders ) ) . $trail;
                                                continue;
                                        }
@@ -2566,8 +2674,8 @@ class Parser {
                                        [ $this, $nt, &$options, &$descQuery ] );
                                # Fetch and register the file (file title may be different via hooks)
                                list( $file, $nt ) = $this->fetchFileAndTitle( $nt, $options );
-                               # Cloak with NOPARSE to avoid replacement in replaceExternalLinks
-                               $s .= $prefix . $this->armorLinks(
+                               # Cloak with NOPARSE to avoid replacement in handleExternalLinks
+                               $s .= $prefix . $this->armorLinksPrivate(
                                        Linker::makeMediaLinkFile( $nt, $file, $text ) ) . $trail;
                                continue;
                        }
@@ -2578,7 +2686,7 @@ class Parser {
                        # batch file existence checks for NS_FILE and NS_MEDIA
                        if ( $iw == '' && $nt->isAlwaysKnown() ) {
                                $this->mOutput->addLink( $nt );
-                               $s .= $this->makeKnownLinkHolder( $nt, $text, $trail, $prefix );
+                               $s .= $this->makeKnownLinkHolderPrivate( $nt, $text, $trail, $prefix );
                        } else {
                                # Links will be added to the output link list after checking
                                $s .= $holders->makeHolder( $nt, $text, [], $trail, $prefix );
@@ -2599,8 +2707,27 @@ class Parser {
         * @param string $trail
         * @param string $prefix
         * @return string HTML-wikitext mix oh yuck
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        protected function makeKnownLinkHolder( $nt, $text = '', $trail = '', $prefix = '' ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->makeKnownLinkHolderPrivate( $nt, $text, $trail, $prefix );
+       }
+
+       /**
+        * Render a forced-blue link inline; protect against double expansion of
+        * URLs if we're in a mode that prepends full URL prefixes to internal links.
+        * Since this little disaster has to split off the trail text to avoid
+        * breaking URLs in the following text without breaking trails on the
+        * wiki links, it's been made into a horrible function.
+        *
+        * @param Title $nt
+        * @param string $text
+        * @param string $trail
+        * @param string $prefix
+        * @return string HTML-wikitext mix oh yuck
+        */
+       private function makeKnownLinkHolderPrivate( $nt, $text = '', $trail = '', $prefix = '' ) {
                list( $inside, $trail ) = Linker::splitTrail( $trail );
 
                if ( $text == '' ) {
@@ -2611,7 +2738,7 @@ class Parser {
                        $nt, new HtmlArmor( "$prefix$text$inside" )
                );
 
-               return $this->armorLinks( $link ) . $trail;
+               return $this->armorLinksPrivate( $link ) . $trail;
        }
 
        /**
@@ -2623,8 +2750,24 @@ class Parser {
         *
         * @param string $text More-or-less HTML
         * @return string Less-or-more HTML with NOPARSE bits
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function armorLinks( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->armorLinksPrivate( $text );
+       }
+
+       /**
+        * Insert a NOPARSE hacky thing into any inline links in a chunk that's
+        * going to go through further parsing steps before inline URL expansion.
+        *
+        * Not needed quite as much as it used to be since free links are a bit
+        * more sensible these days. But bracketed links are still an issue.
+        *
+        * @param string $text More-or-less HTML
+        * @return string Less-or-more HTML with NOPARSE bits
+        */
+       private function armorLinksPrivate( $text ) {
                return preg_replace( '/\b((?i)' . $this->mUrlProtocols . ')/',
                        self::MARKER_PREFIX . "NOPARSE$1", $text );
        }
@@ -2632,9 +2775,11 @@ class Parser {
        /**
         * Return true if subpage links should be expanded on this page.
         * @return bool
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function areSubpagesAllowed() {
                # Some namespaces don't allow subpages
+               wfDeprecated( __METHOD__, '1.34' );
                return $this->nsInfo->hasSubpages( $this->mTitle->getNamespace() );
        }
 
@@ -2645,8 +2790,10 @@ class Parser {
         * @param string &$text The link text, modified as necessary
         * @return string The full name of the link
         * @private
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function maybeDoSubpageLink( $target, &$text ) {
+               wfDeprecated( __METHOD__, '1.34' );
                return Linker::normalizeSubpageLink( $this->mTitle, $target, $text );
        }
 
@@ -2672,8 +2819,25 @@ class Parser {
         *
         * @throws MWException
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function getVariableValue( $index, $frame = false ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->expandMagicVariable( $index, $frame );
+       }
+
+       /**
+        * Return value of a magic variable (like PAGENAME)
+        *
+        * @param string $index Magic variable identifier as mapped in MagicWordFactory::$mVariableIDs
+        * @param bool|PPFrame $frame
+        *
+        * @throws MWException
+        * @return string
+        */
+       private function expandMagicVariable( $index, $frame = false ) {
+               // XXX This function should be moved out of Parser class for
+               // reuse by Parsoid/etc.
                if ( is_null( $this->mTitle ) ) {
                        // If no title set, bad things are going to happen
                        // later. Title should always be set since this
@@ -3056,8 +3220,18 @@ class Parser {
         * initialise the magic variables (like CURRENTMONTHNAME) and substitution modifiers
         *
         * @private
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function initialiseVariables() {
+               wfDeprecated( __METHOD__, '1.34' );
+               $this->initializeVariables();
+       }
+
+       /**
+        * Initialize the magic variables (like CURRENTMONTHNAME) and
+        * substitution modifiers.
+        */
+       private function initializeVariables() {
                $variableIDs = $this->magicWordFactory->getVariableIDs();
                $substIDs = $this->magicWordFactory->getSubstIDs();
 
@@ -3098,8 +3272,10 @@ class Parser {
         * @param string $s
         *
         * @return array
+        * @deprecated since 1.34; appears to be unused.
         */
        public static function splitWhitespace( $s ) {
+               wfDeprecated( __METHOD__, '1.34' );
                $ltrimmed = ltrim( $s );
                $w1 = substr( $s, 0, strlen( $s ) - strlen( $ltrimmed ) );
                $trimmed = rtrim( $ltrimmed );
@@ -3162,8 +3338,10 @@ class Parser {
         * @param array $args
         *
         * @return array
+        * @deprecated since 1.34; appears to be unused in core.
         */
        public static function createAssocArgs( $args ) {
+               wfDeprecated( __METHOD__, '1.34' );
                $assocArgs = [];
                $index = 1;
                foreach ( $args as $arg ) {
@@ -3232,6 +3410,7 @@ class Parser {
         * @param PPFrame $frame The current frame, contains template arguments
         * @throws Exception
         * @return string|array The text of the template
+        * @internal
         */
        public function braceSubstitution( $piece, $frame ) {
                // Flags
@@ -3298,7 +3477,7 @@ class Parser {
                if ( !$found && $args->getLength() == 0 ) {
                        $id = $this->mVariables->matchStartToEnd( $part1 );
                        if ( $id !== false ) {
-                               $text = $this->getVariableValue( $id, $frame );
+                               $text = $this->expandMagicVariable( $id, $frame );
                                if ( $this->magicWordFactory->getCacheTTL( $id ) > -1 ) {
                                        $this->mOutput->updateCacheExpiry(
                                                $this->magicWordFactory->getCacheTTL( $id ) );
@@ -3374,7 +3553,9 @@ class Parser {
                        $ns = NS_TEMPLATE;
                        # Split the title into page and subpage
                        $subpage = '';
-                       $relative = $this->maybeDoSubpageLink( $part1, $subpage );
+                       $relative = Linker::normalizeSubpageLink(
+                               $this->mTitle, $part1, $subpage
+                       );
                        if ( $part1 !== $relative ) {
                                $part1 = $relative;
                                $ns = $this->mTitle->getNamespace();
@@ -4008,7 +4189,7 @@ class Parser {
 
        /**
         * Triple brace replacement -- used for template arguments
-        * @private
+        * @internal
         *
         * @param array $piece
         * @param PPFrame $frame
@@ -4066,6 +4247,7 @@ class Parser {
         *
         * @throws MWException
         * @return string
+        * @internal
         */
        public function extensionSubstitution( $params, $frame ) {
                static $errorStr = '<span class="error">';
@@ -4193,10 +4375,22 @@ class Parser {
         * Fills $this->mDoubleUnderscores, returns the modified text
         *
         * @param string $text
-        *
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function doDoubleUnderscore( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->handleDoubleUnderscore( $text );
+       }
+
+       /**
+        * Strip double-underscore items like __NOGALLERY__ and __NOTOC__
+        * Fills $this->mDoubleUnderscores, returns the modified text
+        *
+        * @param string $text
+        * @return string
+        */
+       private function handleDoubleUnderscore( $text ) {
                # The position of __TOC__ needs to be recorded
                $mw = $this->magicWordFactory->get( 'toc' );
                if ( $mw->match( $text ) ) {
@@ -4268,8 +4462,29 @@ class Parser {
         * @param bool $isMain
         * @return mixed|string
         * @private
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function formatHeadings( $text, $origText, $isMain = true ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->finalizeHeadings( $text, $origText, $isMain );
+       }
+
+       /**
+        * This function accomplishes several tasks:
+        * 1) Auto-number headings if that option is enabled
+        * 2) Add an [edit] link to sections for users who have enabled the option and can edit the page
+        * 3) Add a Table of contents on the top for users who have enabled the option
+        * 4) Auto-anchor headings
+        *
+        * It loops through all headlines, collects the necessary data, then splits up the
+        * string and re-inserts the newly formatted headlines.
+        *
+        * @param string $text
+        * @param string $origText Original, untouched wikitext
+        * @param bool $isMain
+        * @return mixed|string
+        */
+       private function finalizeHeadings( $text, $origText, $isMain = true ) {
                # Inhibit editsection links if requested in the page
                if ( isset( $this->mDoubleUnderscores['noeditsection'] ) ) {
                        $maybeShowEditLink = false;
@@ -4279,7 +4494,7 @@ class Parser {
 
                # Get all headlines for numbering them and adding funky stuff like [edit]
                # links - this is for later, but we need the number of headlines right now
-               # NOTE: white space in headings have been trimmed in doHeadings. They shouldn't
+               # NOTE: white space in headings have been trimmed in handleHeadings. They shouldn't
                # be trimmed here since whitespace in HTML headings is significant.
                $matches = [];
                $numMatches = preg_match_all(
@@ -4423,7 +4638,7 @@ class Parser {
                        # turns into
                        #     link text with suffix
                        # Do this before unstrip since link text can contain strip markers
-                       $safeHeadline = $this->replaceLinkHoldersText( $headline );
+                       $safeHeadline = $this->replaceLinkHoldersTextPrivate( $headline );
 
                        # Avoid insertion of weird stuff like <math> by expanding the relevant sections
                        $safeHeadline = $this->mStripState->unstripBoth( $safeHeadline );
@@ -5137,8 +5352,20 @@ class Parser {
         *
         * @param string &$text
         * @param int $options
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function replaceLinkHolders( &$text, $options = 0 ) {
+               $this->replaceLinkHoldersPrivate( $text, $options );
+       }
+
+       /**
+        * Replace "<!--LINK-->" link placeholders with actual links, in the buffer
+        * Placeholders created in Linker::link()
+        *
+        * @param string &$text
+        * @param int $options
+        */
+       private function replaceLinkHoldersPrivate( &$text, $options = 0 ) {
                $this->mLinkHolders->replace( $text );
        }
 
@@ -5148,8 +5375,21 @@ class Parser {
         *
         * @param string $text
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function replaceLinkHoldersText( $text ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->replaceLinkHoldersTextPrivate( $text );
+       }
+
+       /**
+        * Replace "<!--LINK-->" link placeholders with plain text of links
+        * (not HTML-formatted).
+        *
+        * @param string $text
+        * @return string
+        */
+       private function replaceLinkHoldersTextPrivate( $text ) {
                return $this->mLinkHolders->replaceText( $text );
        }
 
@@ -5282,16 +5522,16 @@ class Parser {
 
                                                switch ( $paramName ) {
                                                        case 'gallery-internal-alt':
-                                                               $alt = $this->stripAltText( $match, false );
+                                                               $alt = $this->stripAltTextPrivate( $match, false );
                                                                break;
                                                        case 'gallery-internal-link':
-                                                               $linkValue = $this->stripAltText( $match, false );
+                                                               $linkValue = $this->stripAltTextPrivate( $match, false );
                                                                if ( preg_match( '/^-{R|(.*)}-$/', $linkValue ) ) {
                                                                        // Result of LanguageConverter::markNoConversion
                                                                        // invoked on an external link.
                                                                        $linkValue = substr( $linkValue, 4, -2 );
                                                                }
-                                                               list( $type, $target ) = $this->parseLinkParameter( $linkValue );
+                                                               list( $type, $target ) = $this->parseLinkParameterPrivate( $linkValue );
                                                                if ( $type === 'link-url' ) {
                                                                        $link = $target;
                                                                        $this->mOutput->addExternalLink( $target );
@@ -5329,8 +5569,18 @@ class Parser {
        /**
         * @param MediaHandler $handler
         * @return array
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function getImageParams( $handler ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->getImageParamsPrivate( $handler );
+       }
+
+       /**
+        * @param MediaHandler $handler
+        * @return array
+        */
+       private function getImageParamsPrivate( $handler ) {
                if ( $handler ) {
                        $handlerClass = get_class( $handler );
                } else {
@@ -5427,7 +5677,7 @@ class Parser {
                # Get parameter map
                $handler = $file ? $file->getHandler() : false;
 
-               list( $paramMap, $mwArray ) = $this->getImageParams( $handler );
+               list( $paramMap, $mwArray ) = $this->getImageParamsPrivate( $handler );
 
                if ( !$file ) {
                        $this->addTrackingCategory( 'broken-file-category' );
@@ -5477,12 +5727,12 @@ class Parser {
                                                                # manualthumb? downstream behavior seems odd with
                                                                # missing manual thumbs.
                                                                $validated = true;
-                                                               $value = $this->stripAltText( $value, $holders );
+                                                               $value = $this->stripAltTextPrivate( $value, $holders );
                                                                break;
                                                        case 'link':
                                                                list( $paramName, $value ) =
-                                                                       $this->parseLinkParameter(
-                                                                               $this->stripAltText( $value, $holders )
+                                                                       $this->parseLinkParameterPrivate(
+                                                                               $this->stripAltTextPrivate( $value, $holders )
                                                                        );
                                                                if ( $paramName ) {
                                                                        $validated = true;
@@ -5559,7 +5809,7 @@ class Parser {
                        if ( !isset( $params['frame']['alt'] ) ) {
                                # No alt text, use the "caption" for the alt text
                                if ( $caption !== '' ) {
-                                       $params['frame']['alt'] = $this->stripAltText( $caption, $holders );
+                                       $params['frame']['alt'] = $this->stripAltTextPrivate( $caption, $holders );
                                } else {
                                        # No caption, fall back to using the filename for the
                                        # alt text
@@ -5567,7 +5817,7 @@ class Parser {
                                }
                        }
                        # Use the "caption" for the tooltip text
-                       $params['frame']['title'] = $this->stripAltText( $caption, $holders );
+                       $params['frame']['title'] = $this->stripAltTextPrivate( $caption, $holders );
                }
                $params['handler']['targetlang'] = $this->getTargetLanguage()->getCode();
 
@@ -5603,8 +5853,32 @@ class Parser {
         *     - When `type` is `null` or `'no-link'`: `false`
         *     - When `type` is `'link-url'`: URL string corresponding to given value
         *     - When `type` is `'link-title'`: Title object corresponding to given value
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function parseLinkParameter( $value ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->parseLinkParameterPrivate( $value );
+       }
+
+       /**
+        * Parse the value of 'link' parameter in image syntax (`[[File:Foo.jpg|link=<value>]]`).
+        *
+        * Adds an entry to appropriate link tables.
+        *
+        * @since 1.32
+        * @param string $value
+        * @return array of `[ type, target ]`, where:
+        *   - `type` is one of:
+        *     - `null`: Given value is not a valid link target, use default
+        *     - `'no-link'`: Given value is empty, do not generate a link
+        *     - `'link-url'`: Given value is a valid external link
+        *     - `'link-title'`: Given value is a valid internal link
+        *   - `target` is:
+        *     - When `type` is `null` or `'no-link'`: `false`
+        *     - When `type` is `'link-url'`: URL string corresponding to given value
+        *     - When `type` is `'link-title'`: Title object corresponding to given value
+        */
+       private function parseLinkParameterPrivate( $value ) {
                $chars = self::EXT_LINK_URL_CLASS;
                $addr = self::EXT_LINK_ADDR;
                $prots = $this->mUrlProtocols;
@@ -5633,15 +5907,26 @@ class Parser {
         * @param string $caption
         * @param LinkHolderArray|bool $holders
         * @return mixed|string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        protected function stripAltText( $caption, $holders ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->stripAltTextPrivate( $caption, $holders );
+       }
+
+       /**
+        * @param string $caption
+        * @param LinkHolderArray|bool $holders
+        * @return mixed|string
+        */
+       private function stripAltTextPrivate( $caption, $holders ) {
                # Strip bad stuff out of the title (tooltip).  We can't just use
                # replaceLinkHoldersText() here, because if this function is called
-               # from replaceInternalLinks2(), mLinkHolders won't be up-to-date.
+               # from handleInternalLinks2(), mLinkHolders won't be up-to-date.
                if ( $holders ) {
                        $tooltip = $holders->replaceText( $caption );
                } else {
-                       $tooltip = $this->replaceLinkHoldersText( $caption );
+                       $tooltip = $this->replaceLinkHoldersTextPrivate( $caption );
                }
 
                # make sure there are no placeholders in thumbnail attributes
@@ -6241,9 +6526,27 @@ class Parser {
         * @param int $outputType
         *
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function testSrvus( $text, Title $title, ParserOptions $options,
                $outputType = self::OT_HTML
+       ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->fuzzTestSrvus( $text, $title, $options, $outputType );
+       }
+
+       /**
+        * Strip/replaceVariables/unstrip for preprocessor regression testing
+        *
+        * @param string $text
+        * @param Title $title
+        * @param ParserOptions $options
+        * @param int $outputType
+        *
+        * @return string
+        */
+       private function fuzzTestSrvus( $text, Title $title, ParserOptions $options,
+               $outputType = self::OT_HTML
        ) {
                $magicScopeVariable = $this->lock();
                $this->startParse( $title, $options, $outputType, true );
@@ -6259,8 +6562,20 @@ class Parser {
         * @param Title $title
         * @param ParserOptions $options
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function testPst( $text, Title $title, ParserOptions $options ) {
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->fuzzTestPst( $text, $title, $options );
+       }
+
+       /**
+        * @param string $text
+        * @param Title $title
+        * @param ParserOptions $options
+        * @return string
+        */
+       private function fuzzTestPst( $text, Title $title, ParserOptions $options ) {
                return $this->preSaveTransform( $text, $title, $options->getUser(), $options );
        }
 
@@ -6269,9 +6584,21 @@ class Parser {
         * @param Title $title
         * @param ParserOptions $options
         * @return string
+        * @deprecated since 1.34; should not be used outside parser class.
         */
        public function testPreprocess( $text, Title $title, ParserOptions $options ) {
-               return $this->testSrvus( $text, $title, $options, self::OT_PREPROCESS );
+               wfDeprecated( __METHOD__, '1.34' );
+               return $this->fuzzTestPreprocess( $text, $title, $options );
+       }
+
+       /**
+        * @param string $text
+        * @param Title $title
+        * @param ParserOptions $options
+        * @return string
+        */
+       private function fuzzTestPreprocess( $text, Title $title, ParserOptions $options ) {
+               return $this->fuzzTestSrvus( $text, $title, $options, self::OT_PREPROCESS );
        }
 
        /**