ChangesListSpecialPage: Implement two new hooks superseding 4 old ones
authorBartosz Dziewoński <matma.rex@gmail.com>
Wed, 8 Jan 2014 17:17:08 +0000 (18:17 +0100)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 11 Apr 2014 20:53:35 +0000 (22:53 +0200)
Old hooks (called by SpecialWatchlist, SpecialRecentChanges and
SpecialRecentChangesLinked) have been deprecated, but I'm not planning
to remove them anytime soon. (They have lots of usages in extensions
as of this writing.)

The new hooks (and their deprecated friends) are:

* ChangesListSpecialPageFilters:
  * Replaces: SpecialRecentChangesFilters and SpecialWatchlistFilters
  * The signature for this one is exactly the same as signatures for
    the other two. We might want to pass something else than $this
    here…

* ChangesListSpecialPageQuery
  * Replaces: SpecialRecentChangesQuery and SpecialWatchlistQuery
  * These hooks have wildly different signatures. The new one is a
    superset of the old ones, in a more reasonable order, with the
    addition of the name of the special page we're doing right now.

Change-Id: I9cceda5d2dcfc53c852c5682c466b48ad8f31202

docs/hooks.txt
includes/specialpage/ChangesListSpecialPage.php
includes/specials/SpecialRecentchanges.php
includes/specials/SpecialRecentchangeslinked.php
includes/specials/SpecialWatchlist.php

index ff1d6a1..a9bc736 100644 (file)
@@ -844,6 +844,21 @@ $changesList: ChangesList instance
 $rows: The data that will be rendered. May be a ResultWrapper instance or
   an array.
 
+'ChangesListSpecialPageFilters': Called after building form options on pages inheriting from ChangesListSpecialPage (in core: RecentChanges, RecentChangesLinked and Watchlist).
+$special: ChangesListSpecialPage instance
+&$filters: associative array of filter definitions. The keys are the HTML
+  name/URL parameters. Each key maps to an associative array with a 'msg'
+  (message key) and a 'default' value.
+
+'ChangesListSpecialPageQuery': Called when building SQL query on pages inheriting from ChangesListSpecialPage (in core: RecentChanges, RecentChangesLinked and Watchlist).
+$name: name of the special page, e.g. 'Watchlist'
+&$tables: array of tables to be queried
+&$fields: array of columns to select
+&$conds: array of WHERE conditionals for query
+&$query_options: array of options for the database request
+&$join_conds: join conditions for the tables
+$opts: FormOptions for this request
+
 'Collation::factory': Called if $wgCategoryCollation is an unknown collation.
 $collationName: Name of the collation in question
 &$collationObject: Null. Replace with a subclass of the Collation class that
@@ -2369,7 +2384,7 @@ use this to change some selection criteria or substitute a different title.
   result from the normal query
 
 'SpecialRecentChangesFilters': Called after building form options at
-RecentChanges.
+RecentChanges. Deprecated, use ChangesListSpecialPageFilters instead.
 $special: the special page object
 &$filters: associative array of filter definitions. The keys are the HTML
   name/URL parameters. Each key maps to an associative array with a 'msg'
@@ -2381,7 +2396,8 @@ SpecialRecentChanges.
 $opts: FormOptions for this request
 
 'SpecialRecentChangesQuery': Called when building SQL query for
-SpecialRecentChanges and SpecialRecentChangesLinked.
+SpecialRecentChanges and SpecialRecentChangesLinked. Deprecated, use
+ChangesListSpecialPageQuery instead.
 &$conds: array of WHERE conditionals for query
 &$tables: array of tables to be queried
 &$join_conds: join conditions for the tables
@@ -2471,12 +2487,14 @@ $wgVersion: Current $wgVersion for you to use
 &$versionUrl: Raw url to link to (eg: release notes)
 
 'SpecialWatchlistFilters': Called after building form options at Watchlist.
+Deprecated, use ChangesListSpecialPageFilters instead.
 $special: the special page object
 &$filters: associative array of filter definitions. The keys are the HTML
   name/URL parameters. Each key maps to an associative array with a 'msg'
   (message key) and a 'default' value.
 
 'SpecialWatchlistQuery': Called when building sql query for SpecialWatchlist.
+Deprecated, use ChangesListSpecialPageQuery instead.
 &$conds: array of WHERE conditionals for query
 &$tables: array of tables to be queried
 &$join_conds: join conditions for the tables
index 14ac401..bc0b8ff 100644 (file)
@@ -151,8 +151,12 @@ abstract class ChangesListSpecialPage extends SpecialPage {
         * @return array Map of filter URL param names to properties (msg/default)
         */
        protected function getCustomFilters() {
-               // @todo Fire a Special{$this->getName()}Filters hook here
-               return array();
+               if ( $this->customFilters === null ) {
+                       $this->customFilters = array();
+                       wfRunHooks( 'ChangesListSpecialPageFilters', array( $this, &$this->customFilters ) );
+               }
+
+               return $this->customFilters;
        }
 
        /**
@@ -286,13 +290,11 @@ abstract class ChangesListSpecialPage extends SpecialPage {
                        ''
                );
 
-               // @todo Fire a Special{$this->getName()}Query hook here
-               // @todo Uncomment and document
-               // if ( !wfRunHooks( 'ChangesListSpecialPageQuery',
-               //      array( &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) )
-               // ) {
-               //      return false;
-               // }
+               if ( !wfRunHooks( 'ChangesListSpecialPageQuery',
+                       array( $this->getName(), &$tables, &$fields, &$conds, &$query_options, &$join_conds, $opts ) )
+               ) {
+                       return false;
+               }
 
                $dbr = $this->getDB();
 
index 72fa9bc..f1a31a5 100644 (file)
@@ -94,8 +94,8 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
         */
        protected function getCustomFilters() {
                if ( $this->customFilters === null ) {
-                       $this->customFilters = array();
-                       wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ) );
+                       $this->customFilters = parent::getCustomFilters();
+                       wfRunHooks( 'SpecialRecentChangesFilters', array( $this, &$this->customFilters ), '1.23' );
                }
 
                return $this->customFilters;
@@ -230,7 +230,8 @@ class SpecialRecentChanges extends ChangesListSpecialPage {
                );
 
                if ( !wfRunHooks( 'SpecialRecentChangesQuery',
-                       array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ) )
+                       array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$fields ),
+                       '1.23' )
                ) {
                        return false;
                }
index 526e949..e73cabc 100644 (file)
@@ -110,7 +110,8 @@ class SpecialRecentChangesLinked extends SpecialRecentChanges {
                );
 
                if ( !wfRunHooks( 'SpecialRecentChangesQuery',
-                       array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ) )
+                       array( &$conds, &$tables, &$join_conds, $opts, &$query_options, &$select ),
+                       '1.23' )
                ) {
                        return false;
                }
index c1fe21a..1345b76 100644 (file)
@@ -107,8 +107,8 @@ class SpecialWatchlist extends ChangesListSpecialPage {
         */
        protected function getCustomFilters() {
                if ( $this->customFilters === null ) {
-                       $this->customFilters = array();
-                       wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ) );
+                       $this->customFilters = parent::getCustomFilters();
+                       wfRunHooks( 'SpecialWatchlistFilters', array( $this, &$this->customFilters ), '1.23' );
                }
 
                return $this->customFilters;
@@ -258,7 +258,8 @@ class SpecialWatchlist extends ChangesListSpecialPage {
                );
 
                wfRunHooks( 'SpecialWatchlistQuery',
-                       array( &$conds, &$tables, &$join_conds, &$fields, $opts ) );
+                       array( &$conds, &$tables, &$join_conds, &$fields, $opts ),
+                       '1.23' );
 
                return $dbr->select(
                        $tables,