From 28f2fe8a2235b76478b0767683a2cb57e2fe7fa7 Mon Sep 17 00:00:00 2001 From: Stephane Bisson Date: Thu, 25 Jun 2015 15:13:23 -0400 Subject: [PATCH] Add 'EnhancedChangesListModifyLineData' hook Gives extensions a chance to modify the data used to build each enhanced recent change 'inner' lines (as opposed to the header lines). Bug: T102021 Change-Id: Ia8a796fb9621db14d6574e66a4572e1fdf3bad03 --- RELEASE-NOTES-1.26 | 4 +- docs/hooks.txt | 7 +++ includes/changes/ChangesList.php | 26 ++++++++++- includes/changes/EnhancedChangesList.php | 55 +++++++++++++++++------- 4 files changed, 74 insertions(+), 18 deletions(-) diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index 983601e840..33ba6de224 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -34,6 +34,8 @@ 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. ==== External libraries ==== * Update es5-shim from v4.0.0 to v4.1.5. @@ -116,7 +118,6 @@ changes to languages because of Bugzilla reports. way will issue a deprecation warning. * The jquery.mwExtension module was deprecated. - == Compatibility == MediaWiki 1.26 requires PHP 5.3.3 or later. There is experimental support for @@ -182,4 +183,3 @@ going to run a public MediaWiki, so you can be notified of security fixes. == IRC help == There's usually someone online in #mediawiki on irc.freenode.net. - diff --git a/docs/hooks.txt b/docs/hooks.txt index 8cfdee904f..5480a255e8 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1304,6 +1304,13 @@ $changesList: EnhancedChangesList object &$links: The links that were generated by EnhancedChangesList $block: The RecentChanges objects in that block +'EnhancedChangesListModifyLineData': to alter data used to build +a 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 + '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 932006d4ce..8989b2aee0 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -204,7 +204,8 @@ class ChangesList extends ContextSource { $code = $lang->getCode(); static $fastCharDiff = array(); if ( !isset( $fastCharDiff[$code] ) ) { - $fastCharDiff[$code] = $config->get( 'MiserMode' ) || $context->msg( 'rc-change-size' )->plain() === '$1'; + $fastCharDiff[$code] = $config->get( 'MiserMode' ) + || $context->msg( 'rc-change-size' )->plain() === '$1'; } $formattedSize = $lang->formatNum( $szdiff ); @@ -542,6 +543,17 @@ class ChangesList extends ContextSource { } } + /** + * @param RecentChange $rc + * @return string + * @since 1.26 + */ + public function getRollback( RecentChange $rc ) { + $s = ''; + $this->insertRollback( $s, $rc ); + return $s; + } + /** * @param string $s * @param RecentChange $rc @@ -560,6 +572,18 @@ class ChangesList extends ContextSource { $s .= ' ' . $tagSummary; } + /** + * @param RecentChange $rc + * @param array $classes + * @return string + * @since 1.26 + */ + public function getTags( RecentChange $rc, array &$classes ) { + $s = ''; + $this->insertTags( $s, $rc, $classes ); + return $s; + } + public function insertExtra( &$s, &$rc, &$classes ) { // Empty, used for subclasses to add anything special. } diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index 54cde0dbee..545ea26e19 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -304,18 +304,18 @@ class EnhancedChangesList extends ChangesList { # 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 = ' . . '; - $r .= ''; - $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 .= ' '; + ); $params = $queryParams; @@ -340,40 +340,65 @@ class EnhancedChangesList extends ChangesList { $link = '' . $link . ' '; } } - $r .= $link . ''; + $data['timestampLink'] = $link; + $currentAndLastLinks = ''; if ( !$type == RC_LOG || $type == RC_NEW ) { - $r .= ' ' . $this->msg( 'parentheses' )->rawParams( + $currentAndLastLinks .= ' ' . $this->msg( 'parentheses' )->rawParams( $rcObj->curlink . $this->message['pipe-separator'] . $rcObj->lastlink )->escaped(); } - $r .= ' . . '; + $data['currentAndLastLinks'] = $currentAndLastLinks; + $data['separatorAfterCurrentAndLastLinks'] = $separator; # Character diff if ( $RCShowChangedSize ) { $cd = $this->formatCharacterDifference( $rcObj ); if ( $cd !== '' ) { - $r .= $cd . ' . . '; + $data['characterDiff'] = $cd; + $data['separatorAfterCharacterDiff'] = $separator; } } if ( $rcObj->mAttribs['rc_type'] == RC_LOG ) { - $r .= $this->insertLogEntry( $rcObj ); + $data['logEntry'] = $this->insertLogEntry( $rcObj ); } else { # User links - $r .= $rcObj->userlink; - $r .= $rcObj->usertalklink; - $r .= $this->insertComment( $rcObj ); + $data['userLink'] = $rcObj->userlink; + $data['userTalkLink'] = $rcObj->usertalklink; + $data['comment'] = $this->insertComment( $rcObj ); } # Rollback - $this->insertRollback( $r, $rcObj ); + $data['rollback'] = $this->getRollback( $rcObj ); + # Tags - $this->insertTags( $r, $rcObj, $classes ); + $data['tags'] = $this->getTags( $rcObj, $classes ); + + // give the hook a chance to modify the data + Hooks::run( 'EnhancedChangesListModifyLineData', + array( $this, &$data, $block, $rcObj ) ); + + $line = ''; + if ( isset( $data['recentChangesFlags'] ) ) { + $line .= $this->recentChangesFlags( $data['recentChangesFlags'] ); + unset( $data['recentChangesFlags'] ); + } + $line .= ' '; + + if ( isset( $data['timestampLink'] ) ) { + $line .= '' . $data['timestampLink'] . ''; + unset( $data['timestampLink'] ); + } + + // everything else: makes it easier for extensions to add or remove data + $line .= implode( '', $data ); + + $line .= "\n"; - $r .= "\n"; + $r .= $line; } $r .= "\n"; -- 2.20.1