Merge "fix diff against archived revision deleted version"
[lhc/web/wiklou.git] / includes / Linker.php
index 722df3a..5355140 100644 (file)
@@ -407,6 +407,11 @@ class Linker {
         * despite $query not being used.
         *
         * @param $nt Title
+        * @param $html String [optional]
+        * @param $query String [optional]
+        * @param $trail String [optional]
+        * @param $prefix String [optional]
+        *
         *
         * @return string
         */
@@ -978,7 +983,7 @@ class Linker {
         * @param $userName String: user name in database.
         * @param $altUserName String: text to display instead of the user name (optional)
         * @return String: HTML fragment
-        * @since 1.19 Method exists for a long time. $displayText was added in 1.19.
+        * @since 1.19 Method exists for a long time. $altUserName was added in 1.19.
         */
        public static function userLink( $userId, $userName, $altUserName = false ) {
                if ( $userId == 0 ) {
@@ -1041,7 +1046,10 @@ class Linker {
                wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
 
                if ( $items ) {
-                       return ' <span class="mw-usertoollinks">' . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped() . '</span>';
+                       return wfMessage( 'word-separator' )->plain()
+                               . '<span class="mw-usertoollinks">'
+                               . wfMessage( 'parentheses' )->rawParams( $wgLang->pipeList( $items ) )->escaped()
+                               . '</span>';
                } else {
                        return '';
                }
@@ -1125,8 +1133,9 @@ class Linker {
                } elseif ( $rev->userCan( Revision::DELETED_USER ) ) {
                        $userId = $rev->getUser( Revision::FOR_THIS_USER );
                        $userText = $rev->getUserText( Revision::FOR_THIS_USER );
-                       $link = self::userLink( $userId, $userText ) .
-                               ' ' . self::userToolLinks( $userId, $userText );
+                       $link = self::userLink( $userId, $userText )
+                               . wfMessage( 'word-separator' )->plain()
+                               . self::userToolLinks( $userId, $userText );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
@@ -1212,41 +1221,45 @@ class Linker {
                $pre = $match[1];
                $auto = $match[2];
                $post = $match[3];
-               $link = '';
-               if ( $title ) {
-                       $section = $auto;
-
-                       # Remove links that a user may have manually put in the autosummary
-                       # This could be improved by copying as much of Parser::stripSectionName as desired.
-                       $section = str_replace( '[[:', '', $section );
-                       $section = str_replace( '[[', '', $section );
-                       $section = str_replace( ']]', '', $section );
-
-                       $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
-                       if ( $local ) {
-                               $sectionTitle = Title::newFromText( '#' . $section );
-                       } else {
-                               $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
-                                       $title->getDBkey(), $section );
+               $comment = null;
+               wfRunHooks( 'FormatAutocomments', array( &$comment, $pre, $auto, $post, $title, $local ) );
+               if ( $comment === null ) {
+                       $link = '';
+                       if ( $title ) {
+                               $section = $auto;
+
+                               # Remove links that a user may have manually put in the autosummary
+                               # This could be improved by copying as much of Parser::stripSectionName as desired.
+                               $section = str_replace( '[[:', '', $section );
+                               $section = str_replace( '[[', '', $section );
+                               $section = str_replace( ']]', '', $section );
+
+                               $section = Sanitizer::normalizeSectionNameWhitespace( $section ); # bug 22784
+                               if ( $local ) {
+                                       $sectionTitle = Title::newFromText( '#' . $section );
+                               } else {
+                                       $sectionTitle = Title::makeTitleSafe( $title->getNamespace(),
+                                               $title->getDBkey(), $section );
+                               }
+                               if ( $sectionTitle ) {
+                                       $link = self::link( $sectionTitle,
+                                               $wgLang->getArrow(), array(), array(),
+                                               'noclasses' );
+                               } else {
+                                       $link = '';
+                               }
                        }
-                       if ( $sectionTitle ) {
-                               $link = self::link( $sectionTitle,
-                                       $wgLang->getArrow(), array(), array(),
-                                       'noclasses' );
-                       } else {
-                               $link = '';
+                       if ( $pre ) {
+                               # written summary $presep autocomment (summary /* section */)
+                               $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) );
                        }
+                       if ( $post ) {
+                               # autocomment $postsep written summary (/* section */ summary)
+                               $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
+                       }
+                       $auto = '<span class="autocomment">' . $auto . '</span>';
+                       $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>';
                }
-               if ( $pre ) {
-                       # written summary $presep autocomment (summary /* section */)
-                       $pre .= wfMsgExt( 'autocomment-prefix', array( 'escapenoentities', 'content' ) );
-               }
-               if ( $post ) {
-                       # autocomment $postsep written summary (/* section */ summary)
-                       $auto .= wfMsgExt( 'colon-separator', array( 'escapenoentities', 'content' ) );
-               }
-               $auto = '<span class="autocomment">' . $auto . '</span>';
-               $comment = $pre . $link . $wgLang->getDirMark() . '<span dir="auto">' . $auto . $post . '</span>';
                return $comment;
        }
 
@@ -1638,11 +1651,17 @@ class Linker {
         * other users.
         *
         * @param $rev Revision object
+        * @param $context IContextSource context to use or null for the main context.
         * @return string
         */
-       public static function generateRollback( $rev ) {
+       public static function generateRollback( $rev, IContextSource $context = null ) {
+               if ( $context === null ) {
+                       $context = RequestContext::getMain();
+               }
+
                return '<span class="mw-rollback-link">'
-                       . wfMessage( 'brackets' )->rawParams( self::buildRollbackLink( $rev ) )->plain()
+                       . $context->msg( 'brackets' )->rawParams(
+                               self::buildRollbackLink( $rev, $context ) )->plain()
                        . '</span>';
        }
 
@@ -1650,24 +1669,28 @@ class Linker {
         * Build a raw rollback link, useful for collections of "tool" links
         *
         * @param $rev Revision object
+        * @param $context IContextSource context to use or null for the main context.
         * @return String: HTML fragment
         */
-       public static function buildRollbackLink( $rev ) {
-               global $wgRequest, $wgUser;
+       public static function buildRollbackLink( $rev, IContextSource $context = null ) {
+               if ( $context === null ) {
+                       $context = RequestContext::getMain();
+               }
+
                $title = $rev->getTitle();
                $query = array(
                        'action' => 'rollback',
                        'from' => $rev->getUserText(),
-                       'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
+                       'token' => $context->getUser()->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
                );
-               if ( $wgRequest->getBool( 'bot' ) ) {
+               if ( $context->getRequest()->getBool( 'bot' ) ) {
                        $query['bot'] = '1';
                        $query['hidediff'] = '1'; // bug 15999
                }
                return self::link(
                        $title,
-                       wfMsgHtml( 'rollbacklink' ),
-                       array( 'title' => wfMsg( 'tooltip-rollback' ) ),
+                       $context->msg( 'rollbacklink' )->escaped(),
+                       array( 'title' => $context->msg( 'tooltip-rollback' )->text() ),
                        $query,
                        array( 'known', 'noclasses' )
                );
@@ -1705,7 +1728,7 @@ class Linker {
                        }
                        $outText .= "</div><ul>\n";
 
-                       usort( $templates, array( 'Title', 'compare' ) );
+                       usort( $templates, 'Title::compare' );
                        foreach ( $templates as $titleObj ) {
                                $r = $titleObj->getRestrictions( 'edit' );
                                if ( in_array( 'sysop', $r ) ) {
@@ -1905,10 +1928,10 @@ class Linker {
         * Creates a (show/hide) link for deleting revisions/log entries
         *
         * @param $query Array: query parameters to be passed to link()
-        * @param $restricted Boolean: set to true to use a <strong> instead of a <span>
+        * @param $restricted Boolean: set to true to use a "<strong>" instead of a "<span>"
         * @param $delete Boolean: set to true to use (show/hide) rather than (show)
         *
-        * @return String: HTML <a> link to Special:Revisiondelete, wrapped in a
+        * @return String: HTML "<a>" link to Special:Revisiondelete, wrapped in a
         * span to allow for customization of appearance with CSS
         */
        public static function revDeleteLink( $query = array(), $restricted = false, $delete = true ) {