Replace get{Local,Full,Link,Canonical}URL's $variant argument with a secondary $query...
[lhc/web/wiklou.git] / includes / Linker.php
index 3297e97..3ccba76 100644 (file)
@@ -109,7 +109,7 @@ class Linker {
         * @param $threshold Integer: user defined threshold
         * @return String: CSS class
         */
-       static function getLinkColour( $t, $threshold ) {
+       public static function getLinkColour( $t, $threshold ) {
                $colour = '';
                if ( $t->isRedirect() ) {
                        # Page is a redirect
@@ -250,11 +250,11 @@ class Linker {
                # there's already an action specified, or unless 'edit' makes no sense
                # (i.e., for a nonexistent special page).
                if ( in_array( 'broken', $options ) && empty( $query['action'] )
-                       && $target->getNamespace() != NS_SPECIAL ) {
+                       && !$target->isSpecialPage() ) {
                        $query['action'] = 'edit';
                        $query['redlink'] = '1';
                }
-               $ret = $target->getLinkUrl( $query );
+               $ret = $target->getLinkURL( $query );
                wfProfileOut( __METHOD__ );
                return $ret;
        }
@@ -376,7 +376,7 @@ class Linker {
         *
         * @return string
         */
-       static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
+       public static function makeSelfLinkObj( $nt, $html = '', $query = '', $trail = '', $prefix = '' ) {
                if ( $html == '' ) {
                        $html = htmlspecialchars( $nt->getPrefixedText() );
                }
@@ -389,7 +389,7 @@ class Linker {
         * @return Title
         */
        static function normaliseSpecialPage( Title $title ) {
-               if ( $title->getNamespace() == NS_SPECIAL ) {
+               if ( $title->isSpecialPage() ) {
                        list( $name, $subpage ) = SpecialPageFactory::resolveAlias( $title->getDBkey() );
                        if ( !$name ) {
                                return $title;
@@ -410,7 +410,7 @@ class Linker {
         *
         * @return string
         */
-       static function fnamePart( $url ) {
+       private static function fnamePart( $url ) {
                $basename = strrchr( $url, '/' );
                if ( false === $basename ) {
                        $basename = $url;
@@ -429,7 +429,7 @@ class Linker {
         *
         * @return string
         */
-       static function makeExternalImage( $url, $alt = '' ) {
+       public static function makeExternalImage( $url, $alt = '' ) {
                if ( $alt == '' ) {
                        $alt = self::fnamePart( $url );
                }
@@ -478,7 +478,7 @@ class Linker {
         * @param $widthOption: Used by the parser to remember the user preference thumbnailsize
         * @return String: HTML for an image, with links, wrappers, etc.
         */
-       static function makeImageLink2( Title $title, $file, $frameParams = array(),
+       public static function makeImageLink2( Title $title, $file, $frameParams = array(),
                $handlerParams = array(), $time = false, $query = "", $widthOption = null )
        {
                $res = null;
@@ -605,7 +605,7 @@ class Linker {
         * @param $frameParams The frame parameters
         * @param $query An optional query string to add to description page links
         */
-       static function getImageLinkMTOParams( $frameParams, $query = '' ) {
+       private static function getImageLinkMTOParams( $frameParams, $query = '' ) {
                $mtoParams = array();
                if ( isset( $frameParams['link-url'] ) && $frameParams['link-url'] !== '' ) {
                        $mtoParams['custom-url-link'] = $frameParams['link-url'];
@@ -634,7 +634,7 @@ class Linker {
         * @param $framed Boolean
         * @param $manualthumb String
         */
-       static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
+       public static function makeThumbLinkObj( Title $title, $file, $label = '', $alt,
                $align = 'right', $params = array(), $framed = false , $manualthumb = "" )
        {
                $frameParams = array(
@@ -660,7 +660,7 @@ class Linker {
         * @param string $query
         * @return mixed
         */
-       static function makeThumbLink2( Title $title, $file, $frameParams = array(),
+       public static function makeThumbLink2( Title $title, $file, $frameParams = array(),
                $handlerParams = array(), $time = false, $query = "" )
        {
                global $wgStylePath, $wgContLang;
@@ -866,11 +866,11 @@ class Linker {
        /**
         * Make a link to a special page given its name and, optionally,
         * a message key from the link text.
-        * Usage example: $skin->specialLink( 'recentchanges' )
+        * Usage example: Linker::specialLink( 'Recentchanges' )
         *
         * @return string
         */
-       static function specialLink( $name, $key = '' ) {
+       public static function specialLink( $name, $key = '' ) {
                if ( $key == '' ) {
                        $key = strtolower( $name );
                }
@@ -886,12 +886,12 @@ class Linker {
         * @param $linktype String: type of external link. Gets added to the classes
         * @param $attribs Array of extra attributes to <a>
         */
-       static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
+       public static function makeExternalLink( $url, $text, $escape = true, $linktype = '', $attribs = array() ) {
                $class = "external";
-               if ( isset($linktype) && $linktype ) {
+               if ( $linktype ) {
                        $class .= " $linktype";
                }
-               if ( isset($attribs['class']) && $attribs['class'] ) {
+               if ( isset( $attribs['class'] ) && $attribs['class'] ) {
                        $class .= " {$attribs['class']}";
                }
                $attribs['class'] = $class;
@@ -941,8 +941,8 @@ class Linker {
        ) {
                global $wgUser, $wgDisableAnonTalk, $wgLang;
                $talkable = !( $wgDisableAnonTalk && 0 == $userId );
-               $blockable = !$flags & self::TOOL_LINKS_NOBLOCK;
-               $addEmailLink = $flags & self::TOOL_LINKS_EMAIL;
+               $blockable = !( $flags & self::TOOL_LINKS_NOBLOCK );
+               $addEmailLink = $flags & self::TOOL_LINKS_EMAIL && $userId;
 
                $items = array();
                if ( $talkable ) {
@@ -969,6 +969,8 @@ class Linker {
                        $items[] = self::emailLink( $userId, $userText );
                }
 
+               wfRunHooks( 'UserToolLinksEdit', array( $userId, $userText, &$items ) );
+
                if ( $items ) {
                        return ' <span class="mw-usertoollinks">(' . $wgLang->pipeList( $items ) . ')</span>';
                } else {
@@ -1026,7 +1028,7 @@ class Linker {
         * @param $isPublic Boolean: show only if all users can see it
         * @return String: HTML fragment
         */
-       static function revUserLink( $rev, $isPublic = false ) {
+       public static function revUserLink( $rev, $isPublic = false ) {
                if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                } elseif ( $rev->userCan( Revision::DELETED_USER ) ) {
@@ -1047,7 +1049,7 @@ class Linker {
         * @param $isPublic Boolean: show only if all users can see it
         * @return string HTML
         */
-       static function revUserTools( $rev, $isPublic = false ) {
+       public static function revUserTools( $rev, $isPublic = false ) {
                if ( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                } elseif ( $rev->userCan( Revision::DELETED_USER ) ) {
@@ -1080,7 +1082,7 @@ class Linker {
         * @param $title Mixed: Title object (to generate link to the section in autocomment) or null
         * @param $local Boolean: whether section links should refer to local page
         */
-       static function formatComment( $comment, $title = null, $local = false ) {
+       public static function formatComment( $comment, $title = null, $local = false ) {
                wfProfileIn( __METHOD__ );
 
                # Sanitize text a bit:
@@ -1132,6 +1134,7 @@ class Linker {
         * @return string
         */
        private static function formatAutocommentsCallback( $match ) {
+               global $wgLang;
                $title = self::$autocommentTitle;
                $local = self::$autocommentLocal;
 
@@ -1157,7 +1160,7 @@ class Linker {
                        }
                        if ( $sectionTitle ) {
                                $link = self::link( $sectionTitle,
-                                       htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
+                                       $wgLang->getArrow(), array(), array(),
                                        'noclasses' );
                        } else {
                                $link = '';
@@ -1234,7 +1237,9 @@ class Linker {
                        # Media link; trail not supported.
                        $linkRegexp = '/\[\[(.*?)\]\]/';
                        $title = Title::makeTitleSafe( NS_FILE, $submatch[1] );
-                       $thelink = self::makeMediaLinkObj( $title, $text );
+                       if ( $title ) {
+                               $thelink = self::makeMediaLinkObj( $title, $text );
+                       }
                } else {
                        # Other kind of link
                        if ( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
@@ -1280,7 +1285,7 @@ class Linker {
         * @param  $text
         * @return string
         */
-       static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
+       public static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
                # Valid link forms:
                # Foobar -- normal
                # :Foobar -- override special treatment of prefix (images, language links)
@@ -1305,7 +1310,7 @@ class Linker {
                        # bug 7425
                        $target = trim( $target );
                        # Look at the first character
-                       if ( $target != '' && $target { 0 } === '/' ) {
+                       if ( $target != '' && $target[0] === '/' ) {
                                # / at end means we don't want the slash to be shown
                                $m = array();
                                $trailingSlashes = preg_match_all( '%(/+)$%', $target, $m );
@@ -1362,7 +1367,7 @@ class Linker {
         *
         * @return string
         */
-       static function commentBlock( $comment, $title = null, $local = false ) {
+       public static function commentBlock( $comment, $title = null, $local = false ) {
                // '*' used to be the comment inserted by the software way back
                // in antiquity in case none was provided, here for backwards
                // compatability, acc. to brion -ævar
@@ -1370,7 +1375,7 @@ class Linker {
                        return '';
                } else {
                        $formatted = self::formatComment( $comment, $title, $local );
-                       return " <span class=\"comment\">($formatted)</span>";
+                       return " <span class=\"comment\" dir=\"auto\">($formatted)</span>";
                }
        }
 
@@ -1383,7 +1388,7 @@ class Linker {
         * @param $isPublic Boolean: show only if all users can see it
         * @return String: HTML fragment
         */
-       static function revComment( Revision $rev, $local = false, $isPublic = false ) {
+       public static function revComment( Revision $rev, $local = false, $isPublic = false ) {
                if ( $rev->getRawComment() == "" ) {
                        return "";
                }
@@ -1422,7 +1427,7 @@ class Linker {
         *
         * @return string
         */
-       static function tocIndent() {
+       public static function tocIndent() {
                return "\n<ul>";
        }
 
@@ -1431,7 +1436,7 @@ class Linker {
         *
         * @return string
         */
-       static function tocUnindent( $level ) {
+       public static function tocUnindent( $level ) {
                return "</li>\n" . str_repeat( "</ul>\n</li>\n", $level > 0 ? $level : 0 );
        }
 
@@ -1440,7 +1445,7 @@ class Linker {
         *
         * @return string
         */
-       static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
+       public static function tocLine( $anchor, $tocline, $tocnumber, $level, $sectionIndex = false ) {
                $classes = "toclevel-$level";
                if ( $sectionIndex !== false ) {
                        $classes .= " tocsection-$sectionIndex";
@@ -1456,7 +1461,7 @@ class Linker {
         * tocUnindent() will be used instead if we're ending a line below
         * the new level.
         */
-       static function tocLineEnd() {
+       public static function tocLineEnd() {
                return "</li>\n";
        }
 
@@ -1467,7 +1472,7 @@ class Linker {
         * @param $lang mixed: Language code for the toc title
         * @return String: full html of the TOC
         */
-       static function tocList( $toc, $lang = false ) {
+       public static function tocList( $toc, $lang = false ) {
                $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
                return
                   '<table id="toc" class="toc"><tr><td>'
@@ -1561,7 +1566,7 @@ class Linker {
         *
         * @param $rev Revision object
         */
-       static function generateRollback( $rev ) {
+       public static function generateRollback( $rev ) {
                return '<span class="mw-rollback-link">['
                        . self::buildRollbackLink( $rev )
                        . ']</span>';
@@ -1579,7 +1584,7 @@ class Linker {
                $query = array(
                        'action' => 'rollback',
                        'from' => $rev->getUserText(),
-                       'token' => $wgUser->editToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
+                       'token' => $wgUser->getEditToken( array( $title->getPrefixedText(), $rev->getUserText() ) ),
                );
                if ( $wgRequest->getBool( 'bot' ) ) {
                        $query['bot'] = '1';
@@ -1659,42 +1664,6 @@ class Linker {
                return $outText;
        }
 
-       /**
-        * Returns HTML for the "templates used on this page" list.
-        *
-        * @param $templates Array of templates from Article::getUsedTemplate
-        * or similar
-        * @param $preview Boolean: whether this is for a preview
-        * @param $section Boolean: whether this is for a section edit
-        * @return String: HTML output
-        */
-       public static function formatDistantTemplates( $templates, $preview = false, $section = false ) {
-               wfProfileIn( __METHOD__ );
-
-               $outText = '';
-               if ( count( $templates ) > 0 ) {
-
-                       # Construct the HTML
-                       $outText = '<div class="mw-templatesUsedExplanation">';
-                       if ( $preview ) {
-                               $outText .= wfMsgExt( 'distanttemplatesusedpreview', array( 'parse' ), count( $templates ) );
-                       } elseif ( $section ) {
-                               $outText .= wfMsgExt( 'distanttemplatesusedsection', array( 'parse' ), count( $templates ) );
-                       } else {
-                               $outText .= wfMsgExt( 'distanttemplatesused', array( 'parse' ), count( $templates ) );
-                       }
-                       $outText .= "</div><ul>\n";
-
-                       usort( $templates, array( 'Title', 'compare' ) );
-                       foreach ( $templates as $titleObj ) {
-                               $outText .= '<li>' . self::link( $titleObj ) . '</li>';
-                       }
-                       $outText .= '</ul>';
-               }
-               wfProfileOut( __METHOD__  );
-               return $outText;
-       }
-
        /**
         * Returns HTML for the "hidden categories on this page" list.
         *
@@ -1747,10 +1716,6 @@ class Linker {
         *   escape), or false for no title attribute
         */
        public static function titleAttrib( $name, $options = null ) {
-               global $wgEnableTooltipsAndAccesskeys;
-               if ( !$wgEnableTooltipsAndAccesskeys )
-                       return false;
-
                wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "tooltip-$name" );
@@ -1857,9 +1822,8 @@ class Linker {
                                return Linker::revDeleteLink( $query,
                                        $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
                        }
-               } else {
-                       return '';
                }
+               return '';
        }
 
        /**
@@ -2041,9 +2005,6 @@ class Linker {
         * Returns the attributes for the tooltip and access key.
         */
        public static function tooltipAndAccesskeyAttribs( $name ) {
-               global $wgEnableTooltipsAndAccesskeys;
-               if ( !$wgEnableTooltipsAndAccesskeys )
-                       return array();
                # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
                # no attribute" instead of "output '' as value for attribute", this
                # would be three lines.
@@ -2065,9 +2026,6 @@ class Linker {
         * Returns raw bits of HTML, use titleAttrib()
         */
        public static function tooltip( $name, $options = null ) {
-               global $wgEnableTooltipsAndAccesskeys;
-               if ( !$wgEnableTooltipsAndAccesskeys )
-                       return '';
                # @todo FIXME: If Sanitizer::expandAttributes() treated "false" as "output
                # no attribute" instead of "output '' as value for attribute", this
                # would be two lines.