New hook accommodates non-revision rc queries
authorErik Bernhardson <ebernhardson@wikimedia.org>
Tue, 15 Oct 2013 22:21:34 +0000 (15:21 -0700)
committerAndrew Garrett <agarrett@wikimedia.org>
Wed, 23 Oct 2013 23:38:54 +0000 (10:38 +1100)
Within Special:RecentChanges the default non-extended query contains

    ( rc_this_oldid=page_latest OR rc_type=3 )

Wikidata has previously used the SpecialWatchlistQuery hook to look for
this exact string and change rc_type=3 to rc_type IN (3,5).  Flow is another
type of change that doesn't have a matching row in revisions to match
page_latest for and needs to be added to this query.

This patch adds a new hook, SpecialWatchlistGetNonRevisionTypes, which allows
different extensions to add to a list of values for rc_type (or rc_source once
85787 is merged).  This will allow multiple extensions to affect the resulting
query without them breaking eachother.

Change-Id: Id6916fe999c0faa38de878b7b5687e7ea00901bd

RELEASE-NOTES-1.22
cache/.htaccess [changed mode: 0644->0755]
docs/hooks.txt
includes/specials/SpecialWatchlist.php

index 4cfd661..d6a75ba 100644 (file)
@@ -253,6 +253,9 @@ production.
   output in a HTML comment.
 * The 'UnwatchArticle' and 'WatchArticle' hooks now support a Status object
   instead of just a boolean return value to abort the hook.
+* Added a hook, SpecialWatchlistGetNonRevisionTypes, to allow extensions
+  with custom recentchanges entries to hook into the Watchlist without 
+  clobbering each other.
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
old mode 100644 (file)
new mode 100755 (executable)
index 26032cb..5aaf596 100644 (file)
@@ -2365,6 +2365,11 @@ $special: the special page object
 &$fields: array of query fields
 $values: array of variables with watchlist options
 
+'SpecialWatchlistGetNonRevisionTypes': Called when building sql query for
+SpecialWatchlist. Allows extensions to register custom values they have 
+inserted to rc_type so they can be returned as part of the watchlist.
+&$nonRevisionTypes: array of values in the rc_type field of recentchanges table
+
 'TestCanonicalRedirect': Called when about to force a redirect to a canonical
 URL for a title when we have no other parameters on the URL. Gives a chance for
 extensions that alter page view behavior radically to abort that redirect or
index 11632a3..4afa279 100644 (file)
@@ -208,7 +208,21 @@ class SpecialWatchlist extends SpecialPage {
                        $usePage = false;
                } else {
                        # Top log Ids for a page are not stored
-                       $conds[] = 'rc_this_oldid=page_latest OR rc_type=' . RC_LOG;
+                       $nonRevisionTypes = array( RC_LOG );
+                       wfRunHooks( 'SpecialWatchlistGetNonRevisionTypes', array( &$nonRevisionTypes ) );
+                       if ( $nonRevisionTypes ) {
+                               if ( count( $nonRevisionTypes ) === 1 ) {
+                                       // if only one use an equality instead of IN condition
+                                       $nonRevisionTypes = reset( $nonRevisionTypes );
+                               }
+                               $conds[] = $dbr->makeList(
+                                       array(
+                                               'rc_this_oldid=page_latest',
+                                               'rc_type' => $nonRevisionTypes,
+                                       ),
+                                       LIST_OR
+                               );
+                       }
                        $limitWatchlist = 0;
                        $usePage = true;
                }