Fix handling of prot-rel URLs in SiteObject.
authordaniel <daniel.kinzler@wikimedia.de>
Wed, 31 Oct 2012 19:16:36 +0000 (20:16 +0100)
committerdaniel <daniel.kinzler@wikimedia.de>
Wed, 31 Oct 2012 19:16:36 +0000 (20:16 +0100)
Previously, getProtocol() would return null for a protocol relative URL,
but the database field sites_protocol does not allow null as a value.
Changed getProtocol() to return an empty string instead.

Change-Id: I7e22cc3c3d8dca17a28fc4627083d5d2cb253887

includes/site/SiteObject.php

index 6470c86..adb2217 100644 (file)
@@ -157,10 +157,20 @@ class SiteObject extends ORMRow implements Site {
                $path = $this->getLinkPath();
 
                if ( $path === false ) {
-                       return false;
+                       return '';
+               }
+
+               $protocol = parse_url( $path, PHP_URL_SCHEME );
+
+               if ( $protocol === false ) { // malformed URL
+                       throw new MWException( "failed to parse URL $path" );
+               }
+
+               if ( $protocol === null ) { // no schema
+                       $protocol = ''; // used for protocol relative URLs
                }
 
-               return parse_url( $path, PHP_URL_SCHEME );
+               return $protocol;
        }
 
        /**