Logic optimization for wfExpandUrl()
authorYuri Astrakhan <yurik@wikimedia.org>
Sat, 16 Nov 2013 19:55:08 +0000 (14:55 -0500)
committerYuri Astrakhan <yurik@wikimedia.org>
Sat, 16 Nov 2013 19:55:08 +0000 (14:55 -0500)
removed redundant checks of the same variable, making the code
slightly more efficient

Change-Id: Ice4d3c45e80ca1214e2c36444baf0ce87b15a59b

includes/GlobalFunctions.php

index 1eb5c3e..688300a 100644 (file)
@@ -496,17 +496,18 @@ function wfAppendQuery( $url, $query ) {
  */
 function wfExpandUrl( $url, $defaultProto = PROTO_CURRENT ) {
        global $wgServer, $wgCanonicalServer, $wgInternalServer, $wgRequest;
-       $serverUrl = $wgServer;
        if ( $defaultProto === PROTO_CANONICAL ) {
                $serverUrl = $wgCanonicalServer;
-       }
-       // Make $wgInternalServer fall back to $wgServer if not set
-       if ( $defaultProto === PROTO_INTERNAL && $wgInternalServer !== false ) {
+       } elseif ( $defaultProto === PROTO_INTERNAL && $wgInternalServer !== false ) {
+               // Make $wgInternalServer fall back to $wgServer if not set
                $serverUrl = $wgInternalServer;
+       } else {
+               $serverUrl = $wgServer;
+               if ( $defaultProto === PROTO_CURRENT ) {
+                       $defaultProto = $wgRequest->getProtocol() . '://';
+               }
        }
-       if ( $defaultProto === PROTO_CURRENT ) {
-               $defaultProto = $wgRequest->getProtocol() . '://';
-       }
+
 
        // Analyze $serverUrl to obtain its protocol
        $bits = wfParseUrl( $serverUrl );