* Handles selecting tags, and filtering.
* Needs $tables to be set up properly, so we can figure out which join conditions to use.
*
- * @param string|array $tables Table names, see Database::select
- * @param string|array $fields Fields used in query, see Database::select
- * @param string|array $conds Conditions used in query, see Database::select
- * @param array $join_conds Join conditions, see Database::select
- * @param array $options Options, see Database::select
- * @param bool|string $filter_tag Tag to select on
+ * WARNING: If $filter_tag contains more than one tag, this function will add DISTINCT,
+ * which may cause performance problems for your query unless you put the ID field of your
+ * table at the end of the ORDER BY, and set a GROUP BY equal to the ORDER BY. For example,
+ * if you had ORDER BY foo_timestamp DESC, you will now need GROUP BY foo_timestamp, foo_id
+ * ORDER BY foo_timestamp DESC, foo_id DESC.
+ *
+ * @param string|array &$tables Table names, see Database::select
+ * @param string|array &$fields Fields used in query, see Database::select
+ * @param string|array &$conds Conditions used in query, see Database::select
+ * @param array &$join_conds Join conditions, see Database::select
+ * @param string|array &$options Options, see Database::select
+ * @param string|array $filter_tag Tag(s) to select on
*
* @throws MWException When unable to determine appropriate JOIN condition for tagging
*/
public static function modifyDisplayQuery( &$tables, &$fields, &$conds,
- &$join_conds, &$options, $filter_tag = false ) {
- global $wgRequest, $wgUseTagFilter;
+ &$join_conds, &$options, $filter_tag = '' ) {
+ global $wgUseTagFilter;
- if ( $filter_tag === false ) {
- $filter_tag = $wgRequest->getVal( 'tagfilter' );
- }
+ // Normalize to arrays
+ $tables = (array)$tables;
+ $fields = (array)$fields;
+ $conds = (array)$conds;
+ $options = (array)$options;
- // Figure out which conditions can be done.
+ // Figure out which ID field to use
if ( in_array( 'recentchanges', $tables ) ) {
$join_cond = 'ct_rc_id=rc_id';
} elseif ( in_array( 'logging', $tables ) ) {
$tables[] = 'change_tag';
$join_conds['change_tag'] = [ 'INNER JOIN', $join_cond ];
- $conds['ct_tag'] = explode( '|', $filter_tag );
+ $conds['ct_tag'] = $filter_tag;
+ if (
+ is_array( $filter_tag ) && count( $filter_tag ) > 1 &&
+ !in_array( 'DISTINCT', $options )
+ ) {
+ $options[] = 'DISTINCT';
+ }
}
}
// tags cannot contain commas (used as a delimiter in tag_summary table),
// pipe (used as a delimiter between multiple tags in
- // modifyDisplayQuery), or slashes (would break tag description messages in
+ // SpecialRecentchanges and friends), or slashes (would break tag description messages in
// MediaWiki namespace)
if ( strpos( $tag, ',' ) !== false || strpos( $tag, '|' ) !== false
|| strpos( $tag, '/' ) !== false ) {
*
* @see listSoftwareDefinedTags
* @deprecated since 1.28
+ * @return array
*/
public static function listExtensionDefinedTags() {
wfDeprecated( __METHOD__, '1.28' );