Message 'filehist-thumbtext' - date and time separated as of request by user "Der...
[lhc/web/wiklou.git] / includes / Linker.php
index 870112e..1578bd7 100644 (file)
@@ -227,6 +227,13 @@ class Linker {
                return $ret;
        }
 
+       /**
+        * Identical to link(), except $options defaults to 'known'.
+        */
+       public function linkKnown( $target, $text = null, $customAttribs = array(), $query = array(), $options = 'known' ) {
+               return $this->link( $target, $text, $customAttribs, $query, $options );
+       }
+
        private function linkUrl( $target, $query, $options ) {
                wfProfileIn( __METHOD__ );
                # We don't want to include fragments for broken links, because they
@@ -268,7 +275,7 @@ class Linker {
                        }
 
                        # Note that redirects never count as stubs here.
-                       if ( $target->isRedirect() ) {
+                       if ( !in_array( 'broken', $options ) && $target->isRedirect() ) {
                                $classes[] = 'mw-redirect';
                        } elseif( $target->isContentPage() ) {
                                # Check for stub.
@@ -284,7 +291,10 @@ class Linker {
                }
 
                # Get a default title attribute.
-               if( in_array( 'known', $options ) ) {
+               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 ) ) {
                        $defaults['title'] = $target->getPrefixedText();
                } else {
                        $defaults['title'] = wfMsg( 'red-link-title', $target->getPrefixedText() );
@@ -433,7 +443,6 @@ class Linker {
         * @param $prefix String: optional prefix. As trail, only before instead of after.
         */
        function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
-               global $wgUser;
                wfProfileIn( __METHOD__ );
 
                $query = wfCgiToArray( $query );
@@ -618,7 +627,7 @@ class Linker {
                $img = '';
                $success = wfRunHooks('LinkerMakeExternalImage', array( &$url, &$alt, &$img ) );
                if(!$success) {
-                       wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}", true);
+                       wfDebug("Hook LinkerMakeExternalImage changed the output of external image with url {$url} and alt text {$alt} to {$img}\n", true);
                        return $img;
                }
                return Xml::element( 'img',
@@ -882,10 +891,13 @@ class Linker {
                        }
                }
 
-               if( $page ) {
-                       $query = $query ? '&page=' . urlencode( $page ) : 'page=' . urlencode( $page );
-               }
+               # ThumbnailImage::toHtml() already adds page= onto the end of DjVu URLs
+               # So we don't need to pass it here in $query. However, the URL for the
+               # zoom icon still needs it, so we make a unique query for it. See bug 14771
                $url = $title->getLocalURL( $query );
+               if( $page ) { 
+                       $url = wfAppendQuery( $url, 'page=' . urlencode( $page ) );
+               }
 
                $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
 
@@ -1007,22 +1019,37 @@ class Linker {
                  wfMsg( $key ) );
        }
 
-       /** @todo document */
+       /**
+        * Make an external link
+        * @param String $url URL to link to
+        * @param String $text text of link
+        * @param boolean $escape Do we escape the link text?
+        * @param String $linktype Type of external link. Gets added to the classes
+        * @param array $attribs Array of extra attributes to <a>
+        * 
+        * @TODO! @FIXME! This is a really crappy implementation. $linktype and 
+        * 'external' are mashed into the class attrib for the link (which is made
+        * into a string). Then, if we've got additional params in $attribs, we 
+        * add to it. People using this might want to change the classes (or other
+        * default link attributes), but passing $attribsText is just messy. Would 
+        * make a lot more sense to make put the classes into $attribs, let the 
+        * hook play with them, *then* expand it all at once. 
+        */
        function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
                $attribsText = $this->getExternalLinkAttributes( $url, $text, 'external ' . $linktype );
-               if ( $attribs ) {
-                       $attribsText .= Xml::expandAttributes( $attribs );
-               }
                $url = htmlspecialchars( $url );
                if( $escape ) {
                        $text = htmlspecialchars( $text );
                }
                $link = '';
-               $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link ) );
+               $success = wfRunHooks('LinkerMakeExternalLink', array( &$url, &$text, &$link, &$attribs, $linktype ) );
                if(!$success) {
-                       wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}", true);
+                       wfDebug("Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true);
                        return $link;
                }
+               if ( $attribs ) {
+                       $attribsText .= Xml::expandAttributes( $attribs );
+               }
                return '<a href="'.$url.'"'.$attribsText.'>'.$text.'</a>';
        }
 
@@ -1053,7 +1080,7 @@ class Linker {
         * @return string
         */
        public function userToolLinks( $userId, $userText, $redContribsWhenNoEdits = false, $flags = 0, $edits=null ) {
-               global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans;
+               global $wgUser, $wgDisableAnonTalk, $wgSysopUserBans, $wgLang;
                $talkable = !( $wgDisableAnonTalk && 0 == $userId );
                $blockable = ( $wgSysopUserBans || 0 == $userId ) && !$flags & self::TOOL_LINKS_NOBLOCK;
 
@@ -1079,7 +1106,7 @@ class Linker {
                }
 
                if( $items ) {
-                       return ' <span class="mw-usertoollinks">(' . implode( ' | ', $items ) . ')</span>';
+                       return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
                } else {
                        return '';
                }
@@ -1249,7 +1276,7 @@ class Linker {
                        }
                        if ( $sectionTitle ) {
                                $link = $this->link( $sectionTitle,
-                                       wfMsgForContent( 'sectionlink' ), array(), array(),
+                                       htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
                                        'noclasses' );
                        } else {
                                $link = '';
@@ -1357,6 +1384,7 @@ class Linker {
         * @return string HTML
         */
        function revComment( Revision $rev, $local = false, $isPublic = false ) {
+               if( $rev->getRawComment() == "" ) return "";
                if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
                        $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
@@ -1515,11 +1543,21 @@ class Linker {
         * @param string $anchor  The anchor to give the headline (the bit after the #)
         * @param string $text    The text of the header
         * @param string $link    HTML to add for the section edit link
+        * @param mixed  $legacyAnchor A second, optional anchor to give for
+        *   backward compatibility (false to omit)
         *
         * @return string HTML headline
         */
-       public function makeHeadline( $level, $attribs, $anchor, $text, $link ) {
-               return "<a name=\"$anchor\" id=\"$anchor\"></a><h$level$attribs$link <span class=\"mw-headline\">$text</span></h$level>";
+       public function makeHeadline( $level, $attribs, $anchor, $text, $link, $legacyAnchor = false ) {
+               $ret = "<a name=\"$anchor\" id=\"$anchor\"></a>"
+                       . "<h$level$attribs"
+                       . $link
+                       . " <span class=\"mw-headline\">$text</span>"
+                       . "</h$level>";
+               if ( $legacyAnchor !== false ) {
+                       $ret = "<a name=\"$legacyAnchor\" id=\"$legacyAnchor\"></a>$ret";
+               }
+               return $ret;
        }
 
        /**
@@ -1579,6 +1617,7 @@ class Linker {
                );
                if( $wgRequest->getBool( 'bot' ) ) {
                        $query['bot'] = '1';
+                       $query['hidediff'] = '1'; // bug 15999
                }
                $query['token'] = $wgUser->editToken( array( $title->getPrefixedText(),
                        $rev->getUserText() ) );
@@ -1596,12 +1635,9 @@ class Linker {
         * @param bool $section Whether this is for a section edit
         * @return string HTML output
         */
-       public function formatTemplates( $templates, $preview = false, $section = false) {
-               global $wgUser;
+       public function formatTemplates( $templates, $preview = false, $section = false ) {
                wfProfileIn( __METHOD__ );
 
-               $sk = $wgUser->getSkin();
-
                $outText = '';
                if ( count( $templates ) > 0 ) {
                        # Do a batch existence check
@@ -1620,7 +1656,7 @@ class Linker {
                        } else {
                                $outText .= wfMsgExt( 'templatesused', array( 'parse' ) );
                        }
-                       $outText .= '</div><ul>';
+                       $outText .= "</div><ul>\n";
 
                        usort( $templates, array( 'Title', 'compare' ) );
                        foreach ( $templates as $titleObj ) {
@@ -1633,11 +1669,11 @@ class Linker {
                                        $protected = '';
                                }
                                if( $titleObj->quickUserCan( 'edit' ) ) {
-                                       $editLink = $sk->makeLinkObj( $titleObj, wfMsg('editlink'), 'action=edit' );
+                                       $editLink = $this->makeLinkObj( $titleObj, wfMsg('editlink'), 'action=edit' );
                                } else {
-                                       $editLink = $sk->makeLinkObj( $titleObj, wfMsg('viewsourcelink'), 'action=edit' );
+                                       $editLink = $this->makeLinkObj( $titleObj, wfMsg('viewsourcelink'), 'action=edit' );
                                }
-                               $outText .= '<li>' . $sk->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
+                               $outText .= '<li>' . $this->link( $titleObj ) . ' (' . $editLink . ') ' . $protected . '</li>';
                        }
                        $outText .= '</ul>';
                }
@@ -1652,21 +1688,19 @@ class Linker {
         * or similar
         * @return string HTML output
         */
-       public function formatHiddenCategories( $hiddencats) {
-               global $wgUser, $wgLang;
+       public function formatHiddenCategories( $hiddencats ) {
+               global $wgLang;
                wfProfileIn( __METHOD__ );
 
-               $sk = $wgUser->getSkin();
-
                $outText = '';
                if ( count( $hiddencats ) > 0 ) {
                        # Construct the HTML
                        $outText = '<div class="mw-hiddenCategoriesExplanation">';
                        $outText .= wfMsgExt( 'hiddencategories', array( 'parse' ), $wgLang->formatnum( count( $hiddencats ) ) );
-                       $outText .= '</div><ul>';
+                       $outText .= "</div><ul>\n";
 
                        foreach ( $hiddencats as $titleObj ) {
-                               $outText .= '<li>' . $sk->link( $titleObj, null, array(), array(), 'known' ) . '</li>'; # If it's hidden, it must exist - no need to check with a LinkBatch
+                               $outText .= '<li>' . $this->link( $titleObj, null, array(), array(), 'known' ) . "</li>\n"; # If it's hidden, it must exist - no need to check with a LinkBatch
                        }
                        $outText .= '</ul>';
                }
@@ -1777,9 +1811,7 @@ class Linker {
                # FIXME: Per standard MW behavior, a value of '-' means to suppress the
                # attribute, but this is broken for accesskey: that might be a useful
                # value.
-               if( $accesskey != ''
-               && $accesskey != '-'
-               && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
+               if( $accesskey != '' && $accesskey != '-' && !wfEmptyMsg( "accesskey-$name", $accesskey ) ) {
                        wfProfileOut( __METHOD__ );
                        return $accesskey;
                }
@@ -1787,4 +1819,21 @@ class Linker {
                wfProfileOut( __METHOD__ );
                return false;
        }
+       
+       /**
+        * Creates a (show/hide) link for deleting revisions/log entries
+        *
+        * @param array $query  Query parameters to be passed to link()
+        * @param bool $restricted  Set to true to use a <strong> instead of a <span>
+        *
+        * @return string HTML <a> link to Special:Revisiondelete, wrapped in a
+        * span to allow for customization of appearance with CSS
+        */
+       public function revDeleteLink( $query = array(), $restricted = false ) {
+               $sp = SpecialPage::getTitleFor( 'Revisiondelete' );
+               $text = wfMsgHtml( 'rev-delundel' );
+               $tag = $restricted ? 'strong' : 'span';
+               $link = $this->link( $sp, $text, array(), $query, array( 'known', 'noclasses' ) );
+               return Xml::tags( $tag, array( 'class' => 'mw-revdelundel-link' ), "($link)" );
+       }
 }