summaryrefslogtreecommitdiff
path: root/includes/changes/EnhancedChangesList.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/changes/EnhancedChangesList.php')
-rw-r--r--includes/changes/EnhancedChangesList.php262
1 files changed, 177 insertions, 85 deletions
diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php
index 19277f10..d912e3a2 100644
--- a/includes/changes/EnhancedChangesList.php
+++ b/includes/changes/EnhancedChangesList.php
@@ -270,6 +270,20 @@ class EnhancedChangesList extends ChangesList {
$queryParams['curid'] = $curId;
+ # Sub-entries
+ $lines = '';
+ foreach ( $block as $i => $rcObj ) {
+ $line = $this->getLineData( $block, $rcObj, $queryParams );
+ $lines .= $line;
+ if ( !$line ) {
+ // completely ignore this RC entry if we don't want to render it
+ unset( $block[$i] );
+ }
+ }
+ // Further down are some assumptions that $block is a 0-indexed array
+ // with (count-1) as last key. Let's make sure it is.
+ $block = array_values( $block );
+
$r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden );
$r .= ' <span class="mw-changeslist-separator">. .</span> ';
@@ -299,88 +313,133 @@ class EnhancedChangesList extends ChangesList {
$r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers );
$r .= '</td></tr>';
- # Sub-entries
- foreach ( $block as $rcObj ) {
- # Classes to apply -- TODO implement
- $classes = array();
- $type = $rcObj->mAttribs['rc_type'];
-
- $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
- ? ' class="mw-enhanced-watched"' : '';
-
- $r .= '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
- $r .= $this->recentChangesFlags( array(
- 'newpage' => $type == RC_NEW,
- 'minor' => $rcObj->mAttribs['rc_minor'],
- 'unpatrolled' => $rcObj->unpatrolled,
- 'bot' => $rcObj->mAttribs['rc_bot'],
- ) );
- $r .= '&#160;</td><td class="mw-enhanced-rc-nested"><span class="mw-enhanced-rc-time">';
+ if ( !$lines ) {
+ // if there are no lines to be rendered (all aborted by hook), don't render the block
+ return '';
+ }
- $params = $queryParams;
+ $r .= $lines;
+ $r .= "</table>\n";
- if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
- $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
- }
+ $this->rcCacheIndex++;
- # Log timestamp
- if ( $type == RC_LOG ) {
- $link = $rcObj->timestamp;
- # Revision link
- } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
- $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
- } else {
+ return $r;
+ }
- $link = Linker::linkKnown(
- $rcObj->getTitle(),
- $rcObj->timestamp,
- array(),
- $params
- );
- if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
- $link = '<span class="history-deleted">' . $link . '</span> ';
- }
+ /**
+ * @param RCCacheEntry[] $block
+ * @param RCCacheEntry $rcObj
+ * @param array $queryParams
+ * @return string
+ * @throws Exception
+ * @throws FatalError
+ * @throws MWException
+ */
+ protected function getLineData( array $block, RCCacheEntry $rcObj, array $queryParams = array() ) {
+ $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' );
+
+ # Classes to apply -- TODO implement
+ $classes = array();
+ $type = $rcObj->mAttribs['rc_type'];
+ $data = array();
+
+ $trClass = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
+ ? ' class="mw-enhanced-watched"' : '';
+ $separator = ' <span class="mw-changeslist-separator">. .</span> ';
+
+ $data['recentChangesFlags'] = array(
+ 'newpage' => $type == RC_NEW,
+ 'minor' => $rcObj->mAttribs['rc_minor'],
+ 'unpatrolled' => $rcObj->unpatrolled,
+ 'bot' => $rcObj->mAttribs['rc_bot'],
+ );
+
+ $params = $queryParams;
+
+ if ( $rcObj->mAttribs['rc_this_oldid'] != 0 ) {
+ $params['oldid'] = $rcObj->mAttribs['rc_this_oldid'];
+ }
+
+ # Log timestamp
+ if ( $type == RC_LOG ) {
+ $link = $rcObj->timestamp;
+ # Revision link
+ } elseif ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) {
+ $link = '<span class="history-deleted">' . $rcObj->timestamp . '</span> ';
+ } else {
+ $link = Linker::linkKnown(
+ $rcObj->getTitle(),
+ $rcObj->timestamp,
+ array(),
+ $params
+ );
+ if ( $this->isDeleted( $rcObj, Revision::DELETED_TEXT ) ) {
+ $link = '<span class="history-deleted">' . $link . '</span> ';
}
- $r .= $link . '</span>';
+ }
+ $data['timestampLink'] = $link;
- if ( !$type == RC_LOG || $type == RC_NEW ) {
- $r .= ' ' . $this->msg( 'parentheses' )->rawParams(
+ $currentAndLastLinks = '';
+ if ( !$type == RC_LOG || $type == RC_NEW ) {
+ $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams(
$rcObj->curlink .
- $this->message['pipe-separator'] .
- $rcObj->lastlink
+ $this->message['pipe-separator'] .
+ $rcObj->lastlink
)->escaped();
- }
- $r .= ' <span class="mw-changeslist-separator">. .</span> ';
+ }
+ $data['currentAndLastLinks'] = $currentAndLastLinks;
+ $data['separatorAfterCurrentAndLastLinks'] = $separator;
- # Character diff
- if ( $RCShowChangedSize ) {
- $cd = $this->formatCharacterDifference( $rcObj );
- if ( $cd !== '' ) {
- $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
- }
+ # Character diff
+ if ( $RCShowChangedSize ) {
+ $cd = $this->formatCharacterDifference( $rcObj );
+ if ( $cd !== '' ) {
+ $data['characterDiff'] = $cd;
+ $data['separatorAfterCharacterDiff'] = $separator;
}
+ }
- if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
- $r .= $this->insertLogEntry( $rcObj );
- } else {
- # User links
- $r .= $rcObj->userlink;
- $r .= $rcObj->usertalklink;
- $r .= $this->insertComment( $rcObj );
- }
+ if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) {
+ $data['logEntry'] = $this->insertLogEntry( $rcObj );
+ } else {
+ # User links
+ $data['userLink'] = $rcObj->userlink;
+ $data['userTalkLink'] = $rcObj->usertalklink;
+ $data['comment'] = $this->insertComment( $rcObj );
+ }
+
+ # Rollback
+ $data['rollback'] = $this->getRollback( $rcObj );
- # Rollback
- $this->insertRollback( $r, $rcObj );
- # Tags
- $this->insertTags( $r, $rcObj, $classes );
+ # Tags
+ $data['tags'] = $this->getTags( $rcObj, $classes );
- $r .= "</td></tr>\n";
+ // give the hook a chance to modify the data
+ $success = Hooks::run( 'EnhancedChangesListModifyLineData',
+ array( $this, &$data, $block, $rcObj ) );
+ if ( !$success ) {
+ // skip entry if hook aborted it
+ return '';
}
- $r .= "</table>\n";
- $this->rcCacheIndex++;
+ $line = '<tr' . $trClass . '><td></td><td class="mw-enhanced-rc">';
+ if ( isset( $data['recentChangesFlags'] ) ) {
+ $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
+ unset( $data['recentChangesFlags'] );
+ }
+ $line .= '&#160;</td><td class="mw-enhanced-rc-nested">';
- return $r;
+ if ( isset( $data['timestampLink'] ) ) {
+ $line .= '<span class="mw-enhanced-rc-time">' . $data['timestampLink'] . '</span>';
+ unset( $data['timestampLink'] );
+ }
+
+ // everything else: makes it easier for extensions to add or remove data
+ $line .= implode( '', $data );
+
+ $line .= "</td></tr>\n";
+
+ return $line;
}
/**
@@ -498,6 +557,8 @@ class EnhancedChangesList extends ChangesList {
* @return string A HTML formatted line (generated using $r)
*/
protected function recentChangesBlockLine( $rcObj ) {
+ $data = array();
+
$query['curid'] = $rcObj->mAttribs['rc_cur_id'];
$type = $rcObj->mAttribs['rc_type'];
@@ -512,32 +573,33 @@ class EnhancedChangesList extends ChangesList {
}
$classes[] = $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched
? 'mw-changeslist-line-watched' : 'mw-changeslist-line-not-watched';
- $r = Html::openElement( 'table', array( 'class' => $classes ) ) .
- Html::openElement( 'tr' );
- $r .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
# Flag and Timestamp
- $r .= $this->recentChangesFlags( array(
+ $data['recentChangesFlags'] = array(
'newpage' => $type == RC_NEW,
'minor' => $rcObj->mAttribs['rc_minor'],
'unpatrolled' => $rcObj->unpatrolled,
'bot' => $rcObj->mAttribs['rc_bot'],
- ) );
- $r .= '&#160;' . $rcObj->timestamp . '&#160;</td><td>';
+ );
+ // timestamp is not really a link here, but is called timestampLink
+ // for consistency with EnhancedChangesListModifyLineData
+ $data['timestampLink'] = $rcObj->timestamp;
+
# Article or log link
if ( $logType ) {
$logPage = new LogPage( $logType );
$logTitle = SpecialPage::getTitleFor( 'Log', $logType );
$logName = $logPage->getName()->escaped();
- $r .= $this->msg( 'parentheses' )
+ $data['logLink'] = $this->msg( 'parentheses' )
->rawParams( Linker::linkKnown( $logTitle, $logName ) )->escaped();
} else {
- $this->insertArticleLink( $r, $rcObj, $rcObj->unpatrolled, $rcObj->watched );
+ $data['articleLink'] = $this->getArticleLink( $rcObj, $rcObj->unpatrolled, $rcObj->watched );
}
+
# Diff and hist links
if ( $type != RC_LOG ) {
$query['action'] = 'history';
- $r .= ' ' . $this->msg( 'parentheses' )
+ $data['historyLink'] = ' ' . $this->msg( 'parentheses' )
->rawParams( $rcObj->difflink . $this->message['pipe-separator'] . Linker::linkKnown(
$rcObj->getTitle(),
$this->message['hist'],
@@ -545,31 +607,61 @@ class EnhancedChangesList extends ChangesList {
$query
) )->escaped();
}
- $r .= ' <span class="mw-changeslist-separator">. .</span> ';
+ $data['separatorAfterLinks'] = ' <span class="mw-changeslist-separator">. .</span> ';
+
# Character diff
if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) {
$cd = $this->formatCharacterDifference( $rcObj );
if ( $cd !== '' ) {
- $r .= $cd . ' <span class="mw-changeslist-separator">. .</span> ';
+ $data['characterDiff'] = $cd;
+ $data['separatorAftercharacterDiff'] = ' <span class="mw-changeslist-separator">. .</span> ';
}
}
if ( $type == RC_LOG ) {
- $r .= $this->insertLogEntry( $rcObj );
+ $data['logEntry'] = $this->insertLogEntry( $rcObj );
} else {
- $r .= ' ' . $rcObj->userlink . $rcObj->usertalklink;
- $r .= $this->insertComment( $rcObj );
- $this->insertRollback( $r, $rcObj );
+ $data['userLink'] = $rcObj->userlink;
+ $data['userTalkLink'] = $rcObj->usertalklink;
+ $data['comment'] = $this->insertComment( $rcObj );
+ $data['rollback'] = $this->getRollback( $rcObj );
}
# Tags
- $this->insertTags( $r, $rcObj, $classes );
+ $data['tags'] = $this->getTags( $rcObj, $classes );
+
# Show how many people are watching this if enabled
- $r .= $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
+ $data['watchingUsers'] = $this->numberofWatchingusers( $rcObj->numberofWatchingusers );
- $r .= "</td></tr></table>\n";
+ // give the hook a chance to modify the data
+ $success = Hooks::run( 'EnhancedChangesListModifyBlockLineData',
+ array( $this, &$data, $rcObj ) );
+ if ( !$success ) {
+ // skip entry if hook aborted it
+ return '';
+ }
- return $r;
+ $line = Html::openElement( 'table', array( 'class' => $classes ) ) .
+ Html::openElement( 'tr' );
+ $line .= '<td class="mw-enhanced-rc"><span class="mw-enhancedchanges-arrow-space"></span>';
+
+ if ( isset( $data['recentChangesFlags'] ) ) {
+ $line .= $this->recentChangesFlags( $data['recentChangesFlags'] );
+ unset( $data['recentChangesFlags'] );
+ }
+
+ if ( isset( $data['timestampLink'] ) ) {
+ $line .= '&#160;' . $data['timestampLink'];
+ unset( $data['timestampLink'] );
+ }
+ $line .= '&#160;</td><td>';
+
+ // everything else: makes it easier for extensions to add or remove data
+ $line .= implode( '', $data );
+
+ $line .= "</td></tr></table>\n";
+
+ return $line;
}
/**