Escape unescaped messages shown in action=info
[lhc/web/wiklou.git] / includes / Linker.php
index 2bc36b1..3a039f6 100644 (file)
@@ -197,7 +197,6 @@ class Linker {
                        wfWarn( __METHOD__ . ': Requires $target to be a Title object.', 2 );
                        return "<!-- ERROR -->$html";
                }
-               wfProfileIn( __METHOD__ );
 
                if ( is_string( $query ) ) {
                        // some functions withing core using this still hand over query strings
@@ -212,7 +211,6 @@ class Linker {
                if ( !Hooks::run( 'LinkBegin',
                        array( $dummy, $target, &$html, &$customAttribs, &$query, &$options, &$ret ) )
                ) {
-                       wfProfileOut( __METHOD__ );
                        return $ret;
                }
 
@@ -220,7 +218,6 @@ class Linker {
                $target = self::normaliseSpecialPage( $target );
 
                # If we don't know whether the page exists, let's find out.
-               wfProfileIn( __METHOD__ . '-checkPageExistence' );
                if ( !in_array( 'known', $options ) && !in_array( 'broken', $options ) ) {
                        if ( $target->isKnown() ) {
                                $options[] = 'known';
@@ -228,7 +225,6 @@ class Linker {
                                $options[] = 'broken';
                        }
                }
-               wfProfileOut( __METHOD__ . '-checkPageExistence' );
 
                $oldquery = array();
                if ( in_array( "forcearticlepath", $options ) && $query ) {
@@ -255,7 +251,6 @@ class Linker {
                        $ret = Html::rawElement( 'a', $attribs, $html );
                }
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -280,7 +275,6 @@ class Linker {
         * @return string
         */
        private static function linkUrl( $target, $query, $options ) {
-               wfProfileIn( __METHOD__ );
                # We don't want to include fragments for broken links, because they
                # generally make no sense.
                if ( in_array( 'broken', $options ) && $target->hasFragment() ) {
@@ -306,7 +300,6 @@ class Linker {
                }
 
                $ret = $target->getLinkURL( $query, false, $proto );
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -320,12 +313,10 @@ class Linker {
         * @return array
         */
        private static function linkAttribs( $target, $attribs, $options ) {
-               wfProfileIn( __METHOD__ );
                global $wgUser;
                $defaults = array();
 
                if ( !in_array( 'noclasses', $options ) ) {
-                       wfProfileIn( __METHOD__ . '-getClasses' );
                        # Now build the classes.
                        $classes = array();
 
@@ -346,7 +337,6 @@ class Linker {
                        if ( $classes != array() ) {
                                $defaults['class'] = implode( ' ', $classes );
                        }
-                       wfProfileOut( __METHOD__ . '-getClasses' );
                }
 
                # Get a default title attribute.
@@ -370,7 +360,6 @@ class Linker {
                                $ret[$key] = $val;
                        }
                }
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -933,7 +922,6 @@ class Linker {
                }
 
                global $wgEnableUploads, $wgUploadMissingFileUrl, $wgUploadNavigationUrl;
-               wfProfileIn( __METHOD__ );
                if ( $label == '' ) {
                        $label = $title->getPrefixedText();
                }
@@ -946,19 +934,16 @@ class Linker {
                        $redir = RepoGroup::singleton()->getLocalRepo()->checkRedirect( $title );
 
                        if ( $redir ) {
-                               wfProfileOut( __METHOD__ );
                                return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
                        }
 
                        $href = self::getUploadUrl( $title, $query );
 
-                       wfProfileOut( __METHOD__ );
                        return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
                                htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
                                $encLabel . '</a>';
                }
 
-               wfProfileOut( __METHOD__ );
                return self::linkKnown( $title, $encLabel, array(), wfCgiToArray( $query ) );
        }
 
@@ -1295,7 +1280,6 @@ class Linker {
         * @return mixed|string
         */
        public static function formatComment( $comment, $title = null, $local = false ) {
-               wfProfileIn( __METHOD__ );
 
                # Sanitize text a bit:
                $comment = str_replace( "\n", " ", $comment );
@@ -1306,7 +1290,6 @@ class Linker {
                $comment = self::formatAutocomments( $comment, $title, $local );
                $comment = self::formatLinksInComment( $comment, $title, $local );
 
-               wfProfileOut( __METHOD__ );
                return $comment;
        }
 
@@ -1402,9 +1385,11 @@ class Linker {
         * @param string $comment Text to format links in
         * @param Title|null $title An optional title object used to links to sections
         * @param bool $local Whether section links should refer to local page
+        * @param string|null $wikiId Id of the wiki to link to (if not the local wiki), as used by WikiMap
+        *
         * @return string
         */
-       public static function formatLinksInComment( $comment, $title = null, $local = false ) {
+       public static function formatLinksInComment( $comment, $title = null, $local = false, $wikiId = null ) {
                return preg_replace_callback(
                        '/
                                \[\[
@@ -1418,7 +1403,7 @@ class Linker {
                                \]\]
                                ([^[]*) # 3. link trail (the text up until the next link)
                        /x',
-                       function ( $match ) use ( $title, $local ) {
+                       function ( $match ) use ( $title, $local, $wikiId ) {
                                global $wgContLang;
 
                                $medians = '(?:' . preg_quote( MWNamespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
@@ -1474,11 +1459,22 @@ class Linker {
                                                        $newTarget = clone ( $title );
                                                        $newTarget->setFragment( '#' . $target->getFragment() );
                                                        $target = $newTarget;
+
                                                }
-                                               $thelink = Linker::link(
-                                                       $target,
-                                                       $linkText . $inside
-                                               ) . $trail;
+
+                                               if ( $wikiId !== null ) {
+                                                       $thelink = Linker::makeExternalLink(
+                                                               WikiMap::getForeignURL( $wikiId, $target->getPrefixedURL() ),
+                                                               $linkText . $inside,
+                                                               true
+                                                       ) . $trail;
+                                               } else {
+                                                       $thelink = Linker::link(
+                                                               $target,
+                                                               $linkText . $inside
+                                                       ) . $trail;
+                                               }
+
                                        }
                                }
                                if ( $thelink ) {
@@ -1515,7 +1511,6 @@ class Linker {
                # ../Foobar/ -- convert to CurrentPage/Foobar, use 'Foobar' as text
                #              (from CurrentPage/CurrentSubPage)
 
-               wfProfileIn( __METHOD__ );
                $ret = $target; # default return value is no change
 
                # Some namespaces don't allow subpages,
@@ -1574,7 +1569,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -1611,7 +1605,7 @@ class Linker {
         * @return string HTML fragment
         */
        public static function revComment( Revision $rev, $local = false, $isPublic = false ) {
-               if ( $rev->getRawComment() == "" ) {
+               if ( $rev->getComment( Revision::RAW ) == "" ) {
                        return "";
                }
                if ( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
@@ -1876,7 +1870,7 @@ class Linker {
                $editCount = 0;
                $moreRevs = false;
                foreach ( $res as $row ) {
-                       if ( $rev->getRawUserText() != $row->rev_user_text ) {
+                       if ( $rev->getUserText( Revision::RAW ) != $row->rev_user_text ) {
                                if ( $verify &&
                                        ( $row->rev_deleted & Revision::DELETED_TEXT
                                                || $row->rev_deleted & Revision::DELETED_USER
@@ -1997,7 +1991,6 @@ class Linker {
                $section = false, $more = null
        ) {
                global $wgLang;
-               wfProfileIn( __METHOD__ );
 
                $outText = '';
                if ( count( $templates ) > 0 ) {
@@ -2050,14 +2043,14 @@ class Linker {
                                if ( $titleObj->quickUserCan( 'edit' ) ) {
                                        $editLink = self::link(
                                                $titleObj,
-                                               wfMessage( 'editlink' )->text(),
+                                               wfMessage( 'editlink' )->escaped(),
                                                array(),
                                                array( 'action' => 'edit' )
                                        );
                                } else {
                                        $editLink = self::link(
                                                $titleObj,
-                                               wfMessage( 'viewsourcelink' )->text(),
+                                               wfMessage( 'viewsourcelink' )->escaped(),
                                                array(),
                                                array( 'action' => 'edit' )
                                        );
@@ -2077,7 +2070,6 @@ class Linker {
 
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__ );
                return $outText;
        }
 
@@ -2089,7 +2081,6 @@ class Linker {
         * @return string HTML output
         */
        public static function formatHiddenCategories( $hiddencats ) {
-               wfProfileIn( __METHOD__ );
 
                $outText = '';
                if ( count( $hiddencats ) > 0 ) {
@@ -2106,7 +2097,6 @@ class Linker {
                        }
                        $outText .= '</ul>';
                }
-               wfProfileOut( __METHOD__ );
                return $outText;
        }
 
@@ -2135,7 +2125,6 @@ class Linker {
         *   escape), or false for no title attribute
         */
        public static function titleAttrib( $name, $options = null ) {
-               wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "tooltip-$name" );
 
@@ -2164,7 +2153,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                return $tooltip;
        }
 
@@ -2184,7 +2172,6 @@ class Linker {
                if ( isset( self::$accesskeycache[$name] ) ) {
                        return self::$accesskeycache[$name];
                }
-               wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "accesskey-$name" );
 
@@ -2200,7 +2187,6 @@ class Linker {
                        }
                }
 
-               wfProfileOut( __METHOD__ );
                self::$accesskeycache[$name] = $accesskey;
                return self::$accesskeycache[$name];
        }
@@ -2308,7 +2294,6 @@ class Linker {
        static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                wfDeprecated( __METHOD__, '1.21' );
 
-               wfProfileIn( __METHOD__ );
                $query = wfCgiToArray( $query );
                list( $inside, $trail ) = self::splitTrail( $trail );
                if ( $text === '' ) {
@@ -2317,7 +2302,6 @@ class Linker {
 
                $ret = self::link( $nt, "$prefix$text$inside", array(), $query ) . $trail;
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }
 
@@ -2342,8 +2326,6 @@ class Linker {
        ) {
                wfDeprecated( __METHOD__, '1.21' );
 
-               wfProfileIn( __METHOD__ );
-
                if ( $text == '' ) {
                        $text = self::linkText( $title );
                }
@@ -2357,7 +2339,6 @@ class Linker {
                $ret = self::link( $title, "$prefix$text$inside", $attribs, $query,
                        array( 'known', 'noclasses' ) ) . $trail;
 
-               wfProfileOut( __METHOD__ );
                return $ret;
        }