MediaWiki
REL1_23
|
00001 <?php 00023 class RCCacheEntryFactory { 00024 00025 /* @var IContextSource */ 00026 private $context; 00027 00028 /* @var string[] */ 00029 private $messages; 00030 00035 public function __construct( IContextSource $context, $messages ) { 00036 $this->context = $context; 00037 $this->messages = $messages; 00038 } 00039 00046 public function newFromRecentChange( RecentChange $baseRC, $watched ) { 00047 $user = $this->context->getUser(); 00048 $counter = $baseRC->counter; 00049 00050 $cacheEntry = RCCacheEntry::newFromParent( $baseRC ); 00051 00052 // Should patrol-related stuff be shown? 00053 $cacheEntry->unpatrolled = ChangesList::isUnpatrolled( $baseRC, $user ); 00054 00055 $cacheEntry->watched = $cacheEntry->mAttribs['rc_type'] == RC_LOG ? false : $watched; 00056 $cacheEntry->numberofWatchingusers = $baseRC->numberofWatchingusers; 00057 00058 $cacheEntry->link = $this->buildCLink( $cacheEntry ); 00059 $cacheEntry->timestamp = $this->buildTimestamp( $cacheEntry ); 00060 00061 // Make "cur" and "diff" links. Do not use link(), it is too slow if 00062 // called too many times (50% of CPU time on RecentChanges!). 00063 $showDiffLinks = $this->showDiffLinks( $cacheEntry, $user ); 00064 00065 $cacheEntry->difflink = $this->buildDiffLink( $cacheEntry, $showDiffLinks, $counter ); 00066 $cacheEntry->curlink = $this->buildCurLink( $cacheEntry, $showDiffLinks, $counter ); 00067 $cacheEntry->lastlink = $this->buildLastLink( $cacheEntry, $showDiffLinks ); 00068 00069 // Make user links 00070 $cacheEntry->userlink = $this->getUserLink( $cacheEntry ); 00071 00072 if ( !ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) { 00073 $cacheEntry->usertalklink = Linker::userToolLinks( 00074 $cacheEntry->mAttribs['rc_user'], 00075 $cacheEntry->mAttribs['rc_user_text'] 00076 ); 00077 } 00078 00079 return $cacheEntry; 00080 } 00081 00088 private function showDiffLinks( RecentChange $cacheEntry, User $user ) { 00089 return ChangesList::userCan( $cacheEntry, Revision::DELETED_TEXT, $user ); 00090 } 00091 00097 private function buildCLink( RecentChange $cacheEntry ) { 00098 $type = $cacheEntry->mAttribs['rc_type']; 00099 00100 // Page moves, very old style, not supported anymore 00101 if ( $type == RC_MOVE || $type == RC_MOVE_OVER_REDIRECT ) { 00102 $clink = ''; 00103 // New unpatrolled pages 00104 } elseif ( $cacheEntry->unpatrolled && $type == RC_NEW ) { 00105 $clink = Linker::linkKnown( $cacheEntry->getTitle() ); 00106 // Log entries 00107 } elseif ( $type == RC_LOG ) { 00108 $logType = $cacheEntry->mAttribs['rc_log_type']; 00109 00110 if ( $logType ) { 00111 $clink = $this->getLogLink( $logType ); 00112 } else { 00113 wfDebugLog( 'recentchanges', 'Unexpected log entry with no log type in recent changes' ); 00114 $clink = Linker::link( $cacheEntry->getTitle() ); 00115 } 00116 // Log entries (old format) and special pages 00117 } elseif ( $cacheEntry->mAttribs['rc_namespace'] == NS_SPECIAL ) { 00118 wfDebugLog( 'recentchanges', 'Unexpected special page in recentchanges' ); 00119 $clink = ''; 00120 // Edits 00121 } else { 00122 $clink = Linker::linkKnown( $cacheEntry->getTitle() ); 00123 } 00124 00125 return $clink; 00126 } 00127 00128 private function getLogLink( $logType ) { 00129 $logtitle = SpecialPage::getTitleFor( 'Log', $logType ); 00130 $logpage = new LogPage( $logType ); 00131 $logname = $logpage->getName()->escaped(); 00132 00133 $logLink = $this->context->msg( 'parentheses' ) 00134 ->rawParams( Linker::linkKnown( $logtitle, $logname ) )->escaped(); 00135 00136 return $logLink; 00137 } 00138 00144 private function buildTimestamp( RecentChange $cacheEntry ) { 00145 return $this->context->getLanguage()->userTime( 00146 $cacheEntry->mAttribs['rc_timestamp'], 00147 $this->context->getUser() 00148 ); 00149 } 00150 00156 private function buildCurQueryParams( RecentChange $recentChange ) { 00157 return array( 00158 'curid' => $recentChange->mAttribs['rc_cur_id'], 00159 'diff' => 0, 00160 'oldid' => $recentChange->mAttribs['rc_this_oldid'] 00161 ); 00162 } 00163 00171 private function buildCurLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) { 00172 $queryParams = $this->buildCurQueryParams( $cacheEntry ); 00173 $curMessage = $this->getMessage( 'cur' ); 00174 $logTypes = array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ); 00175 00176 if ( !$showDiffLinks || in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) { 00177 $curLink = $curMessage; 00178 } else { 00179 $curUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) ); 00180 $curLink = "<a href=\"$curUrl\" tabindex=\"$counter\">$curMessage</a>"; 00181 } 00182 00183 return $curLink; 00184 } 00185 00191 private function buildDiffQueryParams( RecentChange $recentChange ) { 00192 return array( 00193 'curid' => $recentChange->mAttribs['rc_cur_id'], 00194 'diff' => $recentChange->mAttribs['rc_this_oldid'], 00195 'oldid' => $recentChange->mAttribs['rc_last_oldid'] 00196 ); 00197 } 00198 00206 private function buildDiffLink( RecentChange $cacheEntry, $showDiffLinks, $counter ) { 00207 $queryParams = $this->buildDiffQueryParams( $cacheEntry ); 00208 $diffMessage = $this->getMessage( 'diff' ); 00209 $logTypes = array( RC_NEW, RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ); 00210 00211 if ( !$showDiffLinks ) { 00212 $diffLink = $diffMessage; 00213 } elseif ( in_array( $cacheEntry->mAttribs['rc_type'], $logTypes ) ) { 00214 $diffLink = $diffMessage; 00215 } else { 00216 $diffUrl = htmlspecialchars( $cacheEntry->getTitle()->getLinkURL( $queryParams ) ); 00217 $diffLink = "<a href=\"$diffUrl\" tabindex=\"$counter\">$diffMessage</a>"; 00218 } 00219 00220 return $diffLink; 00221 } 00222 00229 private function buildLastLink( RecentChange $cacheEntry, $showDiffLinks ) { 00230 $lastOldid = $cacheEntry->mAttribs['rc_last_oldid']; 00231 $lastMessage = $this->getMessage( 'last' ); 00232 $type = $cacheEntry->mAttribs['rc_type']; 00233 $logTypes = array( RC_LOG, RC_MOVE, RC_MOVE_OVER_REDIRECT ); 00234 00235 // Make "last" link 00236 if ( !$showDiffLinks || !$lastOldid || in_array( $type, $logTypes ) ) { 00237 $lastLink = $lastMessage; 00238 } else { 00239 $lastLink = Linker::linkKnown( 00240 $cacheEntry->getTitle(), 00241 $lastMessage, 00242 array(), 00243 $this->buildDiffQueryParams( $cacheEntry ) 00244 ); 00245 } 00246 00247 return $lastLink; 00248 } 00249 00255 private function getUserLink( RecentChange $cacheEntry ) { 00256 if ( ChangesList::isDeleted( $cacheEntry, Revision::DELETED_USER ) ) { 00257 $userLink = ' <span class="history-deleted">' . 00258 $this->context->msg( 'rev-deleted-user' )->escaped() . '</span>'; 00259 } else { 00260 $userLink = Linker::userLink( 00261 $cacheEntry->mAttribs['rc_user'], 00262 $cacheEntry->mAttribs['rc_user_text'] 00263 ); 00264 } 00265 00266 return $userLink; 00267 } 00268 00274 private function getMessage( $key ) { 00275 return $this->messages[$key]; 00276 } 00277 00278 }