APIEDIT BRANCH MERGE:
[lhc/web/wiklou.git] / includes / Linker.php
index 59a146b..e61578d 100644 (file)
@@ -442,7 +442,6 @@ class Linker {
         * @param boolean $thumb shows image as thumbnail in a frame
         * @param string $manualthumb image name for the manual thumbnail
         * @param string $valign vertical alignment: baseline, sub, super, top, text-top, middle, bottom, text-bottom
-        * @param string $time, timestamp (for image versioning)
         * @return string
         */
        function makeImageLinkObj( $title, $label, $alt, $align = '', $handlerParams = array(), $framed = false,
@@ -872,13 +871,10 @@ class Linker {
        /**
         * Generate a user link if the current user is allowed to view it
         * @param $rev Revision object.
-        * @param $isPublic, bool, show only if all users can see it
         * @return string HTML
         */
-       function revUserLink( $rev, $isPublic = false ) {
-               if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               } else if( $rev->userCan( Revision::DELETED_USER ) ) {
+       function revUserLink( $rev ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
@@ -888,74 +884,21 @@ class Linker {
                }
                return $link;
        }
-       
-       /**
-        * Generate a user link if the current user is allowed to view it
-        * @param $event, log row item.
-        * @param $isPublic, bool, show only if all users can see it
-        * @return string HTML
-        */
-       function logUserLink( $event, $isPublic = false ) {
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_USER ) && $isPublic ) {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               } else if( LogViewer::userCan( $event, LogViewer::DELETED_USER ) ) {
-                       if ( isset($event->user_name) ) {
-                               $link = $this->userLink( $event->log_user, $event->user_name );
-                       } else {
-                               $user = $event->log_user;
-                               $link = $this->userLink( $event->log_user, User::whoIs( $user ) );
-                       }
-               } else {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               }
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_USER ) ) {
-                       return '<span class="history-deleted">' . $link . '</span>';
-               }
-               return $link;
-       }
 
        /**
         * Generate a user tool link cluster if the current user is allowed to view it
         * @param $rev Revision object.
-        * @param $isPublic, bool, show only if all users can see it
         * @return string HTML
         */
-       function revUserTools( $rev, $isPublic = false ) {
-               if( $rev->isDeleted( Revision::DELETED_USER ) && $isPublic ) {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               } else if( $rev->userCan( Revision::DELETED_USER ) ) {
+       function revUserTools( $rev ) {
+               if( $rev->userCan( Revision::DELETED_USER ) ) {
                        $link = $this->userLink( $rev->getRawUser(), $rev->getRawUserText() ) .
-                       ' ' . $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
+                               ' ' .
+                               $this->userToolLinks( $rev->getRawUser(), $rev->getRawUserText() );
                } else {
                        $link = wfMsgHtml( 'rev-deleted-user' );
                }
                if( $rev->isDeleted( Revision::DELETED_USER ) ) {
-                       return ' <span class="history-deleted">' . $link . '</span>';
-               }
-               return " $link";
-       }
-
-       /**
-        * Generate a user tool link cluster if the current user is allowed to view it
-        * @param $event, log item.
-        * @param $isPublic, bool, show only if all users can see it
-        * @return string HTML
-        */
-       function logUserTools( $event, $isPublic = false ) {
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_USER ) && $isPublic ) {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               } else if( LogViewer::userCan( $event, LogViewer::DELETED_USER ) ) {
-                       if( isset($event->user_name) ) {
-                               $link = $this->userLink( $event->log_user, $event->user_name ) . 
-                                       $this->userToolLinksRedContribs( $event->log_user, $event->user_name );
-                       } else {
-                               $link = $this->userLink( $event->log_user, $event->user_name ) . 
-                                       $this->userToolLinksRedContribs( $event->log_user, User::whoIs($event->log_user) );
-                       }
-               } else {
-                       $link = wfMsgHtml( 'rev-deleted-user' );
-               }
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_USER ) ) {
                        return '<span class="history-deleted">' . $link . '</span>';
                }
                return $link;
@@ -1045,42 +988,49 @@ class Linker {
         * Formats wiki links and media links in text; all other wiki formatting
         * is ignored
         *
+        * @fixme doesn't handle sub-links as in image thumb texts like the main parser
         * @param string $comment Text to format links in
         * @return string
         */
        public function formatLinksInComment( $comment ) {
+               return preg_replace_callback(
+                       '/\[\[:?(.*?)(\|(.*?))*\]\]([^[]*)/',
+                       array( $this, 'formatLinksInCommentCallback' ),
+                       $comment );
+       }
+       
+       protected function formatLinksInCommentCallback( $match ) {
                global $wgContLang;
 
                $medians = '(?:' . preg_quote( Namespace::getCanonicalName( NS_MEDIA ), '/' ) . '|';
                $medians .= preg_quote( $wgContLang->getNsText( NS_MEDIA ), '/' ) . '):';
+               
+               $comment = $match[0];
 
-               $match = array();
-               while(preg_match('/\[\[:?(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
-                       # Handle link renaming [[foo|text]] will show link as "text"
-                       if( "" != $match[3] ) {
-                               $text = $match[3];
-                       } else {
-                               $text = $match[1];
-                       }
-                       $submatch = array();
-                       if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
-                               # Media link; trail not supported.
-                               $linkRegexp = '/\[\[(.*?)\]\]/';
-                               $thelink = $this->makeMediaLink( $submatch[1], "", $text );
+               # Handle link renaming [[foo|text]] will show link as "text"
+               if( "" != $match[3] ) {
+                       $text = $match[3];
+               } else {
+                       $text = $match[1];
+               }
+               $submatch = array();
+               if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
+                       # Media link; trail not supported.
+                       $linkRegexp = '/\[\[(.*?)\]\]/';
+                       $thelink = $this->makeMediaLink( $submatch[1], "", $text );
+               } else {
+                       # Other kind of link
+                       if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
+                               $trail = $submatch[1];
                        } else {
-                               # Other kind of link
-                               if( preg_match( $wgContLang->linkTrail(), $match[4], $submatch ) ) {
-                                       $trail = $submatch[1];
-                               } else {
-                                       $trail = "";
-                               }
-                               $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
-                               if (isset($match[1][0]) && $match[1][0] == ':')
-                                       $match[1] = substr($match[1], 1);
-                               $thelink = $this->makeLink( $match[1], $text, "", $trail );
+                               $trail = "";
                        }
-                       $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
+                       $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
+                       if (isset($match[1][0]) && $match[1][0] == ':')
+                               $match[1] = substr($match[1], 1);
+                       $thelink = $this->makeLink( $match[1], $text, "", $trail );
                }
+               $comment = preg_replace( $linkRegexp, StringUtils::escapeRegexReplacement( $thelink ), $comment, 1 );
 
                return $comment;
        }
@@ -1113,43 +1063,20 @@ class Linker {
         *
         * @param Revision $rev
         * @param bool $local Whether section links should refer to local page
-        * @param $isPublic, show only if all users can see it
         * @return string HTML
         */
-       function revComment( Revision $rev, $local = false, $isPublic = false ) {
-               if( $rev->isDeleted( Revision::DELETED_COMMENT ) && $isPublic ) {
-                       $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
-               } else if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
+       function revComment( Revision $rev, $local = false ) {
+               if( $rev->userCan( Revision::DELETED_COMMENT ) ) {
                        $block = $this->commentBlock( $rev->getRawComment(), $rev->getTitle(), $local );
                } else {
-                       $block = " <span class=\"comment\">" . wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
+                       $block = " <span class=\"comment\">" .
+                               wfMsgHtml( 'rev-deleted-comment' ) . "</span>";
                }
                if( $rev->isDeleted( Revision::DELETED_COMMENT ) ) {
                        return " <span class=\"history-deleted\">$block</span>";
                }
                return $block;
        }
-               
-       /**
-        * Wrap and format the given event's comment block, if the current
-        * user is allowed to view it.
-        *
-        * @param Revision $rev
-        * @return string HTML
-        */
-       function logComment( $event, $isPublic = false ) {
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_COMMENT ) && $isPublic ) {
-                       $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
-               } else if( LogViewer::userCan( $event, LogViewer::DELETED_COMMENT ) ) {
-                       $block = $this->commentBlock( LogViewer::getRawComment( $event ) );
-               } else {
-                       $block = ' ' . wfMsgHtml( 'rev-deleted-comment' );
-               }
-               if( LogViewer::isDeleted( $event, LogViewer::DELETED_COMMENT ) ) {
-                       return "<span class=\"history-deleted\">$block</span>";
-               }
-               return $block;
-       }
 
        /** @todo document */
        function tocIndent() {