Last few svn property fixes
[lhc/web/wiklou.git] / includes / Linker.php
index 30a4b00..32f1a57 100644 (file)
@@ -23,8 +23,10 @@ class Linker {
         *
         * @param $class String: the contents of the class attribute; if an empty
         *   string is passed, which is the default value, defaults to 'external'.
+        * @deprecated Just pass the external class directly to something using Html::expandAttributes
         */
        function getExternalLinkAttributes( $class = 'external' ) {
+               wfDeprecated( __METHOD__ );
                return $this->getLinkAttributesInternal( '', $class );
        }
 
@@ -69,7 +71,7 @@ class Linker {
         * Get the appropriate HTML attributes to add to the "a" element of an in-
         * ternal link, given the Title object for the page we want to link to.
         *
-        * @param $nt The Title object
+        * @param $nt Title
         * @param $unused String: unused
         * @param $class String: the contents of the class attribute, default none
         * @param $title Mixed: optional (unescaped) string to use in the title
@@ -223,12 +225,14 @@ class Linker {
 
        /**
         * Returns the Url used to link to a Title
+        *
+        * @param $target Title
         */
        private function linkUrl( $target, $query, $options ) {
                wfProfileIn( __METHOD__ );
                # We don't want to include fragments for broken links, because they
                # generally make no sense.
-               if ( in_array( 'broken', $options ) and $target->mFragment !== '' ) {
+               if ( in_array( 'broken', $options ) && $target->mFragment !== '' ) {
                        $target = clone $target;
                        $target->mFragment = '';
                }
@@ -236,8 +240,8 @@ class Linker {
                # If it's a broken link, add the appropriate query pieces, unless
                # there's already an action specified, or unless 'edit' makes no sense
                # (i.e., for a nonexistent special page).
-               if ( in_array( 'broken', $options ) and empty( $query['action'] )
-               and $target->getNamespace() != NS_SPECIAL ) {
+               if ( in_array( 'broken', $options ) && empty( $query['action'] )
+                       && $target->getNamespace() != NS_SPECIAL ) {
                        $query['action'] = 'edit';
                        $query['redlink'] = '1';
                }
@@ -248,6 +252,8 @@ class Linker {
 
        /**
         * Returns the array of attributes used when linking to the Title $target
+        *
+        * @param $target Title
         */
        private function linkAttribs( $target, $attribs, $options, $linkText ) {
                wfProfileIn( __METHOD__ );
@@ -307,6 +313,8 @@ class Linker {
 
        /**
         * Default text of the links to the Title $target
+        *
+        * @param $target Title
         */
        private function linkText( $target ) {
                # We might be passed a non-Title by make*LinkObj().  Fail gracefully.
@@ -316,7 +324,7 @@ class Linker {
 
                # If the target is just a fragment, with no title, we return the frag-
                # ment text.  Otherwise, we return the title text itself.
-               if ( $target->getPrefixedText() === '' and $target->getFragment() !== '' ) {
+               if ( $target->getPrefixedText() === '' && $target->getFragment() !== '' ) {
                        return htmlspecialchars( $target->getFragment() );
                }
                return htmlspecialchars( $target->getPrefixedText() );
@@ -349,6 +357,8 @@ class Linker {
         * Make appropriate markup for a link to the current article. This is currently rendered
         * as the bold link text. The calling sequence is the same as the other make*LinkObj functions,
         * despite $query not being used.
+        *
+        * @param $nt Title
         */
        function makeSelfLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                if ( $text == '' ) {
@@ -442,7 +452,7 @@ class Linker {
        function makeImageLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "", $widthOption = null ) {
                $res = null;
                if ( !wfRunHooks( 'ImageBeforeProduceHTML', array( &$this, &$title,
-               &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
+                       &$file, &$frameParams, &$handlerParams, &$time, &$res ) ) ) {
                        return $res;
                }
 
@@ -457,9 +467,15 @@ class Linker {
 
                // Clean up parameters
                $page = isset( $hp['page'] ) ? $hp['page'] : false;
-               if ( !isset( $fp['align'] ) ) $fp['align'] = '';
-               if ( !isset( $fp['alt'] ) ) $fp['alt'] = '';
-               if ( !isset( $fp['title'] ) ) $fp['title'] = '';
+               if ( !isset( $fp['align'] ) ) {
+                       $fp['align'] = '';
+               }
+               if ( !isset( $fp['alt'] ) ) {
+                       $fp['alt'] = '';
+               }
+               if ( !isset( $fp['title'] ) ) {
+                       $fp['title'] = '';
+               }
 
                $prefix = $postfix = '';
 
@@ -585,11 +601,24 @@ class Linker {
                        'caption' => $label,
                        'align' => $align
                );
-               if ( $framed ) $frameParams['framed'] = true;
-               if ( $manualthumb ) $frameParams['manualthumb'] = $manualthumb;
+               if ( $framed ) {
+                       $frameParams['framed'] = true;
+               }
+               if ( $manualthumb ) {
+                       $frameParams['manualthumb'] = $manualthumb;
+               }
                return $this->makeThumbLink2( $title, $file, $frameParams, $params );
        }
 
+       /**
+        * @param $title Title
+        * @param  $file File
+        * @param array $frameParams
+        * @param array $handlerParams
+        * @param bool $time
+        * @param string $query
+        * @return mixed
+        */
        function makeThumbLink2( Title $title, $file, $frameParams = array(), $handlerParams = array(), $time = false, $query = "" ) {
                global $wgStylePath;
                $exists = $file && $file->exists();
@@ -684,10 +713,10 @@ class Linker {
         * Make a "broken" link to an image
         *
         * @param $title Title object
-        * @param $text String: link label
+        * @param $text String: link label in unescaped text form
         * @param $query String: query string
-        * @param $trail String: link trail
-        * @param $prefix String: link prefix
+        * @param $trail String: link trail (HTML fragment)
+        * @param $prefix String: link prefix (HTML fragment)
         * @param $time Boolean: a file of a certain timestamp was requested
         * @return String
         */
@@ -714,12 +743,13 @@ class Linker {
                                wfProfileOut( __METHOD__ );
                                return '<a href="' . htmlspecialchars( $href ) . '" class="new" title="' .
                                        htmlspecialchars( $title->getPrefixedText(), ENT_QUOTES ) . '">' .
-                                       htmlspecialchars( $prefix . $text . $inside, ENT_NOQUOTES ) . '</a>' . $trail;
+                                       "$prefix$text$inside</a>$trail";
                        } else {
                                wfProfileOut( __METHOD__ );
                                return $this->linkKnown( $title, "$prefix$text$inside", array(), $query ) . $trail;
                        }
                } else {
+                       wfProfileOut( __METHOD__ );
                        return "<!-- ERROR -->{$prefix}{$text}{$trail}";
                }
        }
@@ -795,25 +825,17 @@ class Linker {
         * @param $escape Boolean: do we escape the link text?
         * @param $linktype String: type of external link. Gets added to the classes
         * @param $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() ) {
-               if ( isset( $attribs['class'] ) ) {
-                       # yet another hack :(
-                       $class = $attribs['class'];
-               } else {
-                       $class =  "external $linktype";
+               $class = "external";
+               if ( isset($linktype) && $linktype ) {
+                       $class .= " $linktype";
                }
-
-               $attribsText = $this->getExternalLinkAttributes( $class );
-               $url = htmlspecialchars( $url );
+               if ( isset($attribs['class']) && $attribs['class'] ) {
+                       $class .= " {$attribs['class']}";
+               }
+               $attribs['class'] = $class;
+               
                if ( $escape ) {
                        $text = htmlspecialchars( $text );
                }
@@ -823,10 +845,8 @@ class Linker {
                        wfDebug( "Hook LinkerMakeExternalLink changed the output of link with url {$url} and text {$text} to {$link}\n", true );
                        return $link;
                }
-               if ( $attribs ) {
-                       $attribsText .= Html::expandAttributes( $attribs );
-               }
-               return '<a href="' . $url . '"' . $attribsText . '>' . $text . '</a>';
+               $attribs['href'] = $url;
+               return Html::rawElement( 'a', $attribs, $text );
        }
 
        /**
@@ -1158,6 +1178,13 @@ class Linker {
                return $comment;
        }
 
+       /**
+        * @static
+        * @param $contextTitle Title
+        * @param  $target
+        * @param  $text
+        * @return string
+        */
        static function normalizeSubpageLink( $contextTitle, $target, &$text ) {
                # Valid link forms:
                # Foobar -- normal
@@ -1262,7 +1289,9 @@ class Linker {
         * @return String: HTML fragment
         */
        function revComment( Revision $rev, $local = false, $isPublic = false ) {
-               if ( $rev->getRawComment() == "" ) return "";
+               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 ) ) {
@@ -1329,10 +1358,11 @@ class Linker {
         * Wraps the TOC in a table and provides the hide/collapse javascript.
         *
         * @param $toc String: html of the Table Of Contents
+        * @param $lang mixed: Language code for the toc title
         * @return String: full html of the TOC
         */
-       function tocList( $toc ) {
-               $title = wfMsgHtml( 'toc' ) ;
+       function tocList( $toc, $lang = false ) {
+               $title = wfMsgExt( 'toc', array( 'language' => $lang, 'escape' ) );
                return
                   '<table id="toc" class="toc"><tr><td>'
                 . '<div id="toctitle"><h2>' . $title . "</h2></div>\n"
@@ -1675,11 +1705,10 @@ class Linker {
         *   escape), or false for no accesskey attribute
         */
        public function accesskey( $name ) {
-               wfProfileIn( __METHOD__ );
-
                if ( isset( $this->accesskeycache[$name] ) ) {
                        return $this->accesskeycache[$name];
                }
+               wfProfileIn( __METHOD__ );
 
                $message = wfMessage( "accesskey-$name" );
 
@@ -1849,7 +1878,6 @@ class Linker {
         */
        function makeLinkObj( $nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
                wfProfileIn( __METHOD__ );
-
                $query = wfCgiToArray( $query );
                list( $inside, $trail ) = Linker::splitTrail( $trail );
                if ( $text === '' ) {
@@ -1960,7 +1988,9 @@ class Linker {
        function makeColouredLinkObj( $nt, $colour, $text = '', $query = '', $trail = '', $prefix = '' ) {
                if ( $colour != '' ) {
                        $style = $this->getInternalLinkAttributesObj( $nt, $text, $colour );
-               } else $style = '';
+               } else {
+                       $style = '';
+               }
                return $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix, '', $style );
        }
 
@@ -1987,8 +2017,7 @@ class Linker {
         * @return String
         */
        function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
-         $thumb = false, $manualthumb = '', $valign = '', $time = false )
-       {
+         $thumb = false, $manualthumb = '', $valign = '', $time = false ) {
                $frameParams = array( 'alt' => $alt, 'caption' => $label );
                if ( $align ) {
                        $frameParams['align'] = $align;