Cleanup of includes/rcfeed
authorKunal Mehta <legoktm@gmail.com>
Sun, 5 Jan 2014 05:10:13 +0000 (21:10 -0800)
committerKunal Mehta <legoktm@gmail.com>
Sun, 5 Jan 2014 05:12:03 +0000 (21:12 -0800)
* Added license headers to everything
* Added @since tags for all classes
* Use wfParseUrl instead of parse_url
* Check for RedisConnectionPool::getConnection returning false

Change-Id: I7db808c0465bd869de3f2daa82444b5e3d1268c2

includes/rcfeed/IRCColourfulRCFeedFormatter.php
includes/rcfeed/JSONRCFeedFormatter.php
includes/rcfeed/RCFeedEngine.php
includes/rcfeed/RCFeedFormatter.php
includes/rcfeed/RedisPubSubFeedEngine.php
includes/rcfeed/UDPRCFeedEngine.php

index 507369f..ddbb548 100644 (file)
@@ -1,7 +1,32 @@
 <?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
+ */
+
+/**
+ * Generates a colourful notification intended for humans on IRC.
+ *
+ * @since 1.22
+ */
+
 class IRCColourfulRCFeedFormatter implements RCFeedFormatter {
        /**
-        * Generates a colourful notification intended for humans on IRC.
         * @see RCFeedFormatter::getLine
         */
        public function getLine( array $feed, RecentChange $rc, $actionComment ) {
index 144ec95..063cb90 100644 (file)
@@ -1,5 +1,30 @@
 <?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
+ */
+
+/**
+ * Formats a notification into the JSON format (http://www.json.org)
+ *
+ * @since 1.22
+ */
+
 class JSONRCFeedFormatter implements RCFeedFormatter {
        /**
         * Generates a notification that can be easily interpreted by a machine.
index f733bcb..022e317 100644 (file)
@@ -1,4 +1,29 @@
 <?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
+ */
+
+/**
+ * Interface for RC feed engines, which send formatted notifications
+ *
+ * @since 1.22
+ */
 interface RCFeedEngine {
        /**
         * Sends some text to the specified live feed.
index 6c9f804..2f15659 100644 (file)
@@ -1,7 +1,32 @@
 <?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
+ */
+
+/**
+ * Interface for RC feed formatters
+ *
+ * @since 1.22
+ */
 interface RCFeedFormatter {
        /**
-        * Formats the line for the live feed.
+        * Formats the line to be sent by an engine
         *
         * @param array $feed The feed, as configured in an associative array.
         * @param RecentChange $rc The RecentChange object showing what sort
index 4bcc133..b9023b6 100644 (file)
@@ -1,23 +1,48 @@
 <?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
+ */
+
+/**
+ * Emit a recent change notification via Redis Pub/Sub
+ *
+ * If the feed URI contains a path component, it will be used to generate a
+ * channel name by stripping the leading slash and replacing any remaining
+ * slashes with '.'. If no path component is present, the channel is set to
+ * 'rc'. If the URI contains a query string, its parameters will be parsed
+ * as RedisConnectionPool options.
+ *
+ * @example
+ * $wgRCFeeds['redis'] = array(
+ *      'formatter' => 'JSONRCFeedFormatter',
+ *      'uri'       => "redis://127.0.0.1:6379/rc.$wgDBname",
+ * );
+ *
+ * @since 1.22
+ */
 class RedisPubSubFeedEngine implements RCFeedEngine {
+
        /**
-        * Emit a recent change notification via Redis Pub/Sub
-        *
-        * If the feed URI contains a path component, it will be used to generate a
-        * channel name by stripping the leading slash and replacing any remaining
-        * slashes with '.'. If no path component is present, the channel is set to
-        * 'rc'. If the URI contains a query string, its parameters will be parsed
-        * as RedisConnectionPool options.
-        *
-        * @example $wgRCFeeds['redis'] = array(
-        *      'formatter' => 'JSONRCFeedFormatter',
-        *      'uri'       => "redis://127.0.0.1:6379/rc.$wgDBname",
-        * );
-        *
-        * @since 1.22
+        * @see RCFeedEngine::send
         */
        public function send( array $feed, $line ) {
-               $parsed = parse_url( $feed['uri'] );
+               $parsed = wfParseUrl( $feed['uri'] );
                $server = $parsed['host'];
                $options = array( 'serializer' => 'none' );
                $channel = 'rc';
@@ -36,6 +61,11 @@ class RedisPubSubFeedEngine implements RCFeedEngine {
                }
                $pool = RedisConnectionPool::singleton( $options );
                $conn = $pool->getConnection( $server );
-               $conn->publish( $channel, $line );
+               if ( $conn !== false ) {
+                       $conn->publish( $channel, $line );
+                       return true;
+               } else {
+                       return false;
+               }
        }
 }
index beeb73b..8554670 100644 (file)
@@ -1,7 +1,31 @@
 <?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
+ */
+
+/**
+ * Sends the notification to the specified host in a UDP packet.
+ * @since 1.22
+ */
+
 class UDPRCFeedEngine implements RCFeedEngine {
        /**
-        * Sends the notification to the specified host in a UDP packet.
         * @see RCFeedEngine::send
         */
        public function send( array $feed, $line ) {