Matthias Mullie has uploaded a new change for review. https://gerrit.wikimedia.org/r/193091
Change subject: Add hook EnhancedChangesList::getLogText ...................................................................... Add hook EnhancedChangesList::getLogText Enhanced RC generates these "(3 changes | history)" links for every block of grouped recentchanges. That changes-link links to a diff page. For Flow, that is all wrong: we have different ids (not integers), on a different page (&curid=&oldid=&diff= means nothing). Even the concept of a "diff" page seems wrong here for us - a new post is not part of some document that can be diffed. In short: we'll want to generate a different link, and we'll need a hook to let us change them. Meanwhile also split the code that generates those links into a separate method. Change-Id: Ib32fb9552b80f9581d89b3b47da6e5d32e3d84a3 --- M RELEASE-NOTES-1.25 M docs/hooks.txt M includes/changes/EnhancedChangesList.php 3 files changed, 119 insertions(+), 88 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/91/193091/1 diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 83a569a..e0b1d5e 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -109,6 +109,8 @@ pointing to it. * New hooks 'ApiMain::moduleManager' and 'ApiQuery::moduleManager', can be used for conditional registration of API modules. +* New hook 'EnhancedChangesList::getLogText' to alter, remove or add to the + links of a group of changes in EnhancedChangesList. ==== External libraries ==== * MediaWiki now requires certain external libraries to be installed. In the past diff --git a/docs/hooks.txt b/docs/hooks.txt index cf2e3dd..30a7e04 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1277,6 +1277,12 @@ &$hookErr: Out-param for the error. Passed as the parameters to OutputPage::showErrorPage. +'EnhancedChangesList::getLogText': to alter, remove or add to the links of a +group of changes in EnhancedChangesList. +$changesList: EnhancedChangesList object +&$links: The links that were generated by EnhancedChangesList +$block: The RecentChanges objects in that block + 'ExemptFromAccountCreationThrottle': Exemption from the account creation throttle. $ip: The ip address of the user diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index 2cee726..19277f1 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -181,14 +181,12 @@ $isnew = false; $allBots = true; $allMinors = true; - $curId = $currentRevision = 0; + $curId = 0; # Some catalyst variables... $namehidden = true; $allLogs = true; - $oldid = ''; $RCShowChangedSize = $this->getConfig()->get( 'RCShowChangedSize' ); foreach ( $block as $rcObj ) { - $oldid = $rcObj->mAttribs['rc_last_oldid']; if ( $rcObj->mAttribs['rc_type'] == RC_NEW ) { $isnew = true; } @@ -211,9 +209,6 @@ # since logs may not have these. if ( !$curId && $rcObj->mAttribs['rc_cur_id'] ) { $curId = $rcObj->mAttribs['rc_cur_id']; - } - if ( !$currentRevision && $rcObj->mAttribs['rc_this_oldid'] ) { - $currentRevision = $rcObj->mAttribs['rc_this_oldid']; } if ( !$rcObj->mAttribs['rc_bot'] ) { @@ -275,87 +270,7 @@ $queryParams['curid'] = $curId; - # Changes message - static $nchanges = array(); - static $sinceLastVisitMsg = array(); - - $n = count( $block ); - if ( !isset( $nchanges[$n] ) ) { - $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped(); - } - - $sinceLast = 0; - $unvisitedOldid = null; - /** @var $rcObj RCCacheEntry */ - foreach ( $block as $rcObj ) { - // Same logic as below inside main foreach - if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) { - $sinceLast++; - $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid']; - } - } - if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) { - $sinceLastVisitMsg[$sinceLast] = - $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped(); - } - - # Total change link - $r .= ' '; - $logtext = ''; - /** @var $block0 RecentChange */ - $block0 = $block[0]; - if ( !$allLogs ) { - if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { - $logtext .= $nchanges[$n]; - } elseif ( $isnew ) { - $logtext .= $nchanges[$n]; - } else { - $logtext .= Linker::link( - $block0->getTitle(), - $nchanges[$n], - array(), - $queryParams + array( - 'diff' => $currentRevision, - 'oldid' => $oldid, - ), - array( 'known', 'noclasses' ) - ); - if ( $sinceLast > 0 && $sinceLast < $n ) { - $logtext .= $this->message['pipe-separator'] . Linker::link( - $block0->getTitle(), - $sinceLastVisitMsg[$sinceLast], - array(), - $queryParams + array( - 'diff' => $currentRevision, - 'oldid' => $unvisitedOldid, - ), - array( 'known', 'noclasses' ) - ); - } - } - } - - # History - if ( $allLogs ) { - // don't show history link for logs - } elseif ( $namehidden || !$block0->getTitle()->exists() ) { - $logtext .= $this->message['pipe-separator'] . $this->message['enhancedrc-history']; - } else { - $params = $queryParams; - $params['action'] = 'history'; - - $logtext .= $this->message['pipe-separator'] . - Linker::linkKnown( - $block0->getTitle(), - $this->message['enhancedrc-history'], - array(), - $params - ); - } - - if ( $logtext !== '' ) { - $r .= $this->msg( 'parentheses' )->rawParams( $logtext )->escaped(); - } + $r .= $this->getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ); $r .= ' <span class="mw-changeslist-separator">. .</span> '; @@ -381,7 +296,7 @@ } $r .= $users; - $r .= $this->numberofWatchingusers( $block0->numberofWatchingusers ); + $r .= $this->numberofWatchingusers( $block[0]->numberofWatchingusers ); $r .= '</td></tr>'; # Sub-entries @@ -469,6 +384,114 @@ } /** + * Generates amount of changes (linking to diff ) & link to history. + * + * @param array $block + * @param array $queryParams + * @param bool $allLogs + * @param bool $isnew + * @param bool $namehidden + * @return string + */ + protected function getLogText( $block, $queryParams, $allLogs, $isnew, $namehidden ) { + # Changes message + static $nchanges = array(); + static $sinceLastVisitMsg = array(); + + $n = count( $block ); + if ( !isset( $nchanges[$n] ) ) { + $nchanges[$n] = $this->msg( 'nchanges' )->numParams( $n )->escaped(); + } + + $sinceLast = 0; + $unvisitedOldid = null; + /** @var $rcObj RCCacheEntry */ + foreach ( $block as $rcObj ) { + // Same logic as below inside main foreach + if ( $rcObj->watched && $rcObj->mAttribs['rc_timestamp'] >= $rcObj->watched ) { + $sinceLast++; + $unvisitedOldid = $rcObj->mAttribs['rc_last_oldid']; + } + } + if ( !isset( $sinceLastVisitMsg[$sinceLast] ) ) { + $sinceLastVisitMsg[$sinceLast] = + $this->msg( 'enhancedrc-since-last-visit' )->numParams( $sinceLast )->escaped(); + } + + $currentRevision = 0; + foreach ( $block as $rcObj ) { + if ( !$currentRevision ) { + $currentRevision = $rcObj->mAttribs['rc_this_oldid']; + } + } + + # Total change link + $links = array(); + /** @var $block0 RecentChange */ + $block0 = $block[0]; + $last = $block[count( $block ) - 1]; + if ( !$allLogs ) { + if ( !ChangesList::userCan( $rcObj, Revision::DELETED_TEXT, $this->getUser() ) ) { + $links['total-changes'] = $nchanges[$n]; + } elseif ( $isnew ) { + $links['total-changes'] = $nchanges[$n]; + } else { + $links['total-changes'] = Linker::link( + $block0->getTitle(), + $nchanges[$n], + array(), + $queryParams + array( + 'diff' => $currentRevision, + 'oldid' => $last->mAttribs['rc_last_oldid'], + ), + array( 'known', 'noclasses' ) + ); + if ( $sinceLast > 0 && $sinceLast < $n ) { + $links['total-changes-since-last'] = Linker::link( + $block0->getTitle(), + $sinceLastVisitMsg[$sinceLast], + array(), + $queryParams + array( + 'diff' => $currentRevision, + 'oldid' => $unvisitedOldid, + ), + array( 'known', 'noclasses' ) + ); + } + } + } + + # History + if ( $allLogs ) { + // don't show history link for logs + } elseif ( $namehidden || !$block0->getTitle()->exists() ) { + $links['history'] = $this->message['enhancedrc-history']; + } else { + $params = $queryParams; + $params['action'] = 'history'; + + $links['history'] = Linker::linkKnown( + $block0->getTitle(), + $this->message['enhancedrc-history'], + array(), + $params + ); + } + + # Allow others to alter, remove or add to these links + Hooks::run( 'EnhancedChangesList::getLogText', + array( $this, &$links, $block ) ); + + if ( !$links ) { + return ''; + } + + $logtext = implode( $this->message['pipe-separator'], $links ); + $logtext = $this->msg( 'parentheses' )->rawParams( $logtext )->escaped(); + return ' ' . $logtext; + } + + /** * Enhanced RC ungrouped line. * * @param RecentChange|RCCacheEntry $rcObj -- To view, visit https://gerrit.wikimedia.org/r/193091 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib32fb9552b80f9581d89b3b47da6e5d32e3d84a3 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Matthias Mullie <mmul...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits