X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=81705d36d646ce227d99e9d1a2030faf3ee799b6;hb=b8ab1e25ca1cb65fcdf928931d7884d81e2ae43e;hp=d0c3a42d175f65795fc05d185e01d565e6a2fe0b;hpb=04f68827d0e3e53ba2924ff7e9f67f6a7e485656;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index d0c3a42d17..81705d36d6 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -1,13 +1,13 @@ 0 ) { if( $splitPos > 256 ) { // Optimize large string offsets by skipping ahead N bytes. @@ -77,7 +78,7 @@ if ( !function_exists( 'mb_substr' ) ) { $charPos = 0; $bytePos = 0; } - + while( $charPos++ < $splitPos ) { ++$bytePos; // Move past any tail bytes @@ -95,7 +96,7 @@ if ( !function_exists( 'mb_substr' ) ) { --$bytePos; } } - + return $bytePos; } } @@ -163,12 +164,12 @@ if( !function_exists( 'mb_strrpos' ) ) { $ar = array(); preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); - if( isset( $ar[0] ) && count( $ar[0] ) > 0 && + if( isset( $ar[0] ) && count( $ar[0] ) > 0 && isset( $ar[0][count($ar[0])-1][1] ) ) { return $ar[0][count($ar[0])-1][1]; } else { return false; - } + } } } @@ -250,9 +251,9 @@ function wfRandom() { * * ;:@$!*(),/ * - * However, IIS7 redirects fail when the url contains a colon (Bug 22709), + * However, IIS7 redirects fail when the url contains a colon (Bug 22709), * so no fancy : for IIS7. - * + * * %2F in the page titles seems to fatally break for some reason. * * @param $s String: @@ -265,8 +266,8 @@ function wfUrlencode( $s ) { if (! isset($_SERVER['SERVER_SOFTWARE']) || ( strpos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS/7") === false)) { $needle[] = '%3A'; } - } - + } + $s = urlencode( $s ); $s = str_ireplace( $needle, @@ -401,12 +402,13 @@ function wfLogDBError( $text ) { /** * Log to a file without getting "file size exceeded" signals. - * - * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will + * + * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will * send lines to the specified port, prefixed by the specified prefix and a space. */ function wfErrorLog( $text, $file ) { if ( substr( $file, 0, 4 ) == 'udp:' ) { + # Needs the sockets extension if ( preg_match( '!^(tcp|udp):(?://)?\[([0-9a-fA-F:]+)\]:(\d+)(?:/(.*))?$!', $file, $m ) ) { // IPv6 bracketed host $protocol = $m[1]; @@ -535,14 +537,14 @@ function wfGetLangObj( $langcode = false ) { # Great, we already have the object (hopefully)! return $langcode; } - + global $wgContLang, $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; } - + global $wgLang; if( $langcode === false || $langcode === $wgLang->getCode() ) { # $langcode is the language code of user language object. @@ -561,9 +563,16 @@ function wfGetLangObj( $langcode = false ) { return $wgContLang; } +/** + * Use this instead of $wgContLang, when working with user interface. + * User interface is currently hard coded according to wiki content language + * in many ways, especially regarding to text direction. There is lots stuff + * to fix, hence this function to keep the old behaviour unless the global + * $wgBetterDirectionality is enabled (or removed when everything works). + */ function wfUILang() { global $wgBetterDirectionality; - return wfGetLangObj( $wgBetterDirectionality ? false: true ); + return wfGetLangObj( !$wgBetterDirectionality ); } /** @@ -576,7 +585,7 @@ function wfUILang() { * defined in languages/Language.php * * This function also takes extra optional parameters (not - * shown in the function definition), which can by used to + * shown in the function definition), which can be used to * insert variable text into the predefined message. */ function wfMsg( $key ) { @@ -707,7 +716,7 @@ function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) { global $wgMessageCache; wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform)); - + if ( !is_object( $wgMessageCache ) ) { throw new MWException( "Trying to get message before message cache is initialised" ); } @@ -1073,7 +1082,7 @@ function wfShowingResults( $offset, $limit ) { */ function wfShowingResultsNum( $offset, $limit, $num ) { global $wgLang; - return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), + return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) ); } @@ -1113,7 +1122,7 @@ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { $q .= '&'.$query; } $plink = '{$prev}"; - } else { + } else { $plink = $prev; } # Make 'next' link @@ -1128,7 +1137,7 @@ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { $nlink = '{$next}"; } # Make links to set number of items per page - $nums = $wgLang->pipeList( array( + $nums = $wgLang->pipeList( array( wfNumLink( $offset, 20, $title, $query ), wfNumLink( $offset, 50, $title, $query ), wfNumLink( $offset, 100, $title, $query ), @@ -1147,9 +1156,9 @@ function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) { */ function wfNumLink( $offset, $limit, $title, $query = '' ) { global $wgLang; - if( $query == '' ) { + if( $query == '' ) { $q = ''; - } else { + } else { $q = $query.'&'; } $q .= "limit={$limit}&offset={$offset}"; @@ -1393,7 +1402,7 @@ function wfPurgeSquidServers ($urlArr) { * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg() * function puts single quotes in regardless of OS. * - * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to + * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to * earlier distro releases of PHP) */ function wfEscapeShellArg( ) { @@ -1517,7 +1526,7 @@ function wfDiff( $before, $after, $params = '-u' ) { if ($before == $after) { return ''; } - + global $wgDiff; # This check may also protect against code injection in @@ -1536,14 +1545,14 @@ function wfDiff( $before, $after, $params = '-u' ) { fwrite( $oldtextFile, $before ); fclose( $oldtextFile ); fwrite( $newtextFile, $after ); fclose( $newtextFile ); - + // Get the diff of the two files $cmd = "$wgDiff " . $params . ' ' .wfEscapeShellArg( $oldtextName, $newtextName ); - + $h = popen( $cmd, 'r' ); - + $diff = ''; - + do { $data = fread( $h, 8192 ); if ( strlen( $data ) == 0 ) { @@ -1551,12 +1560,12 @@ function wfDiff( $before, $after, $params = '-u' ) { } $diff .= $data; } while ( true ); - + // Clean up pclose( $h ); unlink( $oldtextName ); unlink( $newtextName ); - + // Kill the --- and +++ lines. They're not useful. $diff_lines = explode( "\n", $diff ); if (strpos( $diff_lines[0], '---' ) === 0) { @@ -1565,9 +1574,9 @@ function wfDiff( $before, $after, $params = '-u' ) { if (strpos( $diff_lines[1], '+++' ) === 0) { unset($diff_lines[1]); } - + $diff = implode( "\n", $diff_lines ); - + return $diff; } @@ -2101,8 +2110,8 @@ function &wfGetMimeMagic() { * variables are then checked in sequence, and if none are set /tmp is * returned as the generic Unix default. * It is common to call it with tempnam(). - * - * NOTE: When possible, use instead the tmpfile() function to create + * + * NOTE: When possible, use instead the tmpfile() function to create * temporary files to avoid race conditions on file creation, etc. * * @return String @@ -2123,7 +2132,7 @@ function wfTempDir() { /** * Make directory, and make all parent directories if they don't exist - * + * * @param $dir String: full path to directory to create * @param $mode Integer: chmod value to use, default is $wgDirectoryMode * @param $caller String: optional caller param for debugging. @@ -2376,8 +2385,8 @@ function wfShellExec( $cmd, &$retval=null ) { $cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd ); } } - } elseif ( php_uname( 's' ) == 'Windows NT' && - version_compare( PHP_VERSION, '5.3.0', '<' ) ) + } elseif ( php_uname( 's' ) == 'Windows NT' && + version_compare( PHP_VERSION, '5.3.0', '<' ) ) { # This is a hack to work around PHP's flawed invocation of cmd.exe # http://news.php.net/php.internals/21796 @@ -2545,14 +2554,14 @@ function wfArrayMerge( $array1/* ... */ ) { /** * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal * e.g. - * wfMergeErrorArrays( - * array( array( 'x' ) ), - * array( array( 'x', '2' ) ), - * array( array( 'x' ) ), + * wfMergeErrorArrays( + * array( array( 'x' ) ), + * array( array( 'x', '2' ) ), + * array( array( 'x' ) ), * array( array( 'y') ) * ); * returns: - * array( + * array( * array( 'x', '2' ), * array( 'x' ), * array( 'y' ) @@ -2800,7 +2809,7 @@ function wfHttpOnlySafe() { * Initialise php session */ function wfSetupSession() { - global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain, + global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain, $wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler; if( $wgSessionsInMemcached ) { require_once( 'MemcachedSessions.php' ); @@ -2978,7 +2987,7 @@ function &wfGetLBFactory() { * * ignoreRedirect: If true, do not follow file redirects * - * private: If true, return restricted (deleted) files if the current + * private: If true, return restricted (deleted) files if the current * user is allowed to view them. Otherwise, such files will not * be found. * @@ -3191,14 +3200,14 @@ function wfOut( $s ) { } /** - * Count down from $n to zero on the terminal, with a one-second pause + * Count down from $n to zero on the terminal, with a one-second pause * between showing each number. For use in command-line scripts. */ function wfCountDown( $n ) { for ( $i = $n; $i >= 0; $i-- ) { if ( $i != $n ) { echo str_repeat( "\x08", strlen( $i + 1 ) ); - } + } echo $i; flush(); if ( $i ) { @@ -3239,29 +3248,29 @@ function wfArrayInsertAfter( $array, $insert, $after ) { // Find the offset of the element to insert after. $keys = array_keys($array); $offsetByKey = array_flip( $keys ); - + $offset = $offsetByKey[$after]; - + // Insert at the specified offset $before = array_slice( $array, 0, $offset + 1, true ); $after = array_slice( $array, $offset + 1, count($array)-$offset, true ); - + $output = $before + $insert + $after; - + return $output; } /* Recursively converts the parameter (an object) to an array with the same data */ function wfObjectToArray( $object, $recursive = true ) { $array = array(); - foreach ( get_object_vars($object) as $key => $value ) { - if ( is_object($value) && $recursive ) { + foreach ( get_object_vars( $object ) as $key => $value ) { + if ( is_object( $value ) && $recursive ) { $value = wfObjectToArray( $value ); } - + $array[$key] = $value; } - + return $array; } @@ -3269,8 +3278,7 @@ function wfObjectToArray( $object, $recursive = true ) { * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit; * @return Integer value memory was set to. */ - -function wfMemoryLimit () { +function wfMemoryLimit() { global $wgMemoryLimit; $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) ); $conflimit = wfShorthandToInteger( $wgMemoryLimit );