Nik has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/116989

Change subject: Adjusted publisher library to coding guidelines.
......................................................................

Adjusted publisher library to coding guidelines.

Change-Id: I11ea7f900130fc33f2faac50dca683bff63678ac
---
M lib/publisher.php
1 file changed, 107 insertions(+), 61 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PubSubHubbub 
refs/changes/89/116989/1

diff --git a/lib/publisher.php b/lib/publisher.php
index 0bf0ea8..588aaec 100644
--- a/lib/publisher.php
+++ b/lib/publisher.php
@@ -1,86 +1,132 @@
 <?php
+/**
+ * This file is part of the PubSubHubbub Extension to MediaWiki
+ * https://www.mediawiki.org/wiki/Extension:PubSubHubbub
+ *
+ * @section LICENSE
+ * 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
+ */
 
-// a PHP client library for pubsubhubbub
-// as defined at http://code.google.com/p/pubsubhubbub/
-// written by Josh Fraser | joshfraser.com | [email protected]
-// Released under Apache License 2.0
-
+/**
+ * A publisher client library for PubSubHubbub.
+ *
+ * @see http://code.google.com/p/pubsubhubbub/
+ * @license Apache License 2.0
+ * @author Josh Fraser <[email protected]>,
+ *         Sebastian Brücker <[email protected]>
+ */
 class Publisher {
-       
+
+       /**
+        * @var string
+        */
        protected $hub_url;
+       /**
+        * @var string
+        */
        protected $last_response;
-       
-       // create a new Publisher
-       public function __construct($hub_url) {
+
+       /**
+        * Create a new Publisher.
+        *
+        * @param $hub_url string The URL of the hub to publish to.
+        */
+       public function __construct ( $hub_url ) {
+               if ( !isset ( $hub_url ) )
+                       throw new Exception ( "Please specify a hub url" );
                
-               if (!isset($hub_url))
-                       throw new Exception('Please specify a hub url');
-               
-               if (!preg_match("|^https?://|i",$hub_url)) 
-                       throw new Exception('The specified hub url does not 
appear to be valid: '.$hub_url);
-                       
+               if ( !preg_match ( "|^https?://|i" , $hub_url ) )
+                       throw new Exception ( "The specified hub url does not 
appear to be valid: " . $hub_url );
+
                $this->hub_url = $hub_url;
        }
 
-       // accepts either a single url or an array of urls
-       public function publish_update($topic_urls, $http_function = false) {
-               if (!isset($topic_urls))
-                       throw new Exception('Please specify a topic url');
-               
-               // check that we're working with an array
-               if (!is_array($topic_urls)) {
-                       $topic_urls = array($topic_urls);
-               }
-               
-               // set the mode to publish
-               $post_string = "hub.mode=publish";
-               // loop through each topic url 
-               foreach ($topic_urls as $topic_url) {
+       /**
+        * Send an update signal to the hub.
+        *
+        * @param $topic_urls string[]|string The URL or a list of URLs to 
publish.
+        * @return bool whether the HTTP operation succeeded.
+        */
+       public function publish_update ( $topic_urls, $http_function = false ) {
+               if ( !isset ( $topic_urls ) )
+                       throw new Exception ( "Please specify a topic URL" );
 
-                       // lightweight check that we're actually working w/ a 
valid url
-                       if (!preg_match("|^https?://|i",$topic_url)) 
-                               throw new Exception('The specified topic url 
does not appear to be valid: '.$topic_url);
-                       
-                       // append the topic url parameters
-                       $post_string .= "&hub.url=".urlencode($topic_url);
+               // Check that we're working with an array
+               if ( !is_array ( $topic_urls ) ) {
+                       $topic_urls = array( $topic_urls );
                }
                
-               // make the http post request and return true/false
-               // easy to over-write to use your own http function
-               if ($http_function)
-                       return $http_function($this->hub_url,$post_string);
+               // Set the mode to publish
+               $post_string = "hub.mode=publish";
+               // Loop through each topic URL 
+               foreach ( $topic_urls as $topic_url ) {
+
+                       // Lightweight check that we're actually working with a 
valid url
+                       if ( !preg_match ( "|^https?://|i", $topic_url ) )
+                               throw new Exception ( "The specified topic URL 
does not appear to be valid: " . $topic_url );
+
+                       // Append the topic URL parameters
+                       $post_string .= "&hub.url=" . urlencode ($topic_url );
+               }
+               
+               // Send the HTTP POST request and return true/false
+               // Easy to over-write to use your own HTTP function
+               if ( $http_function )
+                       return $http_function ( $this->hub_url, $post_string );
                else
-                       return $this->http_post($this->hub_url,$post_string);
+                       return $this->http_post ( $this->hub_url, $post_string 
);
        }
 
-       // returns any error message from the latest request
-       public function last_response() {
+       /**
+        * @return string The error message from the latest request.
+        */
+       public function last_response () {
                return $this->last_response;
        }
-       
-       // default http function that uses curl to post to the hub endpoint
-       private function http_post($url, $post_string) {
-               
-               // add any additional curl options here
-               $options = array(CURLOPT_URL => $url,
-                                                CURLOPT_POST => true,
-                                                CURLOPT_POSTFIELDS => 
$post_string,
-                                                CURLOPT_USERAGENT => 
"PubSubHubbub-Publisher-PHP/1.0");
 
-               $ch = curl_init();
-               curl_setopt_array($ch, $options);
+       /**
+        * Default HTTP function that uses curl to post to the hub endpoint.
+        *
+        * @param $url string The URL to send the POST request to.
+        * @param $post_string string The POST data.
+        * @return bool whether the HTTP operation succeeded.
+        */
+       private function http_post ( $url, $post_string ) {
+               $options = array(
+                       CURLOPT_URL => $url,
+                       CURLOPT_POST => true,
+                       CURLOPT_POSTFIELDS => $post_string,
+                       CURLOPT_USERAGENT => 
"MediaWiki-PubSubHubbub-Publisher/1.0"
+               );
 
-               $response = curl_exec($ch);
+               $ch = curl_init ();
+               curl_setopt_array ( $ch, $options );
+
+               $response = curl_exec ( $ch );
                $this->last_response = $response;
-               $info = curl_getinfo($ch);
+               $info = curl_getinfo ( $ch );
 
-               curl_close($ch);
+               curl_close ( $ch );
                
-               // all good
-               if ($info['http_code'] == 204) 
+               // All good
+               if ( $info['http_code'] == 204 )
                        return true;
-               return false;   
+               return false;
        }
-}
 
-?>
\ No newline at end of file
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/116989
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11ea7f900130fc33f2faac50dca683bff63678ac
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PubSubHubbub
Gerrit-Branch: master
Gerrit-Owner: Nik <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to