wiki.techinc.nl/includes/rcfeed/RCFeed.php
Timo Tijhof 2e37dc5b3c 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
2017-02-04 03:31:44 +00:00

59 lines
1.6 KiB
PHP

<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
*/
/**
* @see $wgRCFeeds
* @since 1.29
*/
abstract class RCFeed {
/**
* @param array $params
*/
public function __construct( array $params = [] ) {
}
/**
* Dispatch the recent changes notification.
*
* @param RecentChange $rc
* @param string|null $actionComment
* @return bool Success
*/
abstract public function notify( RecentChange $rc, $actionComment = null );
/**
* @param array $params
* @return RCFeed
* @throws Exception
*/
final public static function factory( array $params ) {
if ( !isset( $params['class'] ) ) {
if ( !isset( $params['uri'] ) ) {
throw new Exception( "RCFeeds must have a 'class' or 'uri' set." );
}
return RecentChange::getEngine( $params['uri'], $params );
}
$class = $params['class'];
if ( !class_exists( $class ) ) {
throw new Exception( "Unknown class '$class'." );
}
return new $class( $params );
}
}