X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FChangesList.php;h=507e88fab58c5b68443e97edb339364436ba2a03;hb=bb8cd7e72ead26ab34eed7e35beeb7ed3502e8f6;hp=84aadb3e933388ad6c887d819a0a7cd9f75d47c8;hpb=75521b25624b92ad48b46d734a097f6a66283a8f;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 84aadb3e93..507e88fab5 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -1,15 +1,7 @@ mAttribs = $rc->mAttribs; $rc2->mExtra = $rc->mExtra; @@ -27,24 +18,35 @@ class RCCacheEntry extends RecentChange } ; /** - * @package MediaWiki + * Class to show various lists of changes: + * - what links here + * - related changes + * - recent changes */ class ChangesList { # Called by history lists and recent changes # /** @todo document */ - function ChangesList( &$skin ) { + function __construct( &$skin ) { $this->skin =& $skin; $this->preCacheMessages(); } - function newFromUser( &$user ) { - $sk =& $user->getSkin(); - if( $user->getOption('usenewrc') ) { - return new EnhancedChangesList( $sk ); + /** + * Fetch an appropriate changes list class for the specified user + * Some users might want to use an enhanced list format, for instance + * + * @param $user User to fetch the list class for + * @return ChangesList derivative + */ + public static function newFromUser( &$user ) { + $sk = $user->getSkin(); + $list = NULL; + if( wfRunHooks( 'FetchChangesList', array( &$user, &$sk, &$list ) ) ) { + return $user->getOption( 'usenewrc' ) ? new EnhancedChangesList( $sk ) : new OldChangesList( $sk ); } else { - return new OldChangesList( $sk ); + return $list; } } @@ -56,7 +58,7 @@ class ChangesList { // Precache various messages if( !isset( $this->message ) ) { foreach( explode(' ', 'cur diff hist minoreditletter newpageletter last '. - 'blocklink changes history boteditletter' ) as $msg ) { + 'blocklink history boteditletter semicolon-separator' ) as $msg ) { $this->message[$msg] = wfMsgExt( $msg, array( 'escape') ); } } @@ -169,17 +171,21 @@ class ChangesList { ? 'rcid='.$rc->mAttribs['rc_id'] : ''; $articlelink = ' '. $this->skin->makeKnownLinkObj( $rc->getTitle(), '', $params ); - if($watched) $articlelink = ''.$articlelink.''; + if( $watched ) + $articlelink = "{$articlelink}"; global $wgContLang; $articlelink .= $wgContLang->getDirMark(); + wfRunHooks('ChangesListInsertArticleLink', + array(&$this, &$articlelink, &$s, &$rc, $unpatrolled, $watched)); + $s .= ' '.$articlelink; } - function insertTimestamp(&$s, &$rc) { + function insertTimestamp(&$s, $rc) { global $wgLang; # Timestamp - $s .= '; ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; + $s .= $this->message['semicolon-separator'] . ' ' . $wgLang->time( $rc->mAttribs['rc_timestamp'], true, true ) . ' . . '; } /** Insert links to user page, user talk page and eventually a blocking link */ @@ -202,10 +208,25 @@ class ChangesList { */ function usePatrol() { global $wgUseRCPatrol, $wgUser; - return( $wgUseRCPatrol && $wgUser->isAllowed( 'patrol' ) ); + return( $wgUseRCPatrol && ($wgUser->isAllowed('patrol') || $wgUser->isAllowed('patrolmarks')) ); } - + /** + * Returns the string which indicates the number of watching users + */ + function numberofWatchingusers( $count ) { + global $wgLang; + static $cache = array(); + if ( $count > 0 ) { + if ( !isset( $cache[$count] ) ) { + $cache[$count] = wfMsgExt('number_of_watching_users_RCview', + array('parsemag', 'escape'), $wgLang->formatNum($count)); + } + return $cache[$count]; + } else { + return ''; + } + } } @@ -217,15 +238,14 @@ class OldChangesList extends ChangesList { * Format a line using the old system (aka without any javascript). */ function recentChangesLine( &$rc, $watched = false ) { - global $wgContLang; + global $wgContLang, $wgRCShowChangedSize; $fname = 'ChangesList::recentChangesLineOld'; wfProfileIn( $fname ); - # Extract DB fields into local scope + // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables. extract( $rc->mAttribs ); - $curIdEq = 'curid=' . $rc_cur_id; # Should patrol-related stuff be shown? $unpatrolled = $this->usePatrol() && $rc_patrolled == 0; @@ -238,8 +258,13 @@ class OldChangesList extends ChangesList { if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) { $this->insertMove( $s, $rc ); // log entries - } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) { - $this->insertLog($s, $rc->getTitle(), $matches[1]); + } elseif ( $rc_namespace == NS_SPECIAL ) { + list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); + if ( $specialName == 'Log' ) { + $this->insertLog( $s, $rc->getTitle(), $specialSubpage ); + } else { + wfDebug( "Unexpected special page in recentchanges\n" ); + } // all other stuff } else { wfProfileIn($fname.'-page'); @@ -256,12 +281,15 @@ class OldChangesList extends ChangesList { wfProfileIn( $fname.'-rest' ); $this->insertTimestamp($s,$rc); + + if( $wgRCShowChangedSize ) { + $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' ); + } + $this->insertUserRelatedLinks($s,$rc); $this->insertComment($s, $rc); - if($rc->numberofWatchingusers > 0) { - $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers)); - } + $s .= rtrim(' ' . $this->numberofWatchingusers($rc->numberofWatchingusers)); $s .= "\n"; @@ -287,6 +315,7 @@ class EnhancedChangesList extends ChangesList { $rc = RCCacheEntry::newFromParent( $baseRC ); # 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 local variables. extract( $rc->mAttribs ); $curIdEq = 'curid=' . $rc_cur_id; @@ -313,11 +342,16 @@ class EnhancedChangesList extends ChangesList { $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir"; $clink = wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ), $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) ); - } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) { - # Log updates, etc - $logtype = $matches[1]; - $logname = LogPage::logName( $logtype ); - $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')'; + } elseif( $rc_namespace == NS_SPECIAL ) { + list( $specialName, $logtype ) = SpecialPage::resolveAliasWithSubpage( $rc_title ); + if ( $specialName == 'Log' ) { + # Log updates, etc + $logname = LogPage::logName( $logtype ); + $clink = '(' . $this->skin->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')'; + } else { + wfDebug( "Unexpected special page in recentchanges\n" ); + $clink = ''; + } } elseif( $rc->unpatrolled && $rc_type == RC_NEW ) { # Unpatrolled new page, give rc_id in query $clink = $this->skin->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" ); @@ -386,6 +420,7 @@ class EnhancedChangesList extends ChangesList { * Enhanced RC group */ function recentChangesBlockGroup( $block ) { + global $wgLang, $wgContLang, $wgRCShowChangedSize; $r = ''; # Collate list of users @@ -394,7 +429,6 @@ class EnhancedChangesList extends ChangesList { $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; } @@ -415,13 +449,14 @@ class EnhancedChangesList extends ChangesList { $users = array(); foreach( $userlinks as $userlink => $count) { $text = $userlink; + $text .= $wgContLang->getDirMark(); if( $count > 1 ) { $text .= ' ('.$count.'×)'; } array_push( $users, $text ); } - $users = ' ['.implode('; ',$users).']'; + $users = ' [' . implode( $this->message['semicolon-separator'] . ' ', $users ) . ']'; # Arrow $rci = 'RCI'.$this->rcCacheIndex; @@ -437,43 +472,62 @@ class EnhancedChangesList extends ChangesList { $r .= $this->recentChangesFlags( $isnew, false, $unpatrolled, ' ', $bot ); # Timestamp - $r .= ' '.$block[0]->timestamp.' '; - $r .= ''; + $r .= ' '.$block[0]->timestamp.' '; # Article link $r .= $this->maybeWatchedLink( $block[0]->link, $block[0]->watched ); + $r .= $wgContLang->getDirMark(); $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id']; $currentRevision = $block[0]->mAttribs['rc_this_oldid']; if( $block[0]->mAttribs['rc_type'] != RC_LOG ) { # Changes - $r .= ' ('.count($block).' '; + + $n = count($block); + static $nchanges = array(); + if ( !isset( $nchanges[$n] ) ) { + $nchanges[$n] = wfMsgExt( 'nchanges', array( 'parsemag', 'escape'), + $wgLang->formatNum( $n ) ); + } + + $r .= ' ('; + if( $isnew ) { - $r .= $this->message['changes']; + $r .= $nchanges[$n]; } else { $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), - $this->message['changes'], $curIdEq."&diff=$currentRevision&oldid=$oldid" ); + $nchanges[$n], $curIdEq."&diff=$currentRevision&oldid=$oldid" ); } - $r .= '; '; + + $r .= ') . . '; + + if( $wgRCShowChangedSize ) { + # Character difference + $chardiff = $rcObj->getCharacterDifference( $block[ count( $block ) - 1 ]->mAttribs['rc_old_len'], + $block[0]->mAttribs['rc_new_len'] ); + if( $chardiff == '' ) { + $r .= ' ('; + } else { + $r .= ' ' . $chardiff. ' . . '; + } + } # History - $r .= $this->skin->makeKnownLinkObj( $block[0]->getTitle(), + $r .= '(' . $this->skin->makeKnownLinkObj( $block[0]->getTitle(), $this->message['history'], $curIdEq.'&action=history' ); $r .= ')'; } $r .= $users; - if($block[0]->numberofWatchingusers > 0) { - global $wgContLang; - $r .= wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($block[0]->numberofWatchingusers)); - } + $r .= $this->numberofWatchingusers($block[0]->numberofWatchingusers); $r .= "
\n"; # Sub-entries $r .= '