r96548 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96547‎ | r96548 | r96549 >
Date:09:15, 8 September 2011
Author:nikerabbit
Status:resolved (Comments)
Tags:
Comment:
Update ChangesList and derivatives to use LogFormatter.
This diff is a bit ugly. There is lots of duplication in ChangesList code.
Hopefully it is little better now, when most of the formatting is in LogFormatter.
Modified paths:
  • /trunk/extensions/CleanChanges/CleanChanges_body.php (modified) (history)
  • /trunk/phase3/includes/ChangesList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/ChangesList.php
@@ -225,35 +225,6 @@
226226 }
227227 }
228228
229 - /**
230 - * @param $s
231 - * @param $rc RecentChange
232 - * @return void
233 - */
234 - public function insertMove( &$s, $rc ) {
235 - # Diff
236 - $s .= '(' . $this->message['diff'] . ') (';
237 - # Hist
238 - $s .= Linker::linkKnown(
239 - $rc->getMovedToTitle(),
240 - $this->message['hist'],
241 - array(),
242 - array( 'action' => 'history' )
243 - ) . ') . . ';
244 - # "[[x]] moved to [[y]]"
245 - $msg = ( $rc->mAttribs['rc_type'] == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
246 - $s .= wfMsgHtml(
247 - $msg,
248 - Linker::linkKnown(
249 - $rc->getTitle(),
250 - null,
251 - array(),
252 - array( 'redirect' => 'no' )
253 - ),
254 - Linker::linkKnown( $rc->getMovedToTitle() )
255 - );
256 - }
257 -
258229 public function insertDateHeader( &$s, $rc_timestamp ) {
259230 # Make date header if necessary
260231 $date = $this->getLang()->date( $rc_timestamp, true, true );
@@ -268,8 +239,8 @@
269240 }
270241
271242 public function insertLog( &$s, $title, $logtype ) {
272 - $logname = LogPage::logName( $logtype );
273 - $s .= '(' . Linker::linkKnown( $title, htmlspecialchars( $logname ) ) . ')';
 243+ $logname = LogType::factory( $logtype )->getName()->escaped();
 244+ $s .= '(' . Linker::linkKnown( $title, $logname ) . ')';
274245 }
275246
276247 /**
@@ -388,31 +359,12 @@
389360 *
390361 * @param $rc RecentChange
391362 */
392 - public function insertAction( &$s, &$rc ) {
393 - if( $rc->mAttribs['rc_type'] == RC_LOG ) {
394 - if( $this->isDeleted( $rc, LogPage::DELETED_ACTION ) ) {
395 - $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-event' ) . '</span>';
396 - } else {
397 - $s .= ' '.LogPage::actionText( $rc->mAttribs['rc_log_type'], $rc->mAttribs['rc_log_action'],
398 - $rc->getTitle(), $this->getSkin(), LogPage::extractParams( $rc->mAttribs['rc_params'] ), true, true );
399 - }
400 - }
 363+ public function insertLogEntry( $rc ) {
 364+ $formatter = LogFormatter::newFromRow( $rc->mAttribs );
 365+ $mark = $this->getLang()->getDirMark();
 366+ return $formatter->getActionText() . " $mark" . $formatter->getComment();
401367 }
402368
403 - /** insert a formatted comment
404 - *
405 - * @param $rc RecentChange
406 - */
407 - public function insertComment( &$s, &$rc ) {
408 - if( $rc->mAttribs['rc_type'] != RC_MOVE && $rc->mAttribs['rc_type'] != RC_MOVE_OVER_REDIRECT ) {
409 - if( $this->isDeleted( $rc, Revision::DELETED_COMMENT ) ) {
410 - $s .= ' <span class="history-deleted">' . wfMsgHtml( 'rev-deleted-comment' ) . '</span>';
411 - } else {
412 - $s .= Linker::commentBlock( $rc->mAttribs['rc_comment'], $rc->getTitle() );
413 - }
414 - }
415 - }
416 -
417369 /**
418370 * Check whether to enable recent changes patrol features
419371 * @return Boolean
@@ -546,9 +498,8 @@
547499 }
548500 }
549501
550 - // Moved pages
 502+ // Moved pages (very very old, not supported anymore)
551503 if( $rc->mAttribs['rc_type'] == RC_MOVE || $rc->mAttribs['rc_type'] == RC_MOVE_OVER_REDIRECT ) {
552 - $this->insertMove( $s, $rc );
553504 // Log entries
554505 } elseif( $rc->mAttribs['rc_log_type'] ) {
555506 $logtitle = Title::newFromText( 'Log/'.$rc->mAttribs['rc_log_type'], NS_SPECIAL );
@@ -583,16 +534,16 @@
584535 $s .= "$cd . . ";
585536 }
586537 }
587 - # User tool links
588 - $this->insertUserRelatedLinks( $s, $rc );
589 - # LTR/RTL direction mark
590 - $s .= $this->getLang()->getDirMark();
591 - # Log action text (if any)
592 - $this->insertAction( $s, $rc );
593 - # LTR/RTL direction mark
594 - $s .= $this->getLang()->getDirMark();
595 - # Edit or log comment
596 - $this->insertComment( $s, $rc );
 538+
 539+ if ( $rc->mAttribs['rc_type'] == RC_LOG ) {
 540+ $s .= $this->insertLogEntry( $rc );
 541+ } else {
 542+ # User tool links
 543+ $this->insertUserRelatedLinks( $s, $rc );
 544+ # LTR/RTL direction mark
 545+ $s .= $this->getLang()->getDirMark();
 546+ }
 547+
597548 # Tags
598549 $this->insertTags( $s, $rc, $classes );
599550 # Rollback
@@ -1039,13 +990,14 @@
1040991 $r .= $rcObj->getCharacterDifference() . ' . . ' ;
1041992 }
1042993
1043 - # User links
1044 - $r .= $rcObj->userlink;
1045 - $r .= $rcObj->usertalklink;
1046 - // log action
1047 - $this->insertAction( $r, $rcObj );
1048 - // log comment
1049 - $this->insertComment( $r, $rcObj );
 994+ if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
 995+ $r .= $this->insertLogEntry( $rcObj );
 996+ } else {
 997+ # User links
 998+ $r .= $rcObj->userlink;
 999+ $r .= $rcObj->usertalklink;
 1000+ }
 1001+
10501002 # Rollback
10511003 $this->insertRollback( $r, $rcObj );
10521004 # Tags
@@ -1165,19 +1117,13 @@
11661118 if( $wgRCShowChangedSize && ($cd = $rcObj->getCharacterDifference()) ) {
11671119 $r .= "$cd . . ";
11681120 }
1169 - # User/talk
1170 - $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
1171 - # Log action (if any)
1172 - if( $logType ) {
1173 - if( $this->isDeleted($rcObj,LogPage::DELETED_ACTION) ) {
1174 - $r .= ' <span class="history-deleted">' . wfMsgHtml('rev-deleted-event') . '</span>';
1175 - } else {
1176 - $r .= ' ' . LogPage::actionText( $logType, $rcObj->mAttribs['rc_log_action'], $rcObj->getTitle(),
1177 - $this->getSkin(), LogPage::extractParams( $rcObj->mAttribs['rc_params'] ), true, true );
1178 - }
 1121+
 1122+ if ( $type == RC_LOG ) {
 1123+ $r .= $this->insertLogEntry( $rcObj );
 1124+ } else {
 1125+ $r .= ' '.$rcObj->userlink . $rcObj->usertalklink;
11791126 }
1180 - $this->insertComment( $r, $rcObj );
1181 - $this->insertRollback( $r, $rcObj );
 1127+
11821128 # Tags
11831129 $classes = explode( ' ', $classes );
11841130 $this->insertTags( $r, $rcObj, $classes );
Index: trunk/extensions/CleanChanges/CleanChanges_body.php
@@ -109,29 +109,8 @@
110110 }
111111
112112 protected function getLogAction( $rc ) {
113 - global $wgUser;
114 -
115 - $priviledged = $wgUser->isAllowed('deleterevision');
116 - $deleted = $this->isDeleted($rc, LogPage::DELETED_ACTION);
117 -
118 - if ( $deleted && !$priviledged ) {
119 - return $this->XMLwrapper( 'history-deleted', wfMsg('rev-deleted-event') );
120 - } else {
121 - $action = LogPage::actionText(
122 - $rc->getAttribute('rc_log_type'),
123 - $rc->getAttribute('rc_log_action'),
124 - $rc->getTitle(),
125 - $this->skin,
126 - LogPage::extractParams( $rc->getAttribute('rc_params') ),
127 - true,
128 - true
129 - );
130 - if ( $deleted ) {
131 - $class = array( 'class' => 'history-deleted' );
132 - $action = Xml::tags( 'span', $class, $action );
133 - }
134 - return $action;
135 - }
 113+ $formatter = LogFormatter::newFromRow( $rc->mAttribs );
 114+ return $formatter->getActionText();
136115 }
137116
138117 /**
@@ -181,7 +160,9 @@
182161 $rc->getAttribute( 'rc_user_text' ) );
183162 $rc->_userInfo = $stuff[0];
184163
185 - $rc->_comment = $this->getComment( $rc );
 164+ if ( !$this->isLog( $rc ) ) {
 165+ $rc->_comment = $this->getComment( $rc );
 166+ }
186167
187168 $rc->_watching = $this->numberofWatchingusers( $baseRC->numberofWatchingusers );
188169
@@ -362,10 +343,15 @@
363344 }
364345
365346 $items[] = $this->userSeparator;
366 - $items[] = $rcObj->_user;
367 - $items[] = $rcObj->_userInfo;
368 - $items[] = $rcObj->_comment;
369347
 348+ if ( $this->isLog( $rcObj ) ) {
 349+ $items[] = $this->getLogAction( $rcObj );
 350+ } else {
 351+ $items[] = $rcObj->_user;
 352+ $items[] = $rcObj->_userInfo;
 353+ $items[] = $rcObj->_comment;
 354+ }
 355+
370356 $lines .= '<div>' . implode( " {$this->dir}", $items ) . "</div>\n";
371357 }
372358 return $lines;
@@ -399,11 +385,16 @@
400386 }
401387
402388 $items[] = $this->userSeparator;
403 - $items[] = $rcObj->_user;
404 - $items[] = $rcObj->_userInfo;
405 - $items[] = $rcObj->_comment;
406 - $items[] = $rcObj->_watching;
407389
 390+ if ( $this->isLog( $rcObj ) ) {
 391+ $items[] = $this->getLogAction( $rcObj );
 392+ } else {
 393+ $items[] = $rcObj->_user;
 394+ $items[] = $rcObj->_userInfo;
 395+ $items[] = $rcObj->_comment;
 396+ $items[] = $rcObj->_watching;
 397+ }
 398+
408399 return '<div>' . implode( " {$this->dir}", $items ) . "</div>\n";
409400
410401 }
@@ -412,8 +403,6 @@
413404 global $wgUser;
414405 $comment = $rc->getAttribute( 'rc_comment' );
415406 $action = '';
416 - if ( $this->isLog($rc) ) $action = $this->getLogAction( $rc );
417 -
418407 if ( $comment === '' ) {
419408 return $action;
420409 } elseif ( $this->isDeleted( $rc, LogPage::DELETED_COMMENT ) ) {

Follow-up revisions

RevisionCommit summaryAuthorDate
r96551Improve r96548: fixed one fatal, restored user tool links and removed a littl...nikerabbit10:13, 8 September 2011
r97478My changes in r96548 were too radical, stripping of edit commits (oops!) and ...nikerabbit12:36, 19 September 2011

Comments

#Comment by Duplicatebug (talk | contribs)   18:12, 17 September 2011

Now there are no comments on ChangeLists like (old) watchlist or recentchanges.

Status & tagging log