X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=d215e9f56ec704cee75dc48b811e2983fb631212;hb=6fb0c3a26d50cd24e24eebd52a5c6e3e63eb6c82;hp=afad5c468b285fda9de735fa5122ef8feb1fe21a;hpb=3e83cc276aa498fbf5786a1f9bdd6285fa03cdc9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index afad5c468b..d215e9f56e 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. @@ -866,20 +886,13 @@ function wfParseUrl( $url ) { function wfExpandIRI( $url ) { return preg_replace_callback( '/((?:%[89A-F][0-9A-F])+)/i', - 'wfExpandIRI_callback', + function ( array $matches ) { + return urldecode( $matches[1] ); + }, wfExpandUrl( $url ) ); } -/** - * Private callback for wfExpandIRI - * @param array $matches - * @return string - */ -function wfExpandIRI_callback( $matches ) { - return urldecode( $matches[1] ); -} - /** * Make URL indexes, appropriate for the el_index field of externallinks. * @@ -1295,11 +1308,11 @@ function wfGetLangObj( $langcode = false ) { return $langcode; } - global $wgContLang, $wgLanguageCode; + global $wgLanguageCode; if ( $langcode === true || $langcode === $wgLanguageCode ) { # $langcode is the language code of the wikis content language object. # or it is a boolean and value is true - return $wgContLang; + return MediaWikiServices::getInstance()->getContentLanguage(); } global $wgLang; @@ -1317,7 +1330,7 @@ function wfGetLangObj( $langcode = false ) { # $langcode is a string, but not a valid language code; use content language. wfDebug( "Invalid language code passed to wfGetLangObj, falling back to content language.\n" ); - return $wgContLang; + return MediaWikiServices::getInstance()->getContentLanguage(); } /** @@ -2516,6 +2529,8 @@ function wfUsePHP( $req_ver ) { function wfUseMW( $req_ver ) { global $wgVersion; + wfDeprecated( __FUNCTION__, '1.26' ); + if ( version_compare( $wgVersion, (string)$req_ver, '<' ) ) { throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" ); } @@ -2659,28 +2674,6 @@ function wfGetPrecompiledData( $name ) { return false; } -/** - * @since 1.32 - * @param string[] $data Array with string keys/values to export - * @param string $header - * @return string PHP code - */ -function wfMakeStaticArrayFile( array $data, $header = 'Automatically generated' ) { - $format = "\t%s => %s,\n"; - $code = " $value ) { - $code .= sprintf( - $format, - var_export( $key, true ), - var_export( $value, true ) - ); - } - $code .= "];\n"; - return $code; -} - /** * Make a cache key for the local wiki. * @@ -3104,6 +3097,7 @@ function wfBCP47( $code ) { /** * Get a specific cache object. * + * @deprecated since 1.32, use ObjectCache::getInstance() instead * @param int|string $cacheType A CACHE_* constants, or other key in $wgObjectCaches * @return BagOStuff */ @@ -3114,11 +3108,11 @@ function wfGetCache( $cacheType ) { /** * Get the main cache object * + * @deprecated since 1.32, use ObjectCache::getLocalClusterInstance() instead * @return BagOStuff */ function wfGetMainCache() { - global $wgMainCacheType; - return ObjectCache::getInstance( $wgMainCacheType ); + return ObjectCache::getLocalClusterInstance(); } /**