From 01798c3813b602bd3e8f9a666249e6da58526109 Mon Sep 17 00:00:00 2001 From: Erik Bernhardson Date: Mon, 3 Mar 2014 13:26:54 -0800 Subject: [PATCH] New Hook rc/watchlist hook ChangesListBegin An extension hooking into recent changes may need to load additional data that did not fit into the recentchanges table. This hook gives revisions an opportunity to see the full result prior to rendering and batch load where approprite rather than loading piecemeal during the render process. Change-Id: I28d4e41437e485e518f2a23b6da00cdc430a8c23 --- RELEASE-NOTES-1.23 | 2 ++ docs/hooks.txt | 10 ++++++++++ includes/changes/ChangesList.php | 3 ++- includes/changes/EnhancedChangesList.php | 6 +++++- includes/changes/OldChangesList.php | 11 +++++++++++ includes/specials/SpecialRecentchanges.php | 2 +- includes/specials/SpecialWatchlist.php | 3 ++- 7 files changed, 33 insertions(+), 4 deletions(-) diff --git a/RELEASE-NOTES-1.23 b/RELEASE-NOTES-1.23 index 340aa505a4..4e00d40edf 100644 --- a/RELEASE-NOTES-1.23 +++ b/RELEASE-NOTES-1.23 @@ -130,6 +130,8 @@ production. * Added BaseTemplateAfterPortlet hook to allow injecting html after portlets in skins. * Support has been added for a JSON based localisation file format. The installer has been updated to use it. +* Add new hooks OldChangesListBegin and EnhancedChangesListBegin hooks to allow + extensions a chance to batch process the result set prior to rendering. === Bug fixes in 1.23 === * (bug 41759) The "updated since last visit" markers (on history pages, recent diff --git a/docs/hooks.txt b/docs/hooks.txt index e4037e6a07..122a89be28 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1112,6 +1112,11 @@ $editToken: The user's edit token. &$hookErr: Out-param for the error. Passed as the parameters to OutputPage::showErrorPage. +'EnhancedChangesListBegin': to receive the full list of rows to be rendered +in the enhanced changes list before rendering begings. +$changesList: EnhancedChangesList object +$rows: ResultWrapper containing all rows to be rendered + 'ExemptFromAccountCreationThrottle': Exemption from the account creation throttle. $ip: The ip address of the user @@ -1742,6 +1747,11 @@ displayed. &$transform: whether or not to expand variables and templates in the message (bool) +'OldChangesListBegin': to receive the full list of rows to be rendered +in the enhanced changes list before rendering begings. +$changesList: OldChangesList object +$rows: array containing all rows to be rendered + 'OldChangesListRecentChangesLine': Customize entire recent changes line, or return false to omit the line from RecentChanges and Watchlist special pages. &$changeslist: The OldChangesList instance. diff --git a/includes/changes/ChangesList.php b/includes/changes/ChangesList.php index ca9efc3934..511690125e 100644 --- a/includes/changes/ChangesList.php +++ b/includes/changes/ChangesList.php @@ -160,9 +160,10 @@ class ChangesList extends ContextSource { /** * Returns text for the start of the tabular part of RC + * @param ResultWrapper|array $rows * @return string */ - public function beginRecentChangesList() { + public function beginRecentChangesList( $rows ) { $this->rc_cache = array(); $this->rcMoveIndex = 0; $this->rcCacheIndex = 0; diff --git a/includes/changes/EnhancedChangesList.php b/includes/changes/EnhancedChangesList.php index feb6d7b2bf..de8bf7206d 100644 --- a/includes/changes/EnhancedChangesList.php +++ b/includes/changes/EnhancedChangesList.php @@ -59,9 +59,11 @@ class EnhancedChangesList extends ChangesList { /** * Add the JavaScript file for enhanced changeslist + * + * @param ResultWrapper $res * @return string */ - public function beginRecentChangesList() { + public function beginRecentChangesList( $res ) { $this->rc_cache = array(); $this->rcMoveIndex = 0; $this->rcCacheIndex = 0; @@ -76,6 +78,8 @@ class EnhancedChangesList extends ChangesList { 'mediawiki.icon', ) ); + wfRunHooks( 'EnhancedChangesListBegin', array( $this, $res ) ); + return '
'; } diff --git a/includes/changes/OldChangesList.php b/includes/changes/OldChangesList.php index 458f21a139..d88e99a0a6 100644 --- a/includes/changes/OldChangesList.php +++ b/includes/changes/OldChangesList.php @@ -130,4 +130,15 @@ class OldChangesList extends ChangesList { return "$dateheader
  • " . $s . "
  • \n"; } + + /** + * Returns text for the start of the tabular part of RC + * + * @param ResultWrapper $res + * @return string + */ + public function beginRecentChangesList( $res ) { + wfRunHooks( 'OldChangesListBegin', array( $this, $res ) ); + return parent::beginRecentChangesList( $res ); + } } diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 720d0a80f8..885e4cfdbe 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -295,7 +295,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { $counter = 1; $list = ChangesList::newFromContext( $this->getContext() ); - $rclistOutput = $list->beginRecentChangesList(); + $rclistOutput = $list->beginRecentChangesList( $rows ); foreach ( $rows as $obj ) { if ( $limit == 0 ) { break; diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 4c3f17bb98..7c3002ddf3 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -317,7 +317,8 @@ class SpecialWatchlist extends ChangesListSpecialPage { $list = ChangesList::newFromContext( $this->getContext() ); $list->setWatchlistDivs(); - $s = $list->beginRecentChangesList(); + $s = $list->beginRecentChangesList( $rows ); + $dbr->dataSeek( $rows, 0 ); $counter = 1; foreach ( $rows as $obj ) { # Make RC entry -- 2.20.1