X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=618fa4cab524933354081a2abd1a2a5cdefbce3f;hb=92e3d2f1a39c7048119efe9d1690b72480e84799;hp=3fa91fa7009a87231d7e5d971b419508eb68d013;hpb=5c6a0cf57d98ed517b9470ba21e5b9e6141e0ea8;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3fa91fa700..618fa4cab5 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -39,59 +39,6 @@ use MediaWiki\Session\SessionManager; * PHP extensions may be included here. */ -if ( !function_exists( 'mb_substr' ) ) { - /** - * @codeCoverageIgnore - * @see Fallback::mb_substr - * @return string - */ - function mb_substr( $str, $start, $count = 'end' ) { - return Fallback::mb_substr( $str, $start, $count ); - } - - /** - * @codeCoverageIgnore - * @see Fallback::mb_substr_split_unicode - * @return int - */ - function mb_substr_split_unicode( $str, $splitPos ) { - return Fallback::mb_substr_split_unicode( $str, $splitPos ); - } -} - -if ( !function_exists( 'mb_strlen' ) ) { - /** - * @codeCoverageIgnore - * @see Fallback::mb_strlen - * @return int - */ - function mb_strlen( $str, $enc = '' ) { - return Fallback::mb_strlen( $str, $enc ); - } -} - -if ( !function_exists( 'mb_strpos' ) ) { - /** - * @codeCoverageIgnore - * @see Fallback::mb_strpos - * @return int - */ - function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) { - return Fallback::mb_strpos( $haystack, $needle, $offset, $encoding ); - } -} - -if ( !function_exists( 'mb_strrpos' ) ) { - /** - * @codeCoverageIgnore - * @see Fallback::mb_strrpos - * @return int - */ - function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) { - return Fallback::mb_strrpos( $haystack, $needle, $offset, $encoding ); - } -} - // hash_equals function only exists in PHP >= 5.6.0 // http://php.net/hash_equals if ( !function_exists( 'hash_equals' ) ) { @@ -554,12 +501,26 @@ function wfAppendQuery( $url, $query ) { $query = wfArrayToCgi( $query ); } if ( $query != '' ) { + // Remove the fragment, if there is one + $fragment = false; + $hashPos = strpos( $url, '#' ); + if ( $hashPos !== false ) { + $fragment = substr( $url, $hashPos ); + $url = substr( $url, 0, $hashPos ); + } + + // Add parameter if ( false === strpos( $url, '?' ) ) { $url .= '?'; } else { $url .= '&'; } $url .= $query; + + // Put the fragment back + if ( $fragment !== false ) { + $url .= $fragment; + } } return $url; } @@ -2173,6 +2134,24 @@ function wfTempDir() { return $tmp; } } + + /** + * PHP on Windows will detect C:\Windows\Temp as not writable even though PHP can write to it + * so create a directory within that called 'mwtmp' with a suffix of the user running the + * current process. + * The user is included as if various scripts are run by different users they will likely + * not be able to access each others temporary files. + */ + if ( wfIsWindows() ) { + $tmp = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'mwtmp' . '-' . get_current_user(); + if ( !file_exists( $tmp ) ) { + mkdir( $tmp ); + } + if ( file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) { + return $tmp; + } + } + throw new MWException( 'No writable temporary directory could be found. ' . 'Please set $wgTmpDirectory to a writable directory.' ); } @@ -2990,7 +2969,7 @@ function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, /** * @deprecated since 1.27, PHP's session generation isn't used with - * MediaWiki\\Session\\SessionManager + * MediaWiki\Session\SessionManager */ function wfFixSessionID() { wfDeprecated( __FUNCTION__, '1.27' ); @@ -2999,7 +2978,7 @@ function wfFixSessionID() { /** * Reset the session id * - * @deprecated since 1.27, use MediaWiki\\Session\\SessionManager instead + * @deprecated since 1.27, use MediaWiki\Session\SessionManager instead * @since 1.22 */ function wfResetSessionID() { @@ -3021,7 +3000,7 @@ function wfResetSessionID() { /** * Initialise php session * - * @deprecated since 1.27, use MediaWiki\\Session\\SessionManager instead. + * @deprecated since 1.27, use MediaWiki\Session\SessionManager instead. * Generally, "using" SessionManager will be calling ->getSessionById() or * ::getGlobalSession() (depending on whether you were passing $sessionId * here), then calling $session->persist(). @@ -3162,6 +3141,9 @@ function wfSplitWikiID( $wiki ) { * Note 2: use $this->getDB() in maintenance scripts that may be invoked by * updater to ensure that a proper database is being updated. * + * @todo Replace calls to wfGetDB with calls to LoadBalancer::getConnection() + * on an injected instance of LoadBalancer. + * * @return DatabaseBase */ function wfGetDB( $db, $groups = [], $wiki = false ) { @@ -3171,20 +3153,30 @@ function wfGetDB( $db, $groups = [], $wiki = false ) { /** * Get a load balancer object. * + * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancer() + * or MediaWikiServices::getDBLoadBalancerFactory() instead. + * * @param string|bool $wiki Wiki ID, or false for the current wiki * @return LoadBalancer */ function wfGetLB( $wiki = false ) { - return wfGetLBFactory()->getMainLB( $wiki ); + if ( $wiki === false ) { + return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancer(); + } else { + $factory = \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + return $factory->getMainLB( $wiki ); + } } /** * Get the load balancer factory object * + * @deprecated since 1.27, use MediaWikiServices::getDBLoadBalancerFactory() instead. + * * @return LBFactory */ function wfGetLBFactory() { - return LBFactory::singleton(); + return \MediaWiki\MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); } /**