apply CSS::Janus when user preview its CSS style
[lhc/web/wiklou.git] / includes / Linker.php
index 4861045..35cf756 100644 (file)
@@ -23,7 +23,7 @@ class Linker {
         * @deprecated since 1.18 Just pass the external class directly to something using Html::expandAttributes
         */
        static function getExternalLinkAttributes( $class = 'external' ) {
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.18' );
                return self::getLinkAttributesInternal( '', $class );
        }
 
@@ -135,6 +135,11 @@ class Linker {
         *      name of the target).
         * link() replaces the old functions in the makeLink() family.
         *
+        * @since 1.18 Method exists since 1.16 as non-static, made static in 1.18.
+        * You can call it using this if you want to keep compat with these:
+        * $linker = class_exists( 'DummyLinker' ) ? new DummyLinker() : new Linker();
+        * $linker->link( ... );
+        *
         * @param $target        Title  Can currently only be a Title, but this may
         *   change to support Images, literal URLs, etc.
         * @param $html          string The HTML contents of the <a> element, i.e.,
@@ -250,11 +255,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;
        }
@@ -359,7 +364,7 @@ class Linker {
         */
        static function makeSizeLinkObj( $size, $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                global $wgUser;
-               wfDeprecated( __METHOD__ );
+               wfDeprecated( __METHOD__, '1.17' );
 
                $threshold = $wgUser->getStubThreshold();
                $colour = ( $size < $threshold ) ? 'stub' : '';
@@ -389,7 +394,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;
@@ -866,7 +871,7 @@ 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
         */
@@ -888,10 +893,10 @@ class Linker {
         */
        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;
@@ -969,6 +974,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 {
@@ -1132,6 +1139,7 @@ class Linker {
         * @return string
         */
        private static function formatAutocommentsCallback( $match ) {
+               global $wgLang;
                $title = self::$autocommentTitle;
                $local = self::$autocommentLocal;
 
@@ -1157,7 +1165,7 @@ class Linker {
                        }
                        if ( $sectionTitle ) {
                                $link = self::link( $sectionTitle,
-                                       htmlspecialchars( wfMsgForContent( 'sectionlink' ) ), array(), array(),
+                                       $wgLang->getArrow(), array(), array(),
                                        'noclasses' );
                        } else {
                                $link = '';
@@ -1234,7 +1242,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 ) ) {
@@ -1305,7 +1315,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 );
@@ -1579,7 +1589,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 +1669,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 +1721,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 +1827,8 @@ class Linker {
                                return Linker::revDeleteLink( $query,
                                        $rev->isDeleted( File::DELETED_RESTRICTED ), $canHide );
                        }
-               } else {
-                       return '';
                }
+               return '';
        }
 
        /**
@@ -1909,6 +1878,8 @@ class Linker {
         *               the end of the link.
         */
        static function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
+               wfDeprecated( __METHOD__, '1.16' );
+               
                $nt = Title::newFromText( $title );
                if ( $nt instanceof Title ) {
                        return self::makeBrokenLinkObj( $nt, $text, $query, $trail );
@@ -1935,6 +1906,8 @@ class Linker {
         * @param $prefix String: optional prefix. As trail, only before instead of after.
         */
        static function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
+               # wfDeprecated( __METHOD__, '1.16' ); // See r105985 and it's revert. Somewhere still used.
+               
                wfProfileIn( __METHOD__ );
                $query = wfCgiToArray( $query );
                list( $inside, $trail ) = self::splitTrail( $trail );
@@ -1967,6 +1940,8 @@ class Linker {
        static function makeKnownLinkObj(
                $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = ''
        ) {
+               # wfDeprecated( __METHOD__, '1.16' ); // See r105985 and it's revert. Somewhere still used.
+               
                wfProfileIn( __METHOD__ );
 
                if ( $text == '' ) {
@@ -2000,6 +1975,8 @@ class Linker {
         * @param $prefix String: Optional prefix
         */
        static function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
+               wfDeprecated( __METHOD__, '1.16' );
+               
                wfProfileIn( __METHOD__ );
 
                list( $inside, $trail ) = self::splitTrail( $trail );
@@ -2029,6 +2006,8 @@ class Linker {
         * @param $prefix String: Optional prefix
         */
        static function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
+               wfDeprecated( __METHOD__, '1.16' );
+               
                if ( $colour != '' ) {
                        $style = self::getInternalLinkAttributesObj( $nt, $text, $colour );
                } else {
@@ -2041,9 +2020,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.
@@ -2061,13 +2037,9 @@ class Linker {
        }
 
        /**
-        * @deprecated since 1.14
         * 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.