Use array_merge instead of the plus operator so that hooked functions are
authorJack Phoenix <jack@countervandalism.net>
Sun, 26 Apr 2015 22:29:57 +0000 (01:29 +0300)
committerJack Phoenix <jack@countervandalism.net>
Mon, 27 Apr 2015 22:38:48 +0000 (01:38 +0300)
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

includes/specials/SpecialRecentchanges.php

index 1387988..7dc1158 100644 (file)
@@ -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
                );