From 3635a28bc532eed83009390c8231116ca9490d8e Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 6 Sep 2005 22:16:41 +0000 Subject: [PATCH] Turn stuff from OldChangesList into methods of its parent (ChangesList). TODO: make EnhancedChangesList class use its parent methods. --- includes/ChangesList.php | 522 +++++++++++++++++++++------------------ 1 file changed, 284 insertions(+), 238 deletions(-) diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 11197b71e8..bd74a3b59b 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -17,8 +17,23 @@ class ChangesList { /** @todo document */ function ChangesList( &$skin ) { $this->skin =& $skin; + $this->preCacheMessages(); } + /** + * As we use the same small set of messages in various methods and that + * they are called often, we call them once and save them in $this->message + */ + function preCacheMessages() { + // Precache various messages + if( !isset( $this->message ) ) { + foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last blocklink' ) as $msg ) { + $this->message[$msg] = wfMsg( $msg ); + } + } + } + + /** * Returns the appropiate flags for new page, minor change and patrolling */ @@ -70,6 +85,8 @@ class ChangesList { # Spacer image $r .= '' ; + + # Flag and Timestamp $r .= '' ; if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { @@ -77,8 +94,6 @@ class ChangesList { } else { $r .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $rcObj->unpatrolled ); } - - # Timestamp $r .= ' '.$rcObj->timestamp.' ' ; # Article link @@ -110,151 +125,155 @@ class ChangesList { } /** - * Enhanced RC group + * If enhanced RC is in use, this function takes the previously cached + * RC lines, arranges them, and outputs the HTML */ - function recentChangesBlockGroup ( $block ) { - global $wgStylePath, $wgContLang ; - - $r = ''; - - # Collate list of users - $isnew = false ; - $unpatrolled = false; - $userlinks = array () ; - foreach ( $block AS $rcObj ) { - $oldid = $rcObj->mAttribs['rc_last_oldid']; - $newid = $rcObj->mAttribs['rc_this_oldid']; - if ( $rcObj->mAttribs['rc_new'] ) { - $isnew = true ; - } - $u = $rcObj->userlink ; - if ( !isset ( $userlinks[$u] ) ) { - $userlinks[$u] = 0 ; - } - if ( $rcObj->unpatrolled ) { - $unpatrolled = true; + function recentChangesBlock () { + global $wgStylePath ; + if ( count ( $this->rc_cache ) == 0 ) return '' ; + $blockOut = ''; + foreach ( $this->rc_cache AS $secureName => $block ) { + if ( count ( $block ) < 2 ) { + $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ; + } else { + $blockOut .= $this->recentChangesBlockGroup ( $block ) ; } - $userlinks[$u]++ ; } - # Sort the list and convert to text - krsort ( $userlinks ) ; - asort ( $userlinks ) ; - $users = array () ; - foreach ( $userlinks as $userlink => $count) { - $text = $userlink; - if ( $count > 1 ) $text .= ' ('.$count.'×)' ; - array_push ( $users , $text ) ; - } + return '
'.$blockOut.'
' ; + } - $users = ' ['.implode('; ',$users).']'; - # Arrow - $rci = 'RCI'.$this->rcCacheIndex ; - $rcl = 'RCL'.$this->rcCacheIndex ; - $rcm = 'RCM'.$this->rcCacheIndex ; - $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ; - $arrowdir = $wgContLang->isRTL() ? 'l' : 'r'; - $tl = '+' ; - $tl .= '' ; - $r .= $tl ; + function insertMove(&$s) { + # Diff + $s .= '(' . $this->message['diff'] . ') ('; + # Hist + $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) . + ') . . '; - # Main line - $r .= '' ; - $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled ); + # "[[x]] moved to [[y]]" + $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir'; + $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), + $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); + } - # Timestamp - $r .= ' '.$block[0]->timestamp.' ' ; - $r .= '' ; + function insertDateHeader(&$s, $rc_timestamp) { + global $wgLang; - # Article link - $link = $block[0]->link ; - if ( $block[0]->watched ) $link = ''.$link.'' ; - $r .= $link ; + # Make date header if necessary + $date = $wgLang->date( $rc_timestamp, true, true ); + $s = ''; + if ( $date != $this->lastdate ) { + if ( '' != $this->lastdate ) { $s .= "\n"; } + $s .= '

'.$date."

\n\n"; } - $s .= '

'.$date."

\n