Have Linker::getLinkColour() accept LinkTarget objects
authorKunal Mehta <legoktm@member.fsf.org>
Fri, 13 May 2016 06:28:06 +0000 (23:28 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Thu, 26 May 2016 21:47:45 +0000 (14:47 -0700)
Change-Id: I7d7318099a822f9ddd88c538274511e6d8a8f1bc

includes/Linker.php
includes/linker/LinkRenderer.php

index c0d9358..71cb4e4 100644 (file)
@@ -138,22 +138,30 @@ class Linker {
         * Return the CSS colour of a known link
         *
         * @since 1.16.3
-        * @param Title $t
+        * @param LinkTarget $t
         * @param int $threshold User defined threshold
         * @return string CSS class
         */
-       public static function getLinkColour( $t, $threshold ) {
-               $colour = '';
-               if ( $t->isRedirect() ) {
+       public static function getLinkColour( LinkTarget $t, $threshold ) {
+               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
+               // Make sure the target is in the cache
+               $id = $linkCache->addLinkObj( $t );
+               if ( $id == 0 ) {
+                       // Doesn't exist
+                       return '';
+               }
+
+               if ( $linkCache->getGoodLinkFieldObj( $t, 'redirect' ) ) {
                        # Page is a redirect
-                       $colour = 'mw-redirect';
-               } elseif ( $threshold > 0 && $t->isContentPage() &&
-                       $t->exists() && $t->getLength() < $threshold
+                       return 'mw-redirect';
+               } elseif ( $threshold > 0 && MWNamespace::isContent( $t->getNamespace() )
+                       && $linkCache->getGoodLinkFieldObj( $t, 'length' ) < $threshold
                ) {
                        # Page is a stub
-                       $colour = 'stub';
+                       return 'stub';
                }
-               return $colour;
+
+               return '';
        }
 
        /**
index 1237907..432dcb2 100644 (file)
@@ -276,8 +276,7 @@ class LinkRenderer {
                if ( $target->isExternal() ) {
                        $classes[] = 'extiw';
                }
-               $title = Title::newFromLinkTarget( $target );
-               $colour = Linker::getLinkColour( $title, $this->stubThreshold );
+               $colour = Linker::getLinkColour( $target, $this->stubThreshold );
                if ( $colour !== '' ) {
                        $classes[] = $colour;
                }