Merge "statsd: Rename MediawikiStatsdDataFactory to IBufferingStatsdDataFactory"
[lhc/web/wiklou.git] / includes / Linker.php
index d3d1f38..f2e4ac4 100644 (file)
@@ -38,102 +38,6 @@ class Linker {
        const TOOL_LINKS_NOBLOCK = 1;
        const TOOL_LINKS_EMAIL = 2;
 
-       /**
-        * Get the appropriate HTML attributes to add to the "a" element of an interwiki link.
-        *
-        * @since 1.16.3
-        * @deprecated since 1.25
-        *
-        * @param string $title The title text for the link, URL-encoded (???) but
-        *   not HTML-escaped
-        * @param string $unused Unused
-        * @param string $class The contents of the class attribute; if an empty
-        *   string is passed, which is the default value, defaults to 'external'.
-        * @return string
-        */
-       static function getInterwikiLinkAttributes( $title, $unused = null, $class = 'external' ) {
-               global $wgContLang;
-
-               wfDeprecated( __METHOD__, '1.25' );
-
-               # @todo FIXME: We have a whole bunch of handling here that doesn't happen in
-               # getExternalLinkAttributes, why?
-               $title = urldecode( $title );
-               $title = $wgContLang->checkTitleEncoding( $title );
-               $title = preg_replace( '/[\\x00-\\x1f]/', ' ', $title );
-
-               return self::getLinkAttributesInternal( $title, $class );
-       }
-
-       /**
-        * Get the appropriate HTML attributes to add to the "a" element of an internal link.
-        *
-        * @since 1.16.3
-        * @deprecated since 1.25
-        *
-        * @param string $title The title text for the link, URL-encoded (???) but
-        *   not HTML-escaped
-        * @param string $unused Unused
-        * @param string $class The contents of the class attribute, default none
-        * @return string
-        */
-       static function getInternalLinkAttributes( $title, $unused = null, $class = '' ) {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               $title = urldecode( $title );
-               $title = strtr( $title, '_', ' ' );
-               return self::getLinkAttributesInternal( $title, $class );
-       }
-
-       /**
-        * Get the appropriate HTML attributes to add to the "a" element of an internal
-        * link, given the Title object for the page we want to link to.
-        *
-        * @since 1.16.3
-        * @deprecated since 1.25
-        *
-        * @param Title $nt
-        * @param string $unused Unused
-        * @param string $class The contents of the class attribute, default none
-        * @param string|bool $title Optional (unescaped) string to use in the title
-        *   attribute; if false, default to the name of the page we're linking to
-        * @return string
-        */
-       static function getInternalLinkAttributesObj( $nt, $unused = null, $class = '', $title = false ) {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               if ( $title === false ) {
-                       $title = $nt->getPrefixedText();
-               }
-               return self::getLinkAttributesInternal( $title, $class );
-       }
-
-       /**
-        * Common code for getLinkAttributesX functions
-        *
-        * @since 1.16.3
-        * @deprecated since 1.25
-        *
-        * @param string $title
-        * @param string $class
-        *
-        * @return string
-        */
-       private static function getLinkAttributesInternal( $title, $class ) {
-               wfDeprecated( __METHOD__, '1.25' );
-
-               $title = htmlspecialchars( $title );
-               $class = htmlspecialchars( $class );
-               $r = '';
-               if ( $class != '' ) {
-                       $r .= " class=\"$class\"";
-               }
-               if ( $title != '' ) {
-                       $r .= " title=\"$title\"";
-               }
-               return $r;
-       }
-
        /**
         * Return the CSS colour of a known link
         *
@@ -260,10 +164,10 @@ class Linker {
        }
 
        /**
-        * Make appropriate markup for a link to the current article. This is
-        * currently rendered as the bold link text. The calling sequence is the
-        * same as the other make*LinkObj static functions, despite $query not
-        * being used.
+        * Make appropriate markup for a link to the current article. This is since
+        * MediaWiki 1.29.0 rendered as an <a> tag without an href and with a class
+        * showing the link text. The calling sequence is the same as for the other
+        * make*LinkObj static functions, but $query is not used.
         *
         * @since 1.16.3
         * @param Title $nt
@@ -275,7 +179,7 @@ class Linker {
         * @return string
         */
        public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
-               $ret = "<strong class=\"selflink\">{$prefix}{$html}</strong>{$trail}";
+               $ret = "<a class=\"mw-selflink selflink\">{$prefix}{$html}</a>{$trail}";
                if ( !Hooks::run( 'SelfLinkBegin', [ $nt, &$html, &$trail, &$prefix, &$ret ] ) ) {
                        return $ret;
                }
@@ -284,7 +188,7 @@ class Linker {
                        $html = htmlspecialchars( $nt->getPrefixedText() );
                }
                list( $inside, $trail ) = self::splitTrail( $trail );
-               return "<strong class=\"selflink\">{$prefix}{$html}{$inside}</strong>{$trail}";
+               return "<a class=\"mw-selflink selflink\">{$prefix}{$html}{$inside}</a>{$trail}";
        }
 
        /**
@@ -686,7 +590,7 @@ class Linker {
 
                # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
                # So we don't need to pass it here in $query. However, the URL for the
-               # zoom icon still needs it, so we make a unique query for it. See bug 14771
+               # zoom icon still needs it, so we make a unique query for it. See T16771
                $url = $title->getLocalURL( $query );
                if ( $page ) {
                        $url = wfAppendQuery( $url, [ 'page' => $page ] );
@@ -988,7 +892,7 @@ class Linker {
                        if ( $altUserName === false ) {
                                $altUserName = IP::prettifyIP( $userName );
                        }
-                       $classes .= ' mw-anonuserlink'; // Separate link class for anons (bug 43179)
+                       $classes .= ' mw-anonuserlink'; // Separate link class for anons (T45179)
                } else {
                        $page = Title::makeTitle( NS_USER, $userName );
                }
@@ -1029,13 +933,14 @@ class Linker {
                if ( $userId ) {
                        // check if the user has an edit
                        $attribs = [];
+                       $attribs['class'] = 'mw-usertoollinks-contribs';
                        if ( $redContribsWhenNoEdits ) {
                                if ( intval( $edits ) === 0 && $edits !== 0 ) {
                                        $user = User::newFromId( $userId );
                                        $edits = $user->getEditCount();
                                }
                                if ( $edits === 0 ) {
-                                       $attribs['class'] = 'new';
+                                       $attribs['class'] .= ' new';
                                }
                        }
                        $contribsPage = SpecialPage::getTitleFor( 'Contributions', $userText );
@@ -1082,7 +987,10 @@ class Linker {
         */
        public static function userTalkLink( $userId, $userText ) {
                $userTalkPage = Title::makeTitle( NS_USER_TALK, $userText );
-               $userTalkLink = self::link( $userTalkPage, wfMessage( 'talkpagelinktext' )->escaped() );
+               $moreLinkAttribs['class'] = 'mw-usertoollinks-talk';
+               $userTalkLink = self::link( $userTalkPage,
+                                               wfMessage( 'talkpagelinktext' )->escaped(),
+                                               $moreLinkAttribs );
                return $userTalkLink;
        }
 
@@ -1094,7 +1002,10 @@ class Linker {
         */
        public static function blockLink( $userId, $userText ) {
                $blockPage = SpecialPage::getTitleFor( 'Block', $userText );
-               $blockLink = self::link( $blockPage, wfMessage( 'blocklink' )->escaped() );
+               $moreLinkAttribs['class'] = 'mw-usertoollinks-block';
+               $blockLink = self::link( $blockPage,
+                                        wfMessage( 'blocklink' )->escaped(),
+                                        $moreLinkAttribs );
                return $blockLink;
        }
 
@@ -1105,7 +1016,10 @@ class Linker {
         */
        public static function emailLink( $userId, $userText ) {
                $emailPage = SpecialPage::getTitleFor( 'Emailuser', $userText );
-               $emailLink = self::link( $emailPage, wfMessage( 'emaillink' )->escaped() );
+               $moreLinkAttribs['class'] = 'mw-usertoollinks-mail';
+               $emailLink = self::link( $emailPage,
+                                        wfMessage( 'emaillink' )->escaped(),
+                                        $moreLinkAttribs );
                return $emailLink;
        }
 
@@ -1182,7 +1096,7 @@ class Linker {
        ) {
                # Sanitize text a bit:
                $comment = str_replace( "\n", " ", $comment );
-               # Allow HTML entities (for bug 13815)
+               # Allow HTML entities (for T15815)
                $comment = Sanitizer::escapeHtmlAllowEntities( $comment );
 
                # Render autocomments and make links:
@@ -1251,7 +1165,7 @@ class Linker {
                                                $section = str_replace( '[[', '', $section );
                                                $section = str_replace( ']]', '', $section );
 
-                                               $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
+                                               $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # T24784
                                                if ( $local ) {
                                                        $sectionTitle = Title::newFromText( '#' . $section );
                                                } else {
@@ -1417,7 +1331,10 @@ class Linker {
                        $link = Linker::makeExternalLink(
                                WikiMap::getForeignURL(
                                        $wikiId,
-                                       $title->getPrefixedText(),
+                                       $title->getNamespace() === 0
+                                               ? $title->getDBkey()
+                                               : MWNamespace::getCanonicalName( $title->getNamespace() ) . ':'
+                                                       . $title->getDBkey(),
                                        $title->getFragment()
                                ),
                                $text,
@@ -1460,7 +1377,7 @@ class Linker {
                        } else {
                                $suffix = '';
                        }
-                       # bug 7425
+                       # T9425
                        $target = trim( $target );
                        # Look at the first character
                        if ( $target != '' && $target[0] === '/' ) {
@@ -1647,7 +1564,7 @@ class Linker {
                $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
 
                return '<div id="toc" class="toc">'
-                       . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
+                       . '<div class="toctitle"><h2>' . $title . "</h2></div>\n"
                        . $toc
                        . "</ul>\n</div>\n";
        }
@@ -1883,7 +1800,7 @@ class Linker {
 
                if ( $context->getRequest()->getBool( 'bot' ) ) {
                        $query['bot'] = '1';
-                       $query['hidediff'] = '1'; // bug 15999
+                       $query['hidediff'] = '1'; // T17999
                }
 
                $disableRollbackEditCount = false;
@@ -1968,7 +1885,6 @@ class Linker {
         * @return string HTML output
         */
        public static function formatHiddenCategories( $hiddencats ) {
-
                $outText = '';
                if ( count( $hiddencats ) > 0 ) {
                        # Construct the HTML
@@ -2180,9 +2096,6 @@ class Linker {
         * @return array
         */
        public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = [] ) {
-               # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
-               # no attribute" instead of "output '' as value for attribute", this
-               # would be three lines.
                $attribs = [
                        'title' => self::titleAttrib( $name, 'withaccess', $msgParams ),
                        'accesskey' => self::accesskey( $name )
@@ -2204,9 +2117,6 @@ class Linker {
         * @return null|string
         */
        public static function tooltip( $name, $options = null ) {
-               # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
-               # no attribute" instead of "output '' as value for attribute", this
-               # would be two lines.
                $tooltip = self::titleAttrib( $name, $options );
                if ( $tooltip === false ) {
                        return '';
@@ -2217,4 +2127,3 @@ class Linker {
        }
 
 }
-