From: Jack Phoenix Date: Sun, 26 Apr 2015 22:29:57 +0000 (+0300) Subject: Use array_merge instead of the plus operator so that hooked functions are X-Git-Tag: 1.31.0-rc.0~11575^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=bf059d26337b40589948797715c5e4badf87c787;p=lhc%2Fweb%2Fwiklou.git Use array_merge instead of the plus operator so that hooked functions are able to override the ORDER BY condition This is needed to implement wikiHow's "reverse order" option cleanly, without any core hacks. Without this changeset, you can hook into ChangesListSpecialPageQuery hook, but it will be impossible to override the ORDER BY conditions to get rid of the DESC sort order when the reverse param is set to 1 in the URL. For a live example of the feature in question, see http://www.wikihow.com/Special:RecentChanges (tick the "reverse order" box, press button and take a look at the results). For the code behind this feature, see /extensions/wikihow/hooks/SpecialPagesHooks.php and /extensions/wikihow/hooks/WikihowHooks.php on the wikiHow codebase. Change-Id: I2177aed9e4807b90cbde4baf33083da492d3d194 --- diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index 1387988c49..7dc115828b 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -233,14 +233,21 @@ class SpecialRecentChanges extends ChangesListSpecialPage { return false; } - // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough - // knowledge to use an index merge if it wants (it may use some other index though). + // array_merge() is used intentionally here so that hooks can, should + // they so desire, override the ORDER BY / LIMIT condition(s); prior to + // MediaWiki 1.26 this used to use the plus operator instead, which meant + // that extensions weren't able to change these conditions + $query_options = array_merge( array( + 'ORDER BY' => 'rc_timestamp DESC', + 'LIMIT' => $opts['limit'] ), $query_options ); $rows = $dbr->select( $tables, $fields, + // rc_new is not an ENUM, but adding a redundant rc_new IN (0,1) gives mysql enough + // knowledge to use an index merge if it wants (it may use some other index though). $conds + array( 'rc_new' => array( 0, 1 ) ), __METHOD__, - array( 'ORDER BY' => 'rc_timestamp DESC', 'LIMIT' => $opts['limit'] ) + $query_options, + $query_options, $join_conds );