RCFeed.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. * http://www.gnu.org/copyleft/gpl.html
  17. *
  18. * @file
  19. */
  20. /**
  21. * @see $wgRCFeeds
  22. * @since 1.29
  23. */
  24. abstract class RCFeed {
  25. /**
  26. * @param array $params
  27. */
  28. public function __construct( array $params = [] ) {
  29. }
  30. /**
  31. * Dispatch the recent changes notification.
  32. *
  33. * @param RecentChange $rc
  34. * @param string|null $actionComment
  35. * @return bool Success
  36. */
  37. abstract public function notify( RecentChange $rc, $actionComment = null );
  38. /**
  39. * @param array $params
  40. * @return RCFeed
  41. * @throws Exception
  42. */
  43. final public static function factory( array $params ) {
  44. if ( !isset( $params['class'] ) ) {
  45. if ( !isset( $params['uri'] ) ) {
  46. throw new Exception( "RCFeeds must have a 'class' or 'uri' set." );
  47. }
  48. return RecentChange::getEngine( $params['uri'], $params );
  49. }
  50. $class = $params['class'];
  51. if ( !class_exists( $class ) ) {
  52. throw new Exception( "Unknown class '$class'." );
  53. }
  54. return new $class( $params );
  55. }
  56. }