r44833 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44832‎ | r44833 | r44834 >
Date:08:25, 20 December 2008
Author:aaron
Status:ok
Tags:
Comment:
* Tweaks from profiling
* Remove extract() call
* Break some lines
Modified paths:
  • /trunk/phase3/includes/ChangesList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ChangesList.php
@@ -139,8 +139,8 @@
140140 # Diff
141141 $s .= '(' . $this->message['diff'] . ') (';
142142 # Hist
143 - $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'], 'action=history' ) .
144 - ') . . ';
 143+ $s .= $this->skin->makeKnownLinkObj( $rc->getMovedToTitle(), $this->message['hist'],
 144+ 'action=history' ) . ') . . ';
145145 # "[[x]] moved to [[y]]"
146146 $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
147147 $s .= wfMsg( $msg, $this->skin->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
@@ -168,13 +168,12 @@
169169
170170 protected function insertDiffHist( &$s, &$rc, $unpatrolled ) {
171171 # Diff link
172 - if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
 172+ if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
173173 $diffLink = $this->message['diff'];
174 - } else if( $rc->mAttribs['rc_type'] == RC_NEW || $rc->mAttribs['rc_type'] == RC_LOG ) {
 174+ } else if( !$this->userCan($rc,Revision::DELETED_TEXT) ) {
175175 $diffLink = $this->message['diff'];
176176 } else {
177 - $rcidparam = $unpatrolled ?
178 - array( 'rcid' => $rc->mAttribs['rc_id'] ) : array();
 177+ $rcidparam = $unpatrolled ? array( 'rcid' => $rc->mAttribs['rc_id'] ) : array();
179178 $diffLink = $this->skin->makeKnownLinkObj( $rc->getTitle(), $this->message['diff'],
180179 wfArrayToCGI( array(
181180 'curid' => $rc->mAttribs['rc_cur_id'],
@@ -224,7 +223,7 @@
225224
226225 /** Insert links to user page, user talk page and eventually a blocking link */
227226 public function insertUserRelatedLinks(&$s, &$rc) {
228 - if ( $this->isDeleted($rc,Revision::DELETED_USER) ) {
 227+ if( $this->isDeleted($rc,Revision::DELETED_USER) ) {
229228 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-user') . '</span>';
230229 } else {
231230 $s .= $this->skin->userLink( $rc->mAttribs['rc_user'], $rc->mAttribs['rc_user_text'] );
@@ -234,13 +233,11 @@
235234
236235 /** insert a formatted action */
237236 protected function insertAction(&$s, &$rc) {
238 - # Add action
239237 if( $rc->mAttribs['rc_type'] == RC_LOG ) {
240 - // log action
241 - if ( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) {
 238+ if( $this->isDeleted($rc,LogPage::DELETED_ACTION) ) {
242239 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
243240 } else {
244 - $s .= ' ' . LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
 241+ $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
245242 $rc->getTitle(), $this->skin, LogPage::extractParams($rc->mAttribs['rc_params']), true, true );
246243 }
247244 }
@@ -248,10 +245,8 @@
249246
250247 /** insert a formatted comment */
251248 protected function insertComment(&$s, &$rc) {
252 - # Add comment
253249 if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
254 - // log comment
255 - if ( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
 250+ if( $this->isDeleted($rc,Revision::DELETED_COMMENT) ) {
256251 $s .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-comment') . '</span>';
257252 } else {
258253 $s .= $this->skin->commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
@@ -274,8 +269,8 @@
275270 protected function numberofWatchingusers( $count ) {
276271 global $wgLang;
277272 static $cache = array();
278 - if ( $count > 0 ) {
279 - if ( !isset( $cache[$count] ) ) {
 273+ if( $count > 0 ) {
 274+ if( !isset( $cache[$count] ) ) {
280275 $cache[$count] = wfMsgExt('number_of_watching_users_RCview',
281276 array('parsemag', 'escape'), $wgLang->formatNum($count));
282277 }
@@ -317,7 +312,6 @@
318313
319314 protected function maybeWatchedLink( $link, $watched=false ) {
320315 if( $watched ) {
321 - // FIXME: css style might be more appropriate
322316 return '<strong class="mw-watched">' . $link . '</strong>';
323317 } else {
324318 return '<span class="mw-rc-unwatched">' . $link . '</span>';
@@ -335,48 +329,40 @@
336330 */
337331 public function recentChangesLine( &$rc, $watched = false ) {
338332 global $wgContLang, $wgRCShowChangedSize, $wgUser;
339 -
340333 wfProfileIn( __METHOD__ );
341 -
342 - # Extract DB fields into local scope
343 - // FIXME: Would be good to replace this extract() call with something that explicitly initializes local variables.
344 - extract( $rc->mAttribs );
345 -
346334 # Should patrol-related stuff be shown?
347 - $unpatrolled = $wgUser->useRCPatrol() && $rc_patrolled == 0;
 335+ $unpatrolled = $wgUser->useRCPatrol() && !$rc->mAttribs['rc_patrolled'];
348336
349 - $dateheader = ""; // $s now contains only <li>...</li>, for hooks' convenience.
350 - $this->insertDateHeader($dateheader,$rc_timestamp);
 337+ $dateheader = ''; // $s now contains only <li>...</li>, for hooks' convenience.
 338+ $this->insertDateHeader( $dateheader, $rc->mAttribs['rc_timestamp'] );
351339
352340 $s = '';
353 -
354341 // Moved pages
355 - if( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
 342+ if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
356343 $this->insertMove( $s, $rc );
357344 // Log entries
358 - } elseif( $rc_log_type ) {
359 - $logtitle = Title::newFromText( "Log/$rc_log_type", NS_SPECIAL );
360 - $this->insertLog( $s, $logtitle, $rc_log_type );
 345+ } elseif( $rc->mAttribs['rc_log_type'] ) {
 346+ $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
 347+ $this->insertLog( $s, $logtitle, $rc->mAttribs['rc_log_type'] );
361348 // Log entries (old format) or log targets, and special pages
362 - } elseif( $rc_namespace == NS_SPECIAL ) {
363 - list( $specialName, $specialSubpage ) = SpecialPage::resolveAliasWithSubpage( $rc_title );
364 - if ( $specialName == 'Log' ) {
365 - $this->insertLog( $s, $rc->getTitle(), $specialSubpage );
366 - } else {
367 - wfDebug( "Unexpected special page in recentchanges\n" );
 349+ } elseif( $rc->mAttribs['rc_namespace'] == NS_SPECIAL ) {
 350+ list( $name, $subpage ) = SpecialPage::resolveAliasWithSubpage( $rc->mAttribs['rc_title'] );
 351+ if( $name == 'Log' ) {
 352+ $this->insertLog( $s, $rc->getTitle(), $subpage );
368353 }
369354 // Regular entries
370355 } else {
371 - $this->insertDiffHist($s, $rc, $unpatrolled);
 356+ $this->insertDiffHist( $s, $rc, $unpatrolled );
372357 # M, N, b and ! (minor, new, bot and unpatrolled)
373 - $s .= $this->recentChangesFlags( $rc_type == RC_NEW, $rc_minor, $unpatrolled, '', $rc_bot );
374 - $this->insertArticleLink($s, $rc, $unpatrolled, $watched);
 358+ $s .= $this->recentChangesFlags( $rc->mAttribs['rc_new'], $rc->mAttribs['rc_minor'],
 359+ $unpatrolled, '', $rc->mAttribs['rc_bot'] );
 360+ $this->insertArticleLink( $s, $rc, $unpatrolled, $watched );
375361 }
376 -
377 - $this->insertTimestamp($s,$rc);
378 -
379 - if( $wgRCShowChangedSize ) {
380 - $s .= ( $rc->getCharacterDifference() == '' ? '' : $rc->getCharacterDifference() . ' . . ' );
 362+ # Edit/log timestamp
 363+ $this->insertTimestamp( $s, $rc );
 364+ # Bytes added or removed
 365+ if( $wgRCShowChangedSize && ($cd = $rc->getCharacterDifference()) ) {
 366+ $s .= "$cd . . ";
381367 }
382368 # User tool links
383369 $this->insertUserRelatedLinks($s,$rc);
@@ -384,29 +370,28 @@
385371 $this->insertAction($s, $rc);
386372 # Edit or log comment
387373 $this->insertComment($s, $rc);
388 -
389374 # Mark revision as deleted if so
390 - if ( !$rc_log_type && $this->isDeleted($rc,Revision::DELETED_TEXT) )
 375+ if( !$rc->mAttribs['rc_log_type'] && $this->isDeleted($rc,Revision::DELETED_TEXT) ) {
391376 $s .= ' <tt>' . wfMsgHtml( 'deletedrev' ) . '</tt>';
392 - if($rc->numberofWatchingusers > 0) {
393 - $s .= ' ' . wfMsg('number_of_watching_users_RCview', $wgContLang->formatNum($rc->numberofWatchingusers));
394377 }
 378+ # How many users watch this page
 379+ if( $rc->numberofWatchingusers > 0 ) {
 380+ $s .= ' ' . wfMsg( 'number_of_watching_users_RCview',
 381+ $wgContLang->formatNum($rc->numberofWatchingusers) );
 382+ }
395383
396384 wfRunHooks( 'OldChangesListRecentChangesLine', array(&$this, &$s, $rc) );
397 -
398 - $s = "<li>$s</li>\n";
399385
400386 wfProfileOut( __METHOD__ );
401 - return $dateheader . $s;
 387+ return "$dateheader<li>$s</li>\n";
402388 }
403389 }
404390
405391
406392 /**
407 - * Generate a list of changes using an Enhanced system (use javascript).
 393+ * Generate a list of changes using an Enhanced system (uses javascript).
408394 */
409395 class EnhancedChangesList extends ChangesList {
410 -
411396 /**
412397 * Add the JavaScript file for enhanced changeslist
413398 * @ return string

Status & tagging log