Merge "Special:UserLogin: Consolidate create account buttons"
[lhc/web/wiklou.git] / includes / Linker.php
index 990ad15..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 '';
        }
 
        /**
@@ -217,8 +225,8 @@ class Linker {
                if ( $options ) {
                        // Custom options, create new LinkRenderer
                        if ( !isset( $options['stubThreshold'] ) ) {
-                               global $wgUser;
-                               $options['stubThreshold'] = $wgUser->getStubThreshold();
+                               $defaultLinkRenderer = $services->getLinkRenderer();
+                               $options['stubThreshold'] = $defaultLinkRenderer->getStubThreshold();
                        }
                        $linkRenderer = $services->getLinkRendererFactory()
                                ->createFromLegacyOptions( $options );
@@ -235,6 +243,8 @@ class Linker {
                        return $linkRenderer->makeKnownLink( $target, $text, $customAttribs, $query );
                } elseif ( in_array( 'broken', $options, true ) ) {
                        return $linkRenderer->makeBrokenLink( $target, $text, $customAttribs, $query );
+               } elseif ( in_array( 'noclasses', $options, true ) ) {
+                       return $linkRenderer->makePreloadedLink( $target, $text, '', $customAttribs, $query );
                } else {
                        return $linkRenderer->makeLink( $target, $text, $customAttribs, $query );
                }