Merge "RedisBagOStuff: Do not pass unused parameter"
[lhc/web/wiklou.git] / includes / Linker.php
index 0ee6c92..7eda21b 100644 (file)
@@ -289,6 +289,7 @@ class Linker {
         *          link-title      Title object to link to
         *          link-target     Value for the target attribute, only with link-url
         *          no-link         Boolean, suppress description link
+        *          targetlang      (optional) Target language code, see Parser::getTargetLanguage()
         *
         * @param array $handlerParams Associative array of media handler parameters, to be passed
         *       to transform(). Typical keys are "width" and "page".
@@ -1076,10 +1077,6 @@ class Linker {
         * @author Erik Moeller <moeller@scireview.de>
         * @since 1.16.3. $wikiId added in 1.26
         *
-        * Note: there's not always a title to pass to this function.
-        * Since you can't set a default parameter for a reference, I've turned it
-        * temporarily to a value pass. Should be adjusted further. --brion
-        *
         * @param string $comment
         * @param Title|null $title Title object (to generate link to the section in autocomment)
         *  or null
@@ -1087,7 +1084,7 @@ class Linker {
         * @param string|null $wikiId Id (as used by WikiMap) of the wiki to generate links to.
         *  For use with external changes.
         *
-        * @return mixed|string
+        * @return string HTML
         */
        public static function formatComment(
                $comment, $title = null, $local = false, $wikiId = null
@@ -1171,7 +1168,10 @@ class Linker {
                                                                $title->getDBkey(), $section );
                                                }
                                                if ( $sectionTitle ) {
-                                                       $link = Linker::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
+                                                       $link = Linker::makeCommentLink(
+                                                               $sectionTitle, $wgLang->getArrow() . $auto, $wikiId, 'noclasses'
+                                                       );
+                                                       $auto = '';
                                                } else {
                                                        $link = '';
                                                }
@@ -1184,10 +1184,11 @@ class Linker {
                                                # autocomment $postsep written summary (/* section */ summary)
                                                $auto .= wfMessage( 'colon-separator' )->inContentLanguage()->escaped();
                                        }
-                                       $auto = '<span class="autocomment">' . $auto . '</span>';
-                                       $comment = $pre . $link . $wgLang->getDirMark()
-                                               . '<span dir="auto">' . $auto;
-                                       $append .= '</span>';
+                                       if ( $auto ) {
+                                               $auto = '<span dir="auto"><span class="autocomment">' . $auto . '</span>';
+                                               $append .= '</span>';
+                                       }
+                                       $comment = $pre . $link . $wgLang->getDirMark() . $auto;
                                }
                                return $comment;
                        },
@@ -1221,6 +1222,7 @@ class Linker {
                return preg_replace_callback(
                        '/
                                \[\[
+                               \s*+ # ignore leading whitespace, the *+ quantifier disallows backtracking
                                :? # ignore optional leading colon
                                ([^\]|]+) # 1. link target; page names cannot include ] or |
                                (?:\|
@@ -1442,7 +1444,7 @@ class Linker {
         * @return string
         */
        public static function commentBlock(
-               $comment, $title = null, $local = false, $wikiId = null
+               $comment, $title = null, $local = false, $wikiId = null, $useParentheses = true
        ) {
                // '*' used to be the comment inserted by the software way back
                // in antiquity in case none was provided, here for backwards
@@ -1451,8 +1453,13 @@ class Linker {
                        return '';
                } else {
                        $formatted = self::formatComment( $comment, $title, $local, $wikiId );
-                       $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
-                       return " <span class=\"comment\">$formatted</span>";
+                       if ( $useParentheses ) {
+                               $formatted = wfMessage( 'parentheses' )->rawParams( $formatted )->escaped();
+                               $classNames = 'comment';
+                       } else {
+                               $classNames = 'comment comment--without-parentheses';
+                       }
+                       return " <span class=\"$classNames\">$formatted</span>";
                }
        }
 
@@ -1464,9 +1471,12 @@ class Linker {
         * @param Revision $rev
         * @param bool $local Whether section links should refer to local page
         * @param bool $isPublic Show only if all users can see it
+        * @param bool $useParentheses (optional) Wrap comments in parentheses where needed
         * @return string HTML fragment
         */
-       public static function revComment( Revision $rev, $local = false, $isPublic = false ) {
+       public static function revComment( Revision $rev, $local = false, $isPublic = false,
+               $useParentheses = true
+       ) {
                if ( $rev->getComment( Revision::RAW ) == "" ) {
                        return "";
                }
@@ -1474,7 +1484,7 @@ class Linker {
                        $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
                } elseif ( $rev->userCan( Revision::DELETED_COMMENT ) ) {
                        $block = self::commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
-                               $rev->getTitle(), $local );
+                               $rev->getTitle(), $local, null, $useParentheses );
                } else {
                        $block = " <span class=\"comment\">" . wfMessage( 'rev-deleted-comment' )->escaped() . "</span>";
                }