API: Add ApiDisabled and ApiQueryDisabled classes so individual modules can be disabl...
[lhc/web/wiklou.git] / includes / Linker.php
index 3f8f802..529891c 100644 (file)
@@ -170,6 +170,11 @@ class Linker {
         */
        public function link( $target, $text = null, $customAttribs = array(), $query = array(), $options = array() ) {
                wfProfileIn( __METHOD__ );
+               if( !$target instanceof Title ) {
+                       return "<!-- ERROR -->$text";
+               }
+               $options = (array)$options;
+
                $ret = null;
                if( !wfRunHooks( 'LinkBegin', array( $this, $target, &$text,
                &$customAttribs, &$query, &$options, &$ret ) ) ) {
@@ -177,11 +182,6 @@ class Linker {
                        return $ret;
                }
 
-               if( !$target instanceof Title ) {
-                       throw new MWException( 'Linker::link passed invalid target' );
-               }
-               $options = (array)$options;
-
                # Normalize the Title if it's a special page
                $target = $this->normaliseSpecialPage( $target );
 
@@ -305,6 +305,11 @@ class Linker {
        }
 
        private function linkText( $target ) {
+               # We might be passed a non-Title by make*LinkObj().  Fail gracefully.
+               if( !$target instanceof Title ) {
+                       return '';
+               }
+
                # 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() !== '' ) {
@@ -426,7 +431,7 @@ class Linker {
         *                      the end of the link.
         * @param $prefix String: optional prefix. As trail, only before instead of after.
         */
-       function makeLinkObj( Title $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
+       function makeLinkObj( $nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
                global $wgUser;
                wfProfileIn( __METHOD__ );
 
@@ -458,7 +463,7 @@ class Linker {
         * @param $style  String: style to apply - if empty, use getInternalLinkAttributesObj instead
         * @return the a-element
         */
-       function makeKnownLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
+       function makeKnownLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '', $style = '' ) {
                wfProfileIn( __METHOD__ );
 
                if ( $text == '' ) {
@@ -490,7 +495,7 @@ class Linker {
         *                      be included in the link text. Other characters will be appended after
         *                      the end of the link.
         */
-       function makeBrokenLinkObj( Title $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
+       function makeBrokenLinkObj( $title, $text = '', $query = '', $trail = '', $prefix = '' ) {
                wfProfileIn( __METHOD__ );
 
                list( $inside, $trail ) = Linker::splitTrail( $trail );
@@ -1108,7 +1113,8 @@ class Linker {
                if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                } else if( $rev->userCan( Revision::DELETED_USER ) ) {
-                       $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
+                       $link = $this->userLink( $rev->getUser( Revision::FOR_THIS_USER ), 
+                               $rev->getUserText( Revision::FOR_THIS_USER ) );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
@@ -1128,8 +1134,10 @@ class Linker {
                if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                } else if( $rev->userCan( Revision::DELETED_USER ) ) {
-                       $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
-                       ' ' . $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
+                       $userId = $rev->getUser( Revision::FOR_THIS_USER );
+                       $userText = $rev->getUserText( Revision::FOR_THIS_USER ); 
+                       $link = $this->userLink( $userId, $userText ) .
+                               ' ' . $this->userToolLinks( $userId, $userText );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
@@ -1219,13 +1227,10 @@ class Linker {
                        if ( $local ) {
                                $sectionTitle = Title::newFromText( '#' . $section );
                        } else {
-                               $sectionTitle = clone( $title );
-                               $sectionTitle->mFragment = $section;
+                               $sectionTitle = Title::makeTitleSafe( $title->getNamespace(), 
+                                       $title->getDBkey(), $section );
                        }
-                       # FIXME: $sectionTitle should probably always be valid at this
-                       # point, but in some scenarios it's not (bug 15351).  Is this cor-
-                       # rect?
-                       if( $title instanceof Title ) {
+                       if ( $sectionTitle ) {
                                $link = $this->link( $sectionTitle,
                                        wfMsgForContent( 'sectionlink' ), array(), array(),
                                        'noclasses' );
@@ -1338,7 +1343,8 @@ class Linker {
                if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
                        $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
-                       $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
+                       $block = $this->commentBlock( $rev->getComment( Revision::FOR_THIS_USER ),
+                               $rev->getTitle(), $local );
                } else {
                        $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                }
@@ -1450,7 +1456,7 @@ class Linker {
                if( !is_null( $tooltip ) ) {
                        $attribs['title'] = wfMsg( 'editsectionhint', $tooltip );
                }
-               $url = $this->link( $nt, wfMsg('editsection'),
+               $link = $this->link( $nt, wfMsg('editsection'),
                        $attribs,
                        array( 'action' => 'edit', 'section' => $section ),
                        array( 'noclasses', 'known' )
@@ -1464,19 +1470,19 @@ class Linker {
                        $attribs = " title=\"$attribs\"";
                }
                $result = null;
-               wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $url, &$result ) );
+               wfRunHooks( 'EditSectionLink', array( &$this, $nt, $section, $attribs, $link, &$result ) );
                if( !is_null( $result ) ) {
                        # For reverse compatibility, add the brackets *after* the hook is
                        # run, and even add them to hook-provided text.  (This is the main
                        # reason that the EditSectionLink hook is deprecated in favor of
                        # DoEditSectionLink: it can't change the brackets or the span.)
-                       $result = wfMsgHtml( 'editsection-brackets', $url );
+                       $result = wfMsgHtml( 'editsection-brackets', $result );
                        return "<span class=\"editsection\">$result</span>";
                }
 
                # Add the brackets and the span, and *then* run the nice new hook, with
                # clean and non-redundant arguments.
-               $result = wfMsgHtml( 'editsection-brackets', $url );
+               $result = wfMsgHtml( 'editsection-brackets', $link );
                $result = "<span class=\"editsection\">$result</span>";
 
                wfRunHooks( 'DoEditSectionLink', array( $this, $nt, $section, $tooltip, &$result ) );