* replace use of deprecated makeLinkObj() by link() in core
[lhc/web/wiklou.git] / includes / ChangesList.php
index 1c6f4bd..d14726b 100644 (file)
@@ -25,6 +25,7 @@ class RCCacheEntry extends RecentChange {
 class ChangesList {
        # Called by history lists and recent changes
        public $skin;
+       protected $watchlist = false;
 
        /**
        * Changeslist contructor
@@ -52,6 +53,14 @@ class ChangesList {
                        return $list;
                }
        }
+       
+       /**
+        * Sets the list to use a <li class="watchlist-(namespace)-(page)"> tag
+        * @param bool $value
+        */
+       public function setWatchlistDivs( $value = true ) {
+               $this->watchlist = $value;
+       }
 
        /**
         * As we use the same small set of messages in various methods and that
@@ -106,9 +115,21 @@ class ChangesList {
         * @returns string
         */
        public static function showCharacterDifference( $old, $new ) {
-               global $wgRCChangedSizeThreshold, $wgLang;
+               global $wgRCChangedSizeThreshold, $wgLang, $wgMiserMode;
                $szdiff = $new - $old;
-               $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $wgLang->formatNum( $szdiff ) );
+
+               $code = $wgLang->getCode();
+               static $fastCharDiff = array();
+               if ( !isset($fastCharDiff[$code]) ) {
+                       $fastCharDiff[$code] = $wgMiserMode || wfMsgNoTrans( 'rc-change-size' ) === '$1';
+               }
+                       
+               $formatedSize = $wgLang->formatNum($szdiff);
+
+               if ( !$fastCharDiff[$code] ) {
+                       $formatedSize = wfMsgExt( 'rc-change-size', array( 'parsemag', 'escape' ), $formatedSize );
+               }
+                       
                if( abs( $szdiff ) > abs( $wgRCChangedSizeThreshold ) ) {
                        $tag = 'strong';
                } else {
@@ -155,7 +176,7 @@ class ChangesList {
                        if( '' != $this->lastdate ) {
                                $s .= "</ul>\n";
                        }
-                       $s .= '<h4>'.$date."</h4>\n<ul class=\"special\">";
+                       $s .= Xml::element( 'h4', null, $date ) . "\n<ul class=\"special\">";
                        $this->lastdate = $date;
                        $this->rclistOpen = true;
                }
@@ -322,21 +343,22 @@ class ChangesList {
        /** Inserts a rollback link */
        protected function insertRollback( &$s, &$rc ) {
                global $wgUser;
-               if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $wgUser->isAllowed('rollback') ) {
+               if( !$rc->mAttribs['rc_new'] && $rc->mAttribs['rc_this_oldid'] && $rc->mAttribs['rc_cur_id'] ) {
                        $page = $rc->getTitle();
                        /** Check for rollback and edit permissions, disallow special pages, and only
                          * show a link on the top-most revision */
-                       if( $rc->mAttribs['rc_cur_id'] && $page->getLatestRevID() == $rc->mAttribs['rc_this_oldid'] 
-                               && $page->quickUserCan('rollback') && $page->quickUserCan('edit') )
+                       if ($wgUser->isAllowed('rollback') && $rc->mAttribs['page_latest'] == $rc->mAttribs['rc_this_oldid'] )
                        {
                                $rev = new Revision( array(
                                        'id'        => $rc->mAttribs['rc_this_oldid'],
                                        'user'      => $rc->mAttribs['rc_user'],
-                                       'user_text' => $rc->mAttribs['rc_user_text']
+                                       'user_text' => $rc->mAttribs['rc_user_text'],
+                                       'deleted'   => $rc->mAttribs['rc_deleted']
                                ) );
+                               $rev->setTitle( $page );
                                $s .= ' '.$this->skin->generateRollback( $rev );
                        }
-               }       
+               }
        }
 
        protected function insertTags( &$s, &$rc, &$classes ) {
@@ -361,8 +383,8 @@ class OldChangesList extends ChangesList {
        /**
         * Format a line using the old system (aka without any javascript).
         */
-       public function recentChangesLine( &$rc, $watched = false ) {
-               global $wgContLang, $wgLang, $wgRCShowChangedSize, $wgUser;
+       public function recentChangesLine( &$rc, $watched = false, $linenumber = NULL ) {
+               global $wgLang, $wgRCShowChangedSize, $wgUser;
                wfProfileIn( __METHOD__ );
                # Should patrol-related stuff be shown?
                $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
@@ -372,6 +394,16 @@ class OldChangesList extends ChangesList {
 
                $s = '';
                $classes = array();
+               // use mw-line-even/mw-line-odd class only if linenumber is given (feature from bug 14468)
+               if( $linenumber ) {
+                       if( $linenumber & 1 ) {
+                               $classes[] = 'mw-line-odd';
+                       }
+                       else {
+                               $classes[] = 'mw-line-even';
+                       }
+               }
+
                // Moved pages
                if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
                        $this->insertMove( $s, $rc );
@@ -415,20 +447,20 @@ class OldChangesList extends ChangesList {
                # For subclasses
                $this->insertExtra( $s, $rc, $classes );
                
-               # Mark revision as deleted if so
-               if( !$rc->mAttribs['rc_log_type'] && $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
-                  $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
-               }
                # How many users watch this page
                if( $rc->numberofWatchingusers > 0 ) {
                        $s .= ' ' . wfMsgExt( 'number_of_watching_users_RCview', 
                                array( 'parsemag', 'escape' ), $wgLang->formatNum( $rc->numberofWatchingusers ) );
                }
-
+               
+               if( $this->watchlist ) {
+                       $classes[] = Sanitizer::escapeClass( 'watchlist-'.$rc->mAttribs['rc_namespace'].'-'.$rc->mAttribs['rc_title'] );
+               }
+               
                wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
 
                wfProfileOut( __METHOD__ );
-               return "$dateheader<li class=\"".implode( ' ', $classes )."\">$s</li>\n";
+               return "$dateheader<li class=\"".implode( ' ', $classes )."\">".$s."</li>\n";
        }
 }
 
@@ -457,7 +489,9 @@ class EnhancedChangesList extends ChangesList {
         * Format a line for enhanced recentchange (aka with javascript and block of lines).
         */
        public function recentChangesLine( &$baseRC, $watched = false ) {
-               global $wgLang, $wgContLang, $wgUser;
+               global $wgLang, $wgUser;
+               
+               wfProfileIn( __METHOD__ );
 
                # Create a specialised object
                $rc = RCCacheEntry::newFromParent( $baseRC );
@@ -466,7 +500,7 @@ class EnhancedChangesList extends ChangesList {
                // FIXME: Would be good to replace this extract() call with something
                // that explicitly initializes variables.
                extract( $rc->mAttribs );
-               $curIdEq = 'curid=' . $rc_cur_id;
+               $curIdEq = array( 'curid' => $rc_cur_id );
 
                # If it's a new day, add the headline and flush the cache
                $date = $wgLang->date( $rc_timestamp, true );
@@ -475,7 +509,7 @@ class EnhancedChangesList extends ChangesList {
                        # Process current cache
                        $ret = $this->recentChangesBlock();
                        $this->rc_cache = array();
-                       $ret .= "<h4>{$date}</h4>\n";
+                       $ret .= Xml::element( 'h4', null, $date );
                        $this->lastdate = $date;
                }
 
@@ -491,19 +525,21 @@ class EnhancedChangesList extends ChangesList {
                // Page moves
                if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
-                       $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
-                         $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
+                       $clink = wfMsg( $msg, $this->skin->linkKnown( $rc->getTitle(), null,
+                               array(), array( 'redirect' => 'no' ) ),
+                               $this->skin->linkKnown( $rc->getMovedToTitle() ) );
                // New unpatrolled pages
                } else if( $rc->unpatrolled && $rc_type == RC_NEW ) {
-                       $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
+                       $clink = $this->skin->linkKnown( $rc->getTitle(), null, array(),
+                               array( 'rcid' => $rc_id ) );
                // Log entries
                } else if( $rc_type == RC_LOG ) {
                        if( $rc_log_type ) {
                                $logtitle = SpecialPage::getTitleFor( 'Log', $rc_log_type );
-                               $clink = '(' . $this->skin->makeKnownLinkObj( $logtitle, 
+                               $clink = '(' . $this->skin->linkKnown( $logtitle, 
                                        LogPage::logName($rc_log_type) ) . ')';
                        } else {
-                               $clink = $this->skin->makeLinkObj( $rc->getTitle(), '' );
+                               $clink = $this->skin->link( $rc->getTitle() );
                        }
                        $watched = false;
                // Log entries (old format) and special pages
@@ -512,14 +548,14 @@ class EnhancedChangesList extends ChangesList {
                        if ( $specialName == 'Log' ) {
                                # Log updates, etc
                                $logname = LogPage::logName( $logtype );
-                               $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
+                               $clink = '(' . $this->skin->linkKnown( $rc->getTitle(), $logname ) . ')';
                        } else {
                                wfDebug( "Unexpected special page in recentchanges\n" );
                                $clink = '';
                        }
                // Edits
                } else {
-                       $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '' );
+                       $clink = $this->skin->linkKnown( $rc->getTitle() );
                }
 
                # Don't show unusable diff links
@@ -527,34 +563,39 @@ class EnhancedChangesList extends ChangesList {
                        $showdifflinks = false;
                }
 
-               $time = $wgContLang->time( $rc_timestamp, true, true );
+               $time = $wgLang->time( $rc_timestamp, true, true );
                $rc->watched = $watched;
                $rc->link = $clink;
                $rc->timestamp = $time;
                $rc->numberofWatchingusers = $baseRC->numberofWatchingusers;
 
-               # Make "cur" and "diff" links
+               # Make "cur" and "diff" links.  Don't use link(), it's too slow if
+               # called too many times (50% of CPU time on RecentChanges!).
                if( $rc->unpatrolled ) {
-                       $rcIdQuery = "&rcid={$rc_id}";
+                       $rcIdQuery = array( 'rcid' => $rc_id );
                } else {
-                       $rcIdQuery = '';
+                       $rcIdQuery = array();
                }
-               $querycur = $curIdEq."&diff=0&oldid=$rc_this_oldid";
-               $querydiff = $curIdEq."&diff=$rc_this_oldid&oldid=$rc_last_oldid$rcIdQuery";
-               $aprops = ' tabindex="'.$baseRC->counter.'"';
-               $curLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), 
-                       $this->message['cur'], $querycur, '' ,'', $aprops );
+               $querycur = $curIdEq + array( 'diff' => '0', 'oldid' => $rc_this_oldid );
+               $querydiff = $curIdEq + array( 'diff' => $rc_this_oldid, 'oldid' =>
+                       $rc_last_oldid ) + $rcIdQuery;
 
-               # Make "diff" an "cur" links
                if( !$showdifflinks ) {
-                  $curLink = $this->message['cur'];
-                  $diffLink = $this->message['diff'];
+                       $curLink = $this->message['cur'];
+                       $diffLink = $this->message['diff'];
                } else if( in_array( $rc_type, array(RC_NEW,RC_LOG,RC_MOVE,RC_MOVE_OVER_REDIRECT) ) ) {
-                       $curLink = ($rc_type != RC_NEW) ? $this->message['cur'] : $curLink;
+                       if ( $rc_type != RC_NEW ) {
+                               $curLink = $this->message['cur'];
+                       } else {
+                               $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
+                               $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
+                       }
                        $diffLink = $this->message['diff'];
                } else {
-                       $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'], 
-                               $querydiff, '' ,'', $aprops );
+                       $diffUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querydiff ) );
+                       $curUrl = htmlspecialchars( $rc->getTitle()->getLinkUrl( $querycur ) );
+                       $diffLink = "<a href=\"$diffUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['diff']}</a>";
+                       $curLink = "<a href=\"$curUrl\" tabindex=\"{$baseRC->counter}\">{$this->message['cur']}</a>";
                }
 
                # Make "last" link
@@ -563,8 +604,8 @@ class EnhancedChangesList extends ChangesList {
                } else if( $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
                        $lastLink = $this->message['last'];
                } else {
-                       $lastLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['last'],
-                       $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
+                       $lastLink = $this->skin->linkKnown( $rc->getTitle(), $this->message['last'],
+                               array(), $curIdEq + array('diff' => $rc_this_oldid, 'oldid' => $rc_last_oldid) + $rcIdQuery );
                }
 
                # Make user links
@@ -594,8 +635,12 @@ class EnhancedChangesList extends ChangesList {
                        if( !isset( $this->rc_cache[$secureName] ) ) {
                                $this->rc_cache[$secureName] = array();
                        }
+
                        array_push( $this->rc_cache[$secureName], $rc );
                }
+
+               wfProfileOut( __METHOD__ );
+
                return $ret;
        }
 
@@ -604,6 +649,9 @@ class EnhancedChangesList extends ChangesList {
         */
        protected function recentChangesBlockGroup( $block ) {
                global $wgLang, $wgContLang, $wgRCShowChangedSize;
+
+               wfProfileIn( __METHOD__ );
+
                $r = '<table cellpadding="0" cellspacing="0" border="0" style="background: none"><tr>';
 
                # Collate list of users
@@ -759,6 +807,8 @@ class EnhancedChangesList extends ChangesList {
                        # Extract fields from DB into the function scope (rc_xxxx variables)
                        // FIXME: Would be good to replace this extract() call with something
                        // that explicitly initializes variables.
+                       # Classes to apply -- TODO implement
+                       $classes = array();
                        extract( $rcObj->mAttribs );
 
                        #$r .= '<tr><td valign="top">'.$this->spacerArrow();
@@ -809,16 +859,17 @@ class EnhancedChangesList extends ChangesList {
                        $this->insertComment( $r, $rcObj );
                        # Rollback
                        $this->insertRollback( $r, $rcObj );
-                       # Mark revision as deleted
-                       if( !$rc_log_type && $this->isDeleted($rcObj,Revision::DELETED_TEXT) ) {
-                               $r .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
-                       }
+                       # Tags
+                       $this->insertTags( $r, $rcObj, $classes );
 
                        $r .= "</td></tr>\n";
                }
                $r .= "</table></div>\n";
 
                $this->rcCacheIndex++;
+
+               wfProfileOut( __METHOD__ );
+
                return $r;
        }
 
@@ -878,10 +929,14 @@ class EnhancedChangesList extends ChangesList {
         * @return string a HTML formated line (generated using $r)
         */
        protected function recentChangesBlockLine( $rcObj ) {
-               global $wgContLang, $wgRCShowChangedSize;
+               global $wgRCShowChangedSize;
+
+               wfProfileIn( __METHOD__ );
+
                # Extract fields from DB into the function scope (rc_xxxx variables)
                // FIXME: Would be good to replace this extract() call with something
                // that explicitly initializes variables.
+               $classes = array(); // TODO implement
                extract( $rcObj->mAttribs );
                $curIdEq = "curid={$rc_cur_id}";
 
@@ -926,10 +981,15 @@ class EnhancedChangesList extends ChangesList {
                }
                $this->insertComment( $r, $rcObj );
                $this->insertRollback( $r, $rcObj );
+               # Tags
+               $this->insertTags( $r, $rcObj, $classes );
                # Show how many people are watching this if enabled
                $r .= $this->numberofWatchingusers($rcObj->numberofWatchingusers);
 
                $r .= "</td></tr></table>\n";
+
+               wfProfileOut( __METHOD__ );
+
                return $r;
        }
 
@@ -941,6 +1001,9 @@ class EnhancedChangesList extends ChangesList {
                if( count ( $this->rc_cache ) == 0 ) {
                        return '';
                }
+
+               wfProfileIn( __METHOD__ );
+
                $blockOut = '';
                foreach( $this->rc_cache as $block ) {
                        if( count( $block ) < 2 ) {
@@ -949,6 +1012,9 @@ class EnhancedChangesList extends ChangesList {
                                $blockOut .= $this->recentChangesBlockGroup( $block );
                        }
                }
+
+               wfProfileOut( __METHOD__ );
+
                return '<div>'.$blockOut.'</div>';
        }