Make use of \File::getArchiveRel to avoid code duplication
[lhc/web/wiklou.git] / includes / Linker.php
index b9084cc..b605acd 100644 (file)
@@ -1151,7 +1151,6 @@ class Linker {
                                );
 
                                if ( $comment === null ) {
-                                       $link = '';
                                        if ( $title ) {
                                                $section = $auto;
                                                # Remove links that a user may have manually put in the autosummary
@@ -1160,6 +1159,10 @@ class Linker {
                                                $section = str_replace( '[[', '', $section );
                                                $section = str_replace( ']]', '', $section );
 
+                                               // We don't want any links in the auto text to be linked, but we still
+                                               // want to show any [[ ]]
+                                               $sectionText = str_replace( '[[', '[[', $auto );
+
                                                $section = substr( Parser::guessSectionNameFromStrippedText( $section ), 1 );
                                                if ( $local ) {
                                                        $sectionTitle = Title::makeTitleSafe( NS_MAIN, '', $section );
@@ -1168,9 +1171,10 @@ class Linker {
                                                                $title->getDBkey(), $section );
                                                }
                                                if ( $sectionTitle ) {
-                                                       $link = Linker::makeCommentLink( $sectionTitle, $wgLang->getArrow(), $wikiId, 'noclasses' );
-                                               } else {
-                                                       $link = '';
+                                                       $auto = Linker::makeCommentLink(
+                                                               $sectionTitle, $wgLang->getArrow() . $wgLang->getDirMark() . $sectionText,
+                                                               $wikiId, 'noclasses'
+                                                       );
                                                }
                                        }
                                        if ( $pre ) {
@@ -1181,10 +1185,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 . $auto;
                                }
                                return $comment;
                        },
@@ -1440,7 +1445,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
@@ -1449,8 +1454,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>";
                }
        }
 
@@ -1462,9 +1472,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 "";
                }
@@ -1472,7 +1485,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>";
                }
@@ -1562,11 +1575,18 @@ class Linker {
         *
         * @since 1.16.3
         * @param string $toc Html of the Table Of Contents
-        * @param string|Language|bool $lang Language for the toc title, defaults to user language
+        * @param string|Language|bool|null $lang Language for the toc title, defaults to user language.
+        *  The types string and bool are deprecated.
         * @return string Full html of the TOC
         */
-       public static function tocList( $toc, $lang = false ) {
-               $lang = wfGetLangObj( $lang );
+       public static function tocList( $toc, $lang = null ) {
+               global $wgLang;
+               $lang = $lang ?? $wgLang;
+               if ( !is_object( $lang ) ) {
+                       wfDeprecated( __METHOD__ . ' with type other than Language for $lang', '1.33' );
+                       $lang = wfGetLangObj( $lang );
+               }
+
                $title = wfMessage( 'toc' )->inLanguage( $lang )->escaped();
 
                return '<div id="toc" class="toc">'
@@ -1598,10 +1618,11 @@ class Linker {
         *
         * @since 1.16.3. $lang added in 1.17
         * @param array $tree Return value of ParserOutput::getSections()
-        * @param string|Language|bool $lang Language for the toc title, defaults to user language
+        * @param string|Language|bool|null $lang Language for the toc title, defaults to user language.
+        *  The types string and bool are deprecated.
         * @return string HTML fragment
         */
-       public static function generateTOC( $tree, $lang = false ) {
+       public static function generateTOC( $tree, $lang = null ) {
                $toc = '';
                $lastLevel = 0;
                foreach ( $tree as $section ) {