From a191c08792fefc70572fb74fc2d554cebbae1e4c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bartosz=20Dziewo=C5=84ski?= Date: Fri, 3 Jan 2014 15:31:16 +0100 Subject: [PATCH] ChangesListSpecialPage: Implement doMainQuery() Here SpecialWatchlist and SpecialRecentChanges are different enough that I think it's clearer not to make them call parent; I just cleaned them up a little and extracted the common parts to ChangesListSpecialPage. Change-Id: I3b90e9a0d5017f61f5c50c6c6b35b2876c9644ee --- .../specialpage/ChangesListSpecialPage.php | 37 +++++++++++++++++-- includes/specials/SpecialRecentchanges.php | 25 ++++++------- includes/specials/SpecialWatchlist.php | 28 +++++++++++--- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index c088adb5ad..3a99edab94 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -269,13 +269,44 @@ abstract class ChangesListSpecialPage extends SpecialPage { /** * Process the query - * @todo This should build some basic processing here… * * @param array $conds * @param FormOptions $opts - * @return bool|ResultWrapper Result or false (for Recentchangeslinked only) + * @return bool|ResultWrapper Result or false */ - abstract public function doMainQuery( $conds, $opts ); + public function doMainQuery( $conds, $opts ) { + $tables = array( 'recentchanges' ); + $fields = RecentChange::selectFields(); + $query_options = array(); + $join_conds = array(); + + ChangeTags::modifyDisplayQuery( + $tables, + $fields, + $conds, + $join_conds, + $query_options, + '' + ); + + // @todo Fire a Special{$this->getName()}Query hook here + // @todo Uncomment and document + // if ( !wfRunHooks( 'ChangesListSpecialPageQuery', + // array( &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) ) + // ) { + // return false; + // } + + $dbr = $this->getDB(); + return $dbr->select( + $tables, + $fields, + $conds, + __METHOD__, + $query_options, + $join_conds + ); + } /** * Return a DatabaseBase object for reading diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index fdf8dcbfbd..36a1d1cb17 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -182,35 +182,32 @@ class SpecialRecentChanges extends ChangesListSpecialPage { * @return bool|ResultWrapper Result or false (for Recentchangeslinked only) */ public function doMainQuery( $conds, $opts ) { - $tables = array( 'recentchanges' ); - $join_conds = array(); - $query_options = array(); - - $uid = $this->getUser()->getId(); $dbr = $this->getDB(); - $limit = $opts['limit']; - $namespace = $opts['namespace']; - $invert = $opts['invert']; - $associated = $opts['associated']; + $user = $this->getUser(); + $tables = array( 'recentchanges' ); $fields = RecentChange::selectFields(); + $query_options = array(); + $join_conds = array(); + // JOIN on watchlist for users - if ( $uid && $this->getUser()->isAllowed( 'viewmywatchlist' ) ) { + if ( $user->getId() && $user->isAllowed( 'viewmywatchlist' ) ) { $tables[] = 'watchlist'; $fields[] = 'wl_user'; $fields[] = 'wl_notificationtimestamp'; $join_conds['watchlist'] = array( 'LEFT JOIN', array( - 'wl_user' => $uid, + 'wl_user' => $user->getId(), 'wl_title=rc_title', 'wl_namespace=rc_namespace' ) ); } - if ( $this->getUser()->isAllowed( 'rollback' ) ) { + + if ( $user->isAllowed( 'rollback' ) ) { $tables[] = 'page'; $fields[] = 'page_latest'; $join_conds['page'] = array( 'LEFT JOIN', 'rc_cur_id=page_id' ); } - // Tag stuff. + ChangeTags::modifyDisplayQuery( $tables, $fields, @@ -233,7 +230,7 @@ class SpecialRecentChanges extends ChangesListSpecialPage { $fields, $conds + array( 'rc_new' => array( 0, 1 ) ), __METHOD__, - array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $limit ) + $query_options, + array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $opts['limit'] ) + $query_options, $join_conds ); } diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index a98447be9a..147719248b 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -178,6 +178,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { $dbr = $this->getDB(); $user = $this->getUser(); + # Toggle watchlist content (all recent edits or just the latest) if ( $opts['extended'] ) { $limitWatchlist = $user->getIntOption( 'wllimit' ); @@ -201,6 +202,7 @@ class SpecialWatchlist extends ChangesListSpecialPage { $tables = array( 'recentchanges', 'watchlist' ); $fields = RecentChange::selectFields(); + $query_options = array( 'ORDER BY' => 'rc_timestamp DESC' ); $join_conds = array( 'watchlist' => array( 'INNER JOIN', @@ -211,12 +213,12 @@ class SpecialWatchlist extends ChangesListSpecialPage { ), ), ); - $options = array( 'ORDER BY' => 'rc_timestamp DESC' ); + if ( $wgShowUpdatedMarker ) { $fields[] = 'wl_notificationtimestamp'; } if ( $limitWatchlist ) { - $options['LIMIT'] = $limitWatchlist; + $query_options['LIMIT'] = $limitWatchlist; } $rollbacker = $user->isAllowed( 'rollback' ); @@ -245,10 +247,26 @@ class SpecialWatchlist extends ChangesListSpecialPage { } - ChangeTags::modifyDisplayQuery( $tables, $fields, $conds, $join_conds, $options, '' ); - wfRunHooks( 'SpecialWatchlistQuery', array( &$conds, &$tables, &$join_conds, &$fields, $opts ) ); + ChangeTags::modifyDisplayQuery( + $tables, + $fields, + $conds, + $join_conds, + $query_options, + '' + ); - return $dbr->select( $tables, $fields, $conds, __METHOD__, $options, $join_conds ); + wfRunHooks( 'SpecialWatchlistQuery', + array( &$conds, &$tables, &$join_conds, &$fields, $opts ) ); + + return $dbr->select( + $tables, + $fields, + $conds, + __METHOD__, + $query_options, + $join_conds + ); } /** -- 2.20.1