Index: trunk/phase3/includes/GlobalFunctions.php |
— | — | @@ -1,13 +1,13 @@ |
2 | 2 | <?php |
| 3 | +/** |
| 4 | + * Global functions used everywhere |
| 5 | + * @file |
| 6 | + */ |
3 | 7 | |
4 | 8 | if ( !defined( 'MEDIAWIKI' ) ) { |
5 | 9 | die( "This file is part of MediaWiki, it is not a valid entry point" ); |
6 | 10 | } |
7 | 11 | |
8 | | -/** |
9 | | - * Global functions used everywhere |
10 | | - */ |
11 | | - |
12 | 12 | require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php'; |
13 | 13 | |
14 | 14 | // Hide compatibility functions from Doxygen |
— | — | @@ -49,22 +49,22 @@ |
50 | 50 | $split = mb_substr_split_unicode( $str, intval( $start ) ); |
51 | 51 | $str = substr( $str, $split ); |
52 | 52 | } |
53 | | - |
| 53 | + |
54 | 54 | if( $count !== 'end' ) { |
55 | 55 | $split = mb_substr_split_unicode( $str, intval( $count ) ); |
56 | 56 | $str = substr( $str, 0, $split ); |
57 | 57 | } |
58 | | - |
| 58 | + |
59 | 59 | return $str; |
60 | 60 | } |
61 | | - |
| 61 | + |
62 | 62 | function mb_substr_split_unicode( $str, $splitPos ) { |
63 | 63 | if( $splitPos == 0 ) { |
64 | 64 | return 0; |
65 | 65 | } |
66 | | - |
| 66 | + |
67 | 67 | $byteLen = strlen( $str ); |
68 | | - |
| 68 | + |
69 | 69 | if( $splitPos > 0 ) { |
70 | 70 | if( $splitPos > 256 ) { |
71 | 71 | // Optimize large string offsets by skipping ahead N bytes. |
— | — | @@ -78,7 +78,7 @@ |
79 | 79 | $charPos = 0; |
80 | 80 | $bytePos = 0; |
81 | 81 | } |
82 | | - |
| 82 | + |
83 | 83 | while( $charPos++ < $splitPos ) { |
84 | 84 | ++$bytePos; |
85 | 85 | // Move past any tail bytes |
— | — | @@ -96,7 +96,7 @@ |
97 | 97 | --$bytePos; |
98 | 98 | } |
99 | 99 | } |
100 | | - |
| 100 | + |
101 | 101 | return $bytePos; |
102 | 102 | } |
103 | 103 | } |
— | — | @@ -164,12 +164,12 @@ |
165 | 165 | $ar = array(); |
166 | 166 | preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset ); |
167 | 167 | |
168 | | - if( isset( $ar[0] ) && count( $ar[0] ) > 0 && |
| 168 | + if( isset( $ar[0] ) && count( $ar[0] ) > 0 && |
169 | 169 | isset( $ar[0][count($ar[0])-1][1] ) ) { |
170 | 170 | return $ar[0][count($ar[0])-1][1]; |
171 | 171 | } else { |
172 | 172 | return false; |
173 | | - } |
| 173 | + } |
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
— | — | @@ -251,9 +251,9 @@ |
252 | 252 | * |
253 | 253 | * ;:@$!*(),/ |
254 | 254 | * |
255 | | - * However, IIS7 redirects fail when the url contains a colon (Bug 22709), |
| 255 | + * However, IIS7 redirects fail when the url contains a colon (Bug 22709), |
256 | 256 | * so no fancy : for IIS7. |
257 | | - * |
| 257 | + * |
258 | 258 | * %2F in the page titles seems to fatally break for some reason. |
259 | 259 | * |
260 | 260 | * @param $s String: |
— | — | @@ -266,8 +266,8 @@ |
267 | 267 | if (! isset($_SERVER['SERVER_SOFTWARE']) || ( strpos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS/7") === false)) { |
268 | 268 | $needle[] = '%3A'; |
269 | 269 | } |
270 | | - } |
271 | | - |
| 270 | + } |
| 271 | + |
272 | 272 | $s = urlencode( $s ); |
273 | 273 | $s = str_ireplace( |
274 | 274 | $needle, |
— | — | @@ -402,8 +402,8 @@ |
403 | 403 | |
404 | 404 | /** |
405 | 405 | * Log to a file without getting "file size exceeded" signals. |
406 | | - * |
407 | | - * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will |
| 406 | + * |
| 407 | + * Can also log to TCP or UDP with the syntax udp://host:port/prefix. This will |
408 | 408 | * send lines to the specified port, prefixed by the specified prefix and a space. |
409 | 409 | */ |
410 | 410 | function wfErrorLog( $text, $file ) { |
— | — | @@ -537,14 +537,14 @@ |
538 | 538 | # Great, we already have the object (hopefully)! |
539 | 539 | return $langcode; |
540 | 540 | } |
541 | | - |
| 541 | + |
542 | 542 | global $wgContLang, $wgLanguageCode; |
543 | 543 | if( $langcode === true || $langcode === $wgLanguageCode ) { |
544 | 544 | # $langcode is the language code of the wikis content language object. |
545 | 545 | # or it is a boolean and value is true |
546 | 546 | return $wgContLang; |
547 | 547 | } |
548 | | - |
| 548 | + |
549 | 549 | global $wgLang; |
550 | 550 | if( $langcode === false || $langcode === $wgLang->getCode() ) { |
551 | 551 | # $langcode is the language code of user language object. |
— | — | @@ -709,7 +709,7 @@ |
710 | 710 | global $wgMessageCache; |
711 | 711 | |
712 | 712 | wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform)); |
713 | | - |
| 713 | + |
714 | 714 | if ( !is_object( $wgMessageCache ) ) { |
715 | 715 | throw new MWException( "Trying to get message before message cache is initialised" ); |
716 | 716 | } |
— | — | @@ -1075,7 +1075,7 @@ |
1076 | 1076 | */ |
1077 | 1077 | function wfShowingResultsNum( $offset, $limit, $num ) { |
1078 | 1078 | global $wgLang; |
1079 | | - return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), |
| 1079 | + return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ), |
1080 | 1080 | $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) ); |
1081 | 1081 | } |
1082 | 1082 | |
— | — | @@ -1115,7 +1115,7 @@ |
1116 | 1116 | $q .= '&'.$query; |
1117 | 1117 | } |
1118 | 1118 | $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>"; |
1119 | | - } else { |
| 1119 | + } else { |
1120 | 1120 | $plink = $prev; |
1121 | 1121 | } |
1122 | 1122 | # Make 'next' link |
— | — | @@ -1130,7 +1130,7 @@ |
1131 | 1131 | $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>"; |
1132 | 1132 | } |
1133 | 1133 | # Make links to set number of items per page |
1134 | | - $nums = $wgLang->pipeList( array( |
| 1134 | + $nums = $wgLang->pipeList( array( |
1135 | 1135 | wfNumLink( $offset, 20, $title, $query ), |
1136 | 1136 | wfNumLink( $offset, 50, $title, $query ), |
1137 | 1137 | wfNumLink( $offset, 100, $title, $query ), |
— | — | @@ -1149,9 +1149,9 @@ |
1150 | 1150 | */ |
1151 | 1151 | function wfNumLink( $offset, $limit, $title, $query = '' ) { |
1152 | 1152 | global $wgLang; |
1153 | | - if( $query == '' ) { |
| 1153 | + if( $query == '' ) { |
1154 | 1154 | $q = ''; |
1155 | | - } else { |
| 1155 | + } else { |
1156 | 1156 | $q = $query.'&'; |
1157 | 1157 | } |
1158 | 1158 | $q .= "limit={$limit}&offset={$offset}"; |
— | — | @@ -1395,7 +1395,7 @@ |
1396 | 1396 | * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg() |
1397 | 1397 | * function puts single quotes in regardless of OS. |
1398 | 1398 | * |
1399 | | - * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to |
| 1399 | + * Also fixes the locale problems on Linux in PHP 5.2.6+ (bug backported to |
1400 | 1400 | * earlier distro releases of PHP) |
1401 | 1401 | */ |
1402 | 1402 | function wfEscapeShellArg( ) { |
— | — | @@ -1519,7 +1519,7 @@ |
1520 | 1520 | if ($before == $after) { |
1521 | 1521 | return ''; |
1522 | 1522 | } |
1523 | | - |
| 1523 | + |
1524 | 1524 | global $wgDiff; |
1525 | 1525 | |
1526 | 1526 | # This check may also protect against code injection in |
— | — | @@ -1538,14 +1538,14 @@ |
1539 | 1539 | |
1540 | 1540 | fwrite( $oldtextFile, $before ); fclose( $oldtextFile ); |
1541 | 1541 | fwrite( $newtextFile, $after ); fclose( $newtextFile ); |
1542 | | - |
| 1542 | + |
1543 | 1543 | // Get the diff of the two files |
1544 | 1544 | $cmd = "$wgDiff " . $params . ' ' .wfEscapeShellArg( $oldtextName, $newtextName ); |
1545 | | - |
| 1545 | + |
1546 | 1546 | $h = popen( $cmd, 'r' ); |
1547 | | - |
| 1547 | + |
1548 | 1548 | $diff = ''; |
1549 | | - |
| 1549 | + |
1550 | 1550 | do { |
1551 | 1551 | $data = fread( $h, 8192 ); |
1552 | 1552 | if ( strlen( $data ) == 0 ) { |
— | — | @@ -1553,12 +1553,12 @@ |
1554 | 1554 | } |
1555 | 1555 | $diff .= $data; |
1556 | 1556 | } while ( true ); |
1557 | | - |
| 1557 | + |
1558 | 1558 | // Clean up |
1559 | 1559 | pclose( $h ); |
1560 | 1560 | unlink( $oldtextName ); |
1561 | 1561 | unlink( $newtextName ); |
1562 | | - |
| 1562 | + |
1563 | 1563 | // Kill the --- and +++ lines. They're not useful. |
1564 | 1564 | $diff_lines = explode( "\n", $diff ); |
1565 | 1565 | if (strpos( $diff_lines[0], '---' ) === 0) { |
— | — | @@ -1567,9 +1567,9 @@ |
1568 | 1568 | if (strpos( $diff_lines[1], '+++' ) === 0) { |
1569 | 1569 | unset($diff_lines[1]); |
1570 | 1570 | } |
1571 | | - |
| 1571 | + |
1572 | 1572 | $diff = implode( "\n", $diff_lines ); |
1573 | | - |
| 1573 | + |
1574 | 1574 | return $diff; |
1575 | 1575 | } |
1576 | 1576 | |
— | — | @@ -2103,8 +2103,8 @@ |
2104 | 2104 | * variables are then checked in sequence, and if none are set /tmp is |
2105 | 2105 | * returned as the generic Unix default. |
2106 | 2106 | * It is common to call it with tempnam(). |
2107 | | - * |
2108 | | - * NOTE: When possible, use instead the tmpfile() function to create |
| 2107 | + * |
| 2108 | + * NOTE: When possible, use instead the tmpfile() function to create |
2109 | 2109 | * temporary files to avoid race conditions on file creation, etc. |
2110 | 2110 | * |
2111 | 2111 | * @return String |
— | — | @@ -2125,7 +2125,7 @@ |
2126 | 2126 | |
2127 | 2127 | /** |
2128 | 2128 | * Make directory, and make all parent directories if they don't exist |
2129 | | - * |
| 2129 | + * |
2130 | 2130 | * @param $dir String: full path to directory to create |
2131 | 2131 | * @param $mode Integer: chmod value to use, default is $wgDirectoryMode |
2132 | 2132 | * @param $caller String: optional caller param for debugging. |
— | — | @@ -2378,8 +2378,8 @@ |
2379 | 2379 | $cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd ); |
2380 | 2380 | } |
2381 | 2381 | } |
2382 | | - } elseif ( php_uname( 's' ) == 'Windows NT' && |
2383 | | - version_compare( PHP_VERSION, '5.3.0', '<' ) ) |
| 2382 | + } elseif ( php_uname( 's' ) == 'Windows NT' && |
| 2383 | + version_compare( PHP_VERSION, '5.3.0', '<' ) ) |
2384 | 2384 | { |
2385 | 2385 | # This is a hack to work around PHP's flawed invocation of cmd.exe |
2386 | 2386 | # http://news.php.net/php.internals/21796 |
— | — | @@ -2547,14 +2547,14 @@ |
2548 | 2548 | /** |
2549 | 2549 | * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal |
2550 | 2550 | * e.g. |
2551 | | - * wfMergeErrorArrays( |
2552 | | - * array( array( 'x' ) ), |
2553 | | - * array( array( 'x', '2' ) ), |
2554 | | - * array( array( 'x' ) ), |
| 2551 | + * wfMergeErrorArrays( |
| 2552 | + * array( array( 'x' ) ), |
| 2553 | + * array( array( 'x', '2' ) ), |
| 2554 | + * array( array( 'x' ) ), |
2555 | 2555 | * array( array( 'y') ) |
2556 | 2556 | * ); |
2557 | 2557 | * returns: |
2558 | | - * array( |
| 2558 | + * array( |
2559 | 2559 | * array( 'x', '2' ), |
2560 | 2560 | * array( 'x' ), |
2561 | 2561 | * array( 'y' ) |
— | — | @@ -2802,7 +2802,7 @@ |
2803 | 2803 | * Initialise php session |
2804 | 2804 | */ |
2805 | 2805 | function wfSetupSession() { |
2806 | | - global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain, |
| 2806 | + global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain, |
2807 | 2807 | $wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler; |
2808 | 2808 | if( $wgSessionsInMemcached ) { |
2809 | 2809 | require_once( 'MemcachedSessions.php' ); |
— | — | @@ -2980,7 +2980,7 @@ |
2981 | 2981 | * |
2982 | 2982 | * ignoreRedirect: If true, do not follow file redirects |
2983 | 2983 | * |
2984 | | - * private: If true, return restricted (deleted) files if the current |
| 2984 | + * private: If true, return restricted (deleted) files if the current |
2985 | 2985 | * user is allowed to view them. Otherwise, such files will not |
2986 | 2986 | * be found. |
2987 | 2987 | * |
— | — | @@ -3193,14 +3193,14 @@ |
3194 | 3194 | } |
3195 | 3195 | |
3196 | 3196 | /** |
3197 | | - * Count down from $n to zero on the terminal, with a one-second pause |
| 3197 | + * Count down from $n to zero on the terminal, with a one-second pause |
3198 | 3198 | * between showing each number. For use in command-line scripts. |
3199 | 3199 | */ |
3200 | 3200 | function wfCountDown( $n ) { |
3201 | 3201 | for ( $i = $n; $i >= 0; $i-- ) { |
3202 | 3202 | if ( $i != $n ) { |
3203 | 3203 | echo str_repeat( "\x08", strlen( $i + 1 ) ); |
3204 | | - } |
| 3204 | + } |
3205 | 3205 | echo $i; |
3206 | 3206 | flush(); |
3207 | 3207 | if ( $i ) { |
— | — | @@ -3241,29 +3241,29 @@ |
3242 | 3242 | // Find the offset of the element to insert after. |
3243 | 3243 | $keys = array_keys($array); |
3244 | 3244 | $offsetByKey = array_flip( $keys ); |
3245 | | - |
| 3245 | + |
3246 | 3246 | $offset = $offsetByKey[$after]; |
3247 | | - |
| 3247 | + |
3248 | 3248 | // Insert at the specified offset |
3249 | 3249 | $before = array_slice( $array, 0, $offset + 1, true ); |
3250 | 3250 | $after = array_slice( $array, $offset + 1, count($array)-$offset, true ); |
3251 | | - |
| 3251 | + |
3252 | 3252 | $output = $before + $insert + $after; |
3253 | | - |
| 3253 | + |
3254 | 3254 | return $output; |
3255 | 3255 | } |
3256 | 3256 | |
3257 | 3257 | /* Recursively converts the parameter (an object) to an array with the same data */ |
3258 | 3258 | function wfObjectToArray( $object, $recursive = true ) { |
3259 | 3259 | $array = array(); |
3260 | | - foreach ( get_object_vars($object) as $key => $value ) { |
3261 | | - if ( is_object($value) && $recursive ) { |
| 3260 | + foreach ( get_object_vars( $object ) as $key => $value ) { |
| 3261 | + if ( is_object( $value ) && $recursive ) { |
3262 | 3262 | $value = wfObjectToArray( $value ); |
3263 | 3263 | } |
3264 | | - |
| 3264 | + |
3265 | 3265 | $array[$key] = $value; |
3266 | 3266 | } |
3267 | | - |
| 3267 | + |
3268 | 3268 | return $array; |
3269 | 3269 | } |
3270 | 3270 | |
— | — | @@ -3271,8 +3271,7 @@ |
3272 | 3272 | * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit; |
3273 | 3273 | * @return Integer value memory was set to. |
3274 | 3274 | */ |
3275 | | - |
3276 | | -function wfMemoryLimit () { |
| 3275 | +function wfMemoryLimit() { |
3277 | 3276 | global $wgMemoryLimit; |
3278 | 3277 | $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) ); |
3279 | 3278 | $conflimit = wfShorthandToInteger( $wgMemoryLimit ); |