Merge "Fix link prefix/suffixes around Category and Language links (take 2)."
[lhc/web/wiklou.git] / includes / parser / Parser.php
index 5ef0032..d00b333 100644 (file)
@@ -736,17 +736,6 @@ class Parser {
                return $text;
        }
 
-       /**
-        * Get a random string
-        *
-        * @return string
-        * @deprecated since 1.26; use wfRandomString() instead.
-        */
-       public static function getRandomString() {
-               wfDeprecated( __METHOD__, '1.26' );
-               return wfRandomString( 16 );
-       }
-
        /**
         * Set the current user.
         * Should only be used when doing pre-save transform.
@@ -757,17 +746,6 @@ class Parser {
                $this->mUser = $user;
        }
 
-       /**
-        * Accessor for mUniqPrefix.
-        *
-        * @return string
-        * @deprecated since 1.26; use Parser::MARKER_PREFIX instead.
-        */
-       public function uniqPrefix() {
-               wfDeprecated( __METHOD__, '1.26' );
-               return self::MARKER_PREFIX;
-       }
-
        /**
         * Set the context title
         *
@@ -973,14 +951,9 @@ class Parser {
         * @param array $elements List of element names. Comments are always extracted.
         * @param string $text Source text string.
         * @param array &$matches Out parameter, Array: extracted tags
-        * @param string|null $uniq_prefix
         * @return string Stripped text
-        * @since 1.26 The uniq_prefix argument is deprecated.
         */
-       public static function extractTagsAndParams( $elements, $text, &$matches, $uniq_prefix = null ) {
-               if ( $uniq_prefix !== null ) {
-                       wfDeprecated( __METHOD__ . ' called with $prefix argument', '1.26' );
-               }
+       public static function extractTagsAndParams( $elements, $text, &$matches ) {
                static $n = 1;
                $stripped = '';
                $matches = [];
@@ -2327,7 +2300,9 @@ class Parser {
                                         * Strip the whitespace interwiki links produce, see T10897
                                         */
                                        $s = rtrim( $s . $prefix );
-                                       $s .= rtrim( $trail, "\n" );
+                                       // Special case: strip newlines when only thing between
+                                       // this link and next are newlines
+                                       $s .= trim( $trail, "\n" ) === '' ? '' : $trail;
                                        continue;
                                }
 
@@ -2356,7 +2331,9 @@ class Parser {
                                         * Strip the whitespace Category links produce, see T2087
                                         */
                                        $s = rtrim( $s . $prefix ); # T2087, T87753
-                                       $s .= rtrim( $trail, "\n" );
+                                       // Special case: strip newlines when only thing between
+                                       // this link and next are newlines
+                                       $s .= trim( $trail, "\n" ) === '' ? '' : $trail;
 
                                        if ( $wasblank ) {
                                                $sortkey = $this->getDefaultSort();
@@ -2613,7 +2590,7 @@ class Parser {
                                ) ) );
                                break;
                        case 'talkpagename':
-                               if ( $this->mTitle->canTalk() ) {
+                               if ( $this->mTitle->canHaveTalkPage() ) {
                                        $talkPage = $this->mTitle->getTalkPage();
                                        $value = wfEscapeWikiText( $talkPage->getPrefixedText() );
                                } else {
@@ -2621,7 +2598,7 @@ class Parser {
                                }
                                break;
                        case 'talkpagenamee':
-                               if ( $this->mTitle->canTalk() ) {
+                               if ( $this->mTitle->canHaveTalkPage() ) {
                                        $talkPage = $this->mTitle->getTalkPage();
                                        $value = wfEscapeWikiText( $talkPage->getPrefixedURL() );
                                } else {
@@ -2721,12 +2698,12 @@ class Parser {
                                $value = $this->mTitle->getNamespace();
                                break;
                        case 'talkspace':
-                               $value = $this->mTitle->canTalk()
+                               $value = $this->mTitle->canHaveTalkPage()
                                        ? str_replace( '_', ' ', $this->mTitle->getTalkNsText() )
                                        : '';
                                break;
                        case 'talkspacee':
-                               $value = $this->mTitle->canTalk() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
+                               $value = $this->mTitle->canHaveTalkPage() ? wfUrlencode( $this->mTitle->getTalkNsText() ) : '';
                                break;
                        case 'subjectspace':
                                $value = str_replace( '_', ' ', $this->mTitle->getSubjectNsText() );
@@ -3260,6 +3237,8 @@ class Parser {
                                        . wfMessage( 'parser-template-loop-warning', $titleText )->inContentLanguage()->text()
                                        . '</span>';
                                $this->addTrackingCategory( 'template-loop-category' );
+                               $this->mOutput->addWarning( wfMessage( 'template-loop-warning',
+                                       wfEscapeWikiText( $titleText ) )->text() );
                                wfDebug( __METHOD__ . ": template loop broken at '$titleText'\n" );
                        }
                }
@@ -4231,6 +4210,8 @@ class Parser {
                        # Save headline for section edit hint before it's escaped
                        $headlineHint = $safeHeadline;
 
+                       # Decode HTML entities
+                       $safeHeadline = Sanitizer::decodeCharReferences( $safeHeadline );
                        $fallbackHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_FALLBACK );
                        $linkAnchor = Sanitizer::escapeIdForLink( $safeHeadline );
                        $safeHeadline = Sanitizer::escapeIdForAttribute( $safeHeadline, Sanitizer::ID_PRIMARY );
@@ -5791,6 +5772,7 @@ class Parser {
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
                $text = Sanitizer::normalizeSectionNameWhitespace( $text );
+               $text = Sanitizer::decodeCharReferences( $text );
                return '#' . Sanitizer::escapeIdForLink( $text );
        }
 
@@ -5809,6 +5791,7 @@ class Parser {
                # Strip out wikitext links(they break the anchor)
                $text = $this->stripSectionName( $text );
                $text = Sanitizer::normalizeSectionNameWhitespace( $text );
+               $text = Sanitizer::decodeCharReferences( $text );
 
                if ( isset( $wgFragmentMode[1] ) && $wgFragmentMode[1] === 'legacy' ) {
                        // ForAttribute() and ForLink() are the same for legacy encoding