From: Amir Sarabadani Date: Wed, 14 Nov 2018 20:53:13 +0000 (+0100) Subject: Split ChangeTags::modifyDisplayQuery() to two smaller functions X-Git-Tag: 1.34.0-rc.0~3434^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=6026d27c620c9c5f137007390a6e1b456c751938;p=lhc%2Fweb%2Fwiklou.git Split ChangeTags::modifyDisplayQuery() to two smaller functions This would be useful for replacing cases of tag_summary Bug: T209525 Change-Id: If0c949fe190934fe5318d9c5ff9dfb13d52adc56 --- diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index 0e360098fc..c6e8e1fb89 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -788,7 +788,7 @@ class ChangeTags { public static function modifyDisplayQuery( &$tables, &$fields, &$conds, &$join_conds, &$options, $filter_tag = '' ) { - global $wgUseTagFilter, $wgChangeTagsSchemaMigrationStage; + global $wgChangeTagsSchemaMigrationStage, $wgUseTagFilter; // Normalize to arrays $tables = (array)$tables; @@ -796,6 +796,8 @@ class ChangeTags { $conds = (array)$conds; $options = (array)$options; + $fields['ts_tags'] = self::makeTagSummarySubquery( $tables ); + // Figure out which ID field to use if ( in_array( 'recentchanges', $tables ) ) { $join_cond = 'ct_rc_id=rc_id'; @@ -809,20 +811,6 @@ class ChangeTags { throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' ); } - $tagTables[] = 'change_tag'; - if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tagTables[] = 'change_tag_def'; - $join_cond_ts_tags = [ 'change_tag_def' => [ 'INNER JOIN', 'ct_tag_id=ctd_id' ] ]; - $field = 'ctd_name'; - } else { - $field = 'ct_tag'; - $join_cond_ts_tags = []; - } - - $fields['ts_tags'] = wfGetDB( DB_REPLICA )->buildGroupConcatField( - ',', $tagTables, $field, $join_cond, $join_cond_ts_tags - ); - if ( $wgUseTagFilter && $filter_tag ) { // Somebody wants to filter on a tag. // Add an INNER JOIN on change_tag @@ -858,6 +846,48 @@ class ChangeTags { } } + /** + * Make the tag summary subquery based on the given tables and return it. + * + * @param string|array $tables Table names, see Database::select + * + * @return string tag summary subqeury + * @throws MWException When unable to determine appropriate JOIN condition for tagging + */ + public static function makeTagSummarySubquery( $tables ) { + global $wgChangeTagsSchemaMigrationStage; + + // Normalize to arrays + $tables = (array)$tables; + + // Figure out which ID field to use + if ( in_array( 'recentchanges', $tables ) ) { + $join_cond = 'ct_rc_id=rc_id'; + } elseif ( in_array( 'logging', $tables ) ) { + $join_cond = 'ct_log_id=log_id'; + } elseif ( in_array( 'revision', $tables ) ) { + $join_cond = 'ct_rev_id=rev_id'; + } elseif ( in_array( 'archive', $tables ) ) { + $join_cond = 'ct_rev_id=ar_rev_id'; + } else { + throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' ); + } + + $tagTables[] = 'change_tag'; + if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { + $tagTables[] = 'change_tag_def'; + $join_cond_ts_tags = [ 'change_tag_def' => [ 'INNER JOIN', 'ct_tag_id=ctd_id' ] ]; + $field = 'ctd_name'; + } else { + $field = 'ct_tag'; + $join_cond_ts_tags = []; + } + + return wfGetDB( DB_REPLICA )->buildGroupConcatField( + ',', $tagTables, $field, $join_cond, $join_cond_ts_tags + ); + } + /** * Build a text box to select a change tag *