From 94f153db6a0e6cd0c6e06e186fbcfa8c6ea01566 Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Thu, 2 Jul 2015 14:09:41 +0200 Subject: [PATCH] Add hook EnhancedChangesListModifyBlockLineData Introduce a new hook to allow (single) block-level entries. Very similar to EnhancedChangesListModifyLineData. Bug: T104399 Change-Id: I6b4715277d44e5f09d7a230b33e956676aeab1c2 --- RELEASE-NOTES-1.26 | 5 +- docs/hooks.txt | 8 ++- includes/changes/ChangesList.php | 13 +++++ includes/changes/EnhancedChangesList.php | 65 +++++++++++++++++------- 4 files changed, 70 insertions(+), 21 deletions(-) diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index aed6de9790..111e775b89 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -38,8 +38,9 @@ production. if ImageMagick is used as image scaler ($wgUseImageMagick = true). Uploading of WebP images still disabled by default. Add $wgFileExtensions[] = 'webp'; to LocalSettings.php to enable uploading of WebP images. -* Added a new hook 'EnhancedChangesListModifyLineData', to - modify the data used to build lines in enhanced recentchanges and watchlist. +* Added new hooks 'EnhancedChangesListModifyLineData' & + 'EnhancedChangesListModifyBlockLineData', to modify the data used to build + lines in enhanced recentchanges and watchlist. ==== External libraries ==== * Update es5-shim from v4.0.0 to v4.1.5. diff --git a/docs/hooks.txt b/docs/hooks.txt index bcdfa40a70..92bc95a098 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1305,12 +1305,18 @@ $changesList: EnhancedChangesList object $block: The RecentChanges objects in that block 'EnhancedChangesListModifyLineData': to alter data used to build -a recent change inner line in EnhancedChangesList. +a grouped recent change inner line in EnhancedChangesList. $changesList: EnhancedChangesList object &$data: An array with all the components that will be joined in order to create the line $block: An array of RecentChange objects in that block $rc: The RecentChange object for this line +'EnhancedChangesListModifyBlockLineData': to alter data used to build +a non-grouped recent change line in EnhancedChangesList. +$changesList: EnhancedChangesList object +&$data: An array with all the components that will be joined in order to create the line +$rc: The RecentChange object for this line + 'ExemptFromAccountCreationThrottle': Exemption from the account creation throttle. $ip: The ip address of the user diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index 8989b2aee0..fdc9944fdc 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -371,6 +371,19 @@ class ChangesList extends ContextSource { $s .= " $articlelink"; } + /** + * @param RecentChange $rc + * @param bool $unpatrolled + * @param bool $watched + * @return string + * @since 1.26 + */ + public function getArticleLink( RecentChange $rc, $unpatrolled, $watched ) { + $s = ''; + $this->insertArticleLink( $s, $rc, $unpatrolled, $watched ); + return $s; + } + /** * Get the timestamp from $rc formatted with current user's settings * and a separator diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index 545ea26e19..fe7deb60dd 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -522,6 +522,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']; @@ -536,32 +538,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 .= ''; # Flag and Timestamp - $r .= $this->recentChangesFlags( array( + $data['recentChangesFlags'] = $this->recentChangesFlags( array( 'newpage' => $type == RC_NEW, 'minor' => $rcObj->mAttribs['rc_minor'], 'unpatrolled' => $rcObj->unpatrolled, 'bot' => $rcObj->mAttribs['rc_bot'], ) ); - $r .= ' ' . $rcObj->timestamp . ' '; + // 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'], @@ -569,31 +572,57 @@ class EnhancedChangesList extends ChangesList { $query ) )->escaped(); } - $r .= ' . . '; + $data['separatorAfterLinks'] = ' . . '; + # Character diff if ( $this->getConfig()->get( 'RCShowChangedSize' ) ) { $cd = $this->formatCharacterDifference( $rcObj ); if ( $cd !== '' ) { - $r .= $cd . ' . . '; + $data['characterDiff'] = $cd; + $data['separatorAftercharacterDiff'] = ' . . '; } } 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 .= "\n"; + // give the hook a chance to modify the data + Hooks::run( 'EnhancedChangesListModifyBlockLineData', + array( $this, &$data, $rcObj ) ); - return $r; + $line = Html::openElement( 'table', array( 'class' => $classes ) ) . + Html::openElement( 'tr' ); + $line .= ''; + + if ( isset( $data['recentChangesFlags'] ) ) { + $line .= $this->recentChangesFlags( $data['recentChangesFlags'] ); + unset( $data['recentChangesFlags'] ); + } + + if ( isset( $data['timestampLink'] ) ) { + $line .= ' ' . $data['timestampLink']; + unset( $data['timestampLink'] ); + } + $line .= ' '; + + // everything else: makes it easier for extensions to add or remove data + $line .= implode( '', $data ); + + $line .= "\n"; + + return $line; } /** -- 2.20.1