Merge "Move EditPage robot policy out into EditAction"
[lhc/web/wiklou.git] / includes / Linker.php
index 80e4c62..f0a2963 100644 (file)
@@ -188,6 +188,7 @@ class Linker {
         *       Has compatibility issues on some setups, so avoid wherever possible.
         *     'http': Force a full URL with http:// as the scheme.
         *     'https': Force a full URL with https:// as the scheme.
+        *     'stubThreshold' => (int): Stub threshold to use when determining link classes.
         * @return string HTML <a> attribute
         */
        public static function link(
@@ -218,7 +219,7 @@ class Linker {
                $target = self::normaliseSpecialPage( $target );
 
                # If we don't know whether the page exists, let's find out.
-               if ( !in_array( 'known', $options ) && !in_array( 'broken', $options ) ) {
+               if ( !in_array( 'known', $options, true ) && !in_array( 'broken', $options, true ) ) {
                        if ( $target->isKnown() ) {
                                $options[] = 'known';
                        } else {
@@ -227,14 +228,14 @@ class Linker {
                }
 
                $oldquery = array();
-               if ( in_array( "forcearticlepath", $options ) && $query ) {
+               if ( in_array( "forcearticlepath", $options, true ) && $query ) {
                        $oldquery = $query;
                        $query = array();
                }
 
                # Note: we want the href attribute first, for prettiness.
                $attribs = array( 'href' => self::linkUrl( $target, $query, $options ) );
-               if ( in_array( 'forcearticlepath', $options ) && $oldquery ) {
+               if ( in_array( 'forcearticlepath', $options, true ) && $oldquery ) {
                        $attribs['href'] = wfAppendQuery( $attribs['href'], $oldquery );
                }
 
@@ -277,7 +278,7 @@ class Linker {
        private static function linkUrl( $target, $query, $options ) {
                # We don't want to include fragments for broken links, because they
                # generally make no sense.
-               if ( in_array( 'broken', $options ) && $target->hasFragment() ) {
+               if ( in_array( 'broken', $options, true ) && $target->hasFragment() ) {
                        $target = clone $target;
                        $target->setFragment( '' );
                }
@@ -285,15 +286,15 @@ class Linker {
                # If it's a broken link, add the appropriate query pieces, unless
                # there's already an action specified, or unless 'edit' makes no sense
                # (i.e., for a nonexistent special page).
-               if ( in_array( 'broken', $options ) && empty( $query['action'] )
+               if ( in_array( 'broken', $options, true ) && empty( $query['action'] )
                        && !$target->isSpecialPage() ) {
                        $query['action'] = 'edit';
                        $query['redlink'] = '1';
                }
 
-               if ( in_array( 'http', $options ) ) {
+               if ( in_array( 'http', $options, true ) ) {
                        $proto = PROTO_HTTP;
-               } elseif ( in_array( 'https', $options ) ) {
+               } elseif ( in_array( 'https', $options, true ) ) {
                        $proto = PROTO_HTTPS;
                } else {
                        $proto = PROTO_RELATIVE;
@@ -316,11 +317,11 @@ class Linker {
                global $wgUser;
                $defaults = array();
 
-               if ( !in_array( 'noclasses', $options ) ) {
+               if ( !in_array( 'noclasses', $options, true ) ) {
                        # Now build the classes.
                        $classes = array();
 
-                       if ( in_array( 'broken', $options ) ) {
+                       if ( in_array( 'broken', $options, true ) ) {
                                $classes[] = 'new';
                        }
 
@@ -328,8 +329,11 @@ class Linker {
                                $classes[] = 'extiw';
                        }
 
-                       if ( !in_array( 'broken', $options ) ) { # Avoid useless calls to LinkCache (see r50387)
-                               $colour = self::getLinkColour( $target, $wgUser->getStubThreshold() );
+                       if ( !in_array( 'broken', $options, true ) ) { # Avoid useless calls to LinkCache (see r50387)
+                               $colour = self::getLinkColour(
+                                       $target,
+                                       isset( $options['stubThreshold'] ) ? $options['stubThreshold'] : $wgUser->getStubThreshold()
+                               );
                                if ( $colour !== '' ) {
                                        $classes[] = $colour; # mw-redirect or stub
                                }
@@ -343,10 +347,13 @@ class Linker {
                if ( $target->getPrefixedText() == '' ) {
                        # A link like [[#Foo]].  This used to mean an empty title
                        # attribute, but that's silly.  Just don't output a title.
-               } elseif ( in_array( 'known', $options ) ) {
+               } elseif ( in_array( 'known', $options, true ) ) {
                        $defaults['title'] = $target->getPrefixedText();
                } else {
-                       $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )->text();
+                       // This ends up in parser cache!
+                       $defaults['title'] = wfMessage( 'red-link-title', $target->getPrefixedText() )
+                               ->inContentLanguage()
+                               ->text();
                }
 
                # Finally, merge the custom attribs with the default ones, and iterate
@@ -1842,7 +1849,7 @@ class Linker {
                }
 
                $editCount = false;
-               if ( in_array( 'verify', $options ) ) {
+               if ( in_array( 'verify', $options, true ) ) {
                        $editCount = self::getRollbackEditCount( $rev, true );
                        if ( $editCount === false ) {
                                return '';
@@ -1851,7 +1858,7 @@ class Linker {
 
                $inner = self::buildRollbackLink( $rev, $context, $editCount );
 
-               if ( !in_array( 'noBrackets', $options ) ) {
+               if ( !in_array( 'noBrackets', $options, true ) ) {
                        $inner = $context->msg( 'brackets' )->rawParams( $inner )->escaped();
                }
 
@@ -2010,7 +2017,7 @@ class Linker {
         * directly paste it in as the link (escaping needs to be done manually).
         * Finally, if $more is a Message, call toString().
         *
-        * @param array $templates Array of templates from Article::getUsedTemplate or similar
+        * @param Title[] $templates Array of templates
         * @param bool $preview Whether this is for a preview
         * @param bool $section Whether this is for a section edit
         * @param Title|Message|string|null $more An escaped link for "More..." of the templates
@@ -2150,13 +2157,13 @@ class Linker {
         * @param string $name Id of the element, minus prefixes.
         * @param string|null $options Null or the string 'withaccess' to add an access-
         *   key hint
+        * @param array $msgParams Parameters to pass to the message
+        *
         * @return string Contents of the title attribute (which you must HTML-
         *   escape), or false for no title attribute
         */
-       public static function titleAttrib( $name, $options = null ) {
-
-               $message = wfMessage( "tooltip-$name" );
-
+       public static function titleAttrib( $name, $options = null, array $msgParams = array() ) {
+               $message = wfMessage( "tooltip-$name", $msgParams );
                if ( !$message->exists() ) {
                        $tooltip = false;
                } else {
@@ -2306,15 +2313,18 @@ class Linker {
 
        /**
         * Returns the attributes for the tooltip and access key.
+        *
         * @param string $name
+        * @param array $msgParams Params for constructing the message
+        *
         * @return array
         */
-       public static function tooltipAndAccesskeyAttribs( $name ) {
+       public static function tooltipAndAccesskeyAttribs( $name, array $msgParams = array() ) {
                # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
                # no attribute" instead of "output '' as value for attribute", this
                # would be three lines.
                $attribs = array(
-                       'title' => self::titleAttrib( $name, 'withaccess' ),
+                       'title' => self::titleAttrib( $name, 'withaccess', $msgParams ),
                        'accesskey' => self::accesskey( $name )
                );
                if ( $attribs['title'] === false ) {