From 0c68faf403c3ed88a1f5f88a18271ae5791b0ea9 Mon Sep 17 00:00:00 2001 From: umherirrender Date: Thu, 8 Nov 2012 19:25:59 +0100 Subject: [PATCH] Add RecentChange::selectFields and use it This avoids * in SELECTs Change-Id: I218c93f23b650e597db1ae2055dc536f2cc195a3 --- includes/RecentChange.php | 36 ++++++++++++++++++- includes/specials/SpecialRecentchanges.php | 2 +- .../specials/SpecialRecentchangeslinked.php | 2 +- includes/specials/SpecialWatchlist.php | 2 +- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/includes/RecentChange.php b/includes/RecentChange.php index 3cf6c72f92..2bdcab4031 100644 --- a/includes/RecentChange.php +++ b/includes/RecentChange.php @@ -125,7 +125,7 @@ class RecentChange { */ public static function newFromConds( $conds, $fname = __METHOD__ ) { $dbr = wfGetDB( DB_SLAVE ); - $row = $dbr->selectRow( 'recentchanges', '*', $conds, $fname ); + $row = $dbr->selectRow( 'recentchanges', self::selectFields(), $conds, $fname ); if ( $row !== false ) { return self::newFromRow( $row ); } else { @@ -133,6 +133,40 @@ class RecentChange { } } + /** + * Return the list of recentchanges fields that should be selected to create + * a new recentchanges object. + * @return array + */ + public static function selectFields() { + return array( + 'rc_id', + 'rc_timestamp', + 'rc_cur_time', + 'rc_user', + 'rc_user_text', + 'rc_namespace', + 'rc_title', + 'rc_comment', + 'rc_minor', + 'rc_bot', + 'rc_new', + 'rc_cur_id', + 'rc_this_oldid', + 'rc_last_oldid', + 'rc_type', + 'rc_patrolled', + 'rc_ip', + 'rc_old_len', + 'rc_new_len', + 'rc_deleted', + 'rc_logid', + 'rc_log_type', + 'rc_log_action', + 'rc_params', + ); + } + # Accessors /** diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 2bd8b0a96d..f542640252 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -382,7 +382,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $invert = $opts['invert']; $associated = $opts['associated']; - $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' ); // all rc columns + $fields = RecentChange::selectFields(); // JOIN on watchlist for users if ( $uid ) { $tables[] = 'watchlist'; diff --git a/includes/specials/SpecialRecentchangeslinked.php b/includes/specials/SpecialRecentchangeslinked.php index 40ebc2fe4f..4db89586f8 100644 --- a/includes/specials/SpecialRecentchangeslinked.php +++ b/includes/specials/SpecialRecentchangeslinked.php @@ -93,7 +93,7 @@ class SpecialRecentchangeslinked extends SpecialRecentChanges { $dbkey = $title->getDBkey(); $tables = array( 'recentchanges' ); - $select = array( $dbr->tableName( 'recentchanges' ) . '.*' ); + $select = RecentChange::selectFields(); $join_conds = array(); $query_options = array(); diff --git a/includes/specials/SpecialWatchlist.php b/includes/specials/SpecialWatchlist.php index 5dfc1133ef..688e0a50cb 100644 --- a/includes/specials/SpecialWatchlist.php +++ b/includes/specials/SpecialWatchlist.php @@ -272,7 +272,7 @@ class SpecialWatchlist extends SpecialPage { $form .= '
'; $tables = array( 'recentchanges', 'watchlist' ); - $fields = array( $dbr->tableName( 'recentchanges' ) . '.*' ); + $fields = RecentChange::selectFields(); $join_conds = array( 'watchlist' => array( 'INNER JOIN', -- 2.20.1