From 2e37dc5b3cfcf0265e67903470d95e6f1f4f8d27 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 4 Feb 2017 03:31:44 +0000 Subject: [PATCH] rcfeed: Ensure formatter (and other params) is passed to RCFeedEngine 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 | 2 +- includes/changes/RecentChange.php | 4 ++-- includes/rcfeed/RCFeed.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 42253abb07..a1a4067f56 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -6704,7 +6704,7 @@ $wgRCLinkDays = [ 1, 3, 7, 14, 30 ]; * 'omit_bots' => true, * ]; * @example $wgRCFeeds['example'] = [ - * 'class' => 'ExampleRCFeed', + * 'class' => 'ExampleRCFeed', * ]; * @since 1.22 */ diff --git a/includes/changes/RecentChange.php b/includes/changes/RecentChange.php index 507e6c3646..dcab158ddb 100644 --- a/includes/changes/RecentChange.php +++ b/includes/changes/RecentChange.php @@ -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 ); } /** diff --git a/includes/rcfeed/RCFeed.php b/includes/rcfeed/RCFeed.php index 7e9ce606ad..284f68a2da 100644 --- a/includes/rcfeed/RCFeed.php +++ b/includes/rcfeed/RCFeed.php @@ -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 ) ) { -- 2.20.1