rcfeed: Ensure formatter (and other params) is passed to RCFeedEngine
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 4 Feb 2017 03:31:44 +0000 (03:31 +0000)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 4 Feb 2017 03:31:44 +0000 (03:31 +0000)
Follows-up 39a6e3dc4d. Class-based feeds are always given their parameters
by RCFeed::factory. However because the old getEngine() method insists
on creating its own object, the constructor parameters were not given.

Add it as optional parameter and pass it through there.

This is backwards-compatible still because before the 39a6e3dc4d refactor,
an RCFeedEngine also was not given information about any formatter and it
was the callers responsibility to format the line before calling send().
CentralAuth still uses it this way and that works fine. The core-caller
that expected the construction parameters since 39a6e3dc4d is hereby fixed.

The test couldn't catch this because it constructed the class instance there,
since PHPUnit does not support a mock class that is instantiated by foreign
code, and the parameter is passed there.

Bug: T156996
Bug: T157106
Change-Id: I83433cf57b6e040cdb69f3ad8807a999c4f931a5

includes/DefaultSettings.php
includes/changes/RecentChange.php
includes/rcfeed/RCFeed.php

index 42253ab..a1a4067 100644 (file)
@@ -6704,7 +6704,7 @@ $wgRCLinkDays = [ 1, 3, 7, 14, 30 ];
  *             'omit_bots' => true,
  *     ];
  * @example $wgRCFeeds['example'] = [
- *      'class' => 'ExampleRCFeed',
+ *             'class' => 'ExampleRCFeed',
  *     ];
  * @since 1.22
  */
index 507e6c3..dcab158 100644 (file)
@@ -429,7 +429,7 @@ class RecentChange {
         * @return RCFeedEngine The engine object
         * @throws MWException
         */
-       public static function getEngine( $uri ) {
+       public static function getEngine( $uri, $params = [] ) {
                // TODO: Merge into RCFeed::factory().
                global $wgRCEngines;
                $scheme = parse_url( $uri, PHP_URL_SCHEME );
@@ -442,7 +442,7 @@ class RecentChange {
                if ( defined( 'MW_PHPUNIT_TEST' ) && is_object( $wgRCEngines[$scheme] ) ) {
                        return $wgRCEngines[$scheme];
                }
-               return new $wgRCEngines[$scheme];
+               return new $wgRCEngines[$scheme]( $params );
        }
 
        /**
index 7e9ce60..284f68a 100644 (file)
@@ -48,7 +48,7 @@ abstract class RCFeed {
                        if ( !isset( $params['uri'] ) ) {
                                throw new Exception( "RCFeeds must have a 'class' or 'uri' set." );
                        }
-                       return RecentChange::getEngine( $params['uri'] );
+                       return RecentChange::getEngine( $params['uri'], $params );
                }
                $class = $params['class'];
                if ( !class_exists( $class ) ) {