Merge "Correct recent schema changes for MSSQL, Oracle"
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index eec4216..aa8aee5 100644 (file)
@@ -548,17 +548,24 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
        } elseif ( substr( $url, 0, 1 ) == '/' ) {
                // If $serverUrl is protocol-relative, prepend $defaultProtoWithoutSlashes,
                // otherwise leave it alone.
-               $url = ( $serverHasProto ? '' : $defaultProtoWithoutSlashes ) . $serverUrl . $url;
+               if ( $serverHasProto ) {
+                       $url = $serverUrl . $url;
+               } else {
+                       // If an HTTPS URL is synthesized from a protocol-relative $wgServer, allow the
+                       // user to override the port number (T67184)
+                       if ( $defaultProto === PROTO_HTTPS && $wgHttpsPort != 443 ) {
+                               if ( isset( $bits['port'] ) ) {
+                                       throw new Exception( 'A protocol-relative $wgServer may not contain a port number' );
+                               }
+                               $url = $defaultProtoWithoutSlashes . $serverUrl . ':' . $wgHttpsPort . $url;
+                       } else {
+                               $url = $defaultProtoWithoutSlashes . $serverUrl . $url;
+                       }
+               }
        }
 
        $bits = wfParseUrl( $url );
 
-       // ensure proper port for HTTPS arrives in URL
-       // https://phabricator.wikimedia.org/T67184
-       if ( $defaultProto === PROTO_HTTPS && $wgHttpsPort != 443 ) {
-               $bits['port'] = $wgHttpsPort;
-       }
-
        if ( $bits && isset( $bits['path'] ) ) {
                $bits['path'] = wfRemoveDotSegments( $bits['path'] );
                return wfAssembleUrl( $bits );
@@ -574,6 +581,19 @@ function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
        return false;
 }
 
+/**
+ * Get the wiki's "server", i.e. the protocol and host part of the URL, with a
+ * protocol specified using a PROTO_* constant as in wfExpandUrl()
+ *
+ * @since 1.32
+ * @param string|int|null $proto One of the PROTO_* constants.
+ * @return string The URL
+ */
+function wfGetServerUrl( $proto ) {
+       $url = wfExpandUrl( '/', $proto );
+       return substr( $url, 0, -1 );
+}
+
 /**
  * This function will reassemble a URL parsed with wfParseURL.  This is useful
  * if you need to edit part of a URL and put it back together.