r70276 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70275‎ | r70276 | r70277 >
Date:12:31, 1 August 2010
Author:ialex
Status:ok
Tags:
Comment:
* Removed trailing whitespaces
* Moved the description comment to the very top and added "@file"
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -1,13 +1,13 @@
22 <?php
 3+/**
 4+ * Global functions used everywhere
 5+ * @file
 6+ */
37
48 if ( !defined( 'MEDIAWIKI' ) ) {
59 die( "This file is part of MediaWiki, it is not a valid entry point" );
610 }
711
8 -/**
9 - * Global functions used everywhere
10 - */
11 -
1212 require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
1313
1414 // Hide compatibility functions from Doxygen
@@ -49,22 +49,22 @@
5050 $split = mb_substr_split_unicode( $str, intval( $start ) );
5151 $str = substr( $str, $split );
5252 }
53 -
 53+
5454 if( $count !== 'end' ) {
5555 $split = mb_substr_split_unicode( $str, intval( $count ) );
5656 $str = substr( $str, 0, $split );
5757 }
58 -
 58+
5959 return $str;
6060 }
61 -
 61+
6262 function mb_substr_split_unicode( $str, $splitPos ) {
6363 if( $splitPos == 0 ) {
6464 return 0;
6565 }
66 -
 66+
6767 $byteLen = strlen( $str );
68 -
 68+
6969 if( $splitPos > 0 ) {
7070 if( $splitPos > 256 ) {
7171 // Optimize large string offsets by skipping ahead N bytes.
@@ -78,7 +78,7 @@
7979 $charPos = 0;
8080 $bytePos = 0;
8181 }
82 -
 82+
8383 while( $charPos++ < $splitPos ) {
8484 ++$bytePos;
8585 // Move past any tail bytes
@@ -96,7 +96,7 @@
9797 --$bytePos;
9898 }
9999 }
100 -
 100+
101101 return $bytePos;
102102 }
103103 }
@@ -164,12 +164,12 @@
165165 $ar = array();
166166 preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
167167
168 - if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
 168+ if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
169169 isset( $ar[0][count($ar[0])-1][1] ) ) {
170170 return $ar[0][count($ar[0])-1][1];
171171 } else {
172172 return false;
173 - }
 173+ }
174174 }
175175 }
176176
@@ -251,9 +251,9 @@
252252 *
253253 * ;:@$!*(),/
254254 *
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),
256256 * so no fancy : for IIS7.
257 - *
 257+ *
258258 * %2F in the page titles seems to fatally break for some reason.
259259 *
260260 * @param $s String:
@@ -266,8 +266,8 @@
267267 if (! isset($_SERVER['SERVER_SOFTWARE']) || ( strpos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS/7") === false)) {
268268 $needle[] = '%3A';
269269 }
270 - }
271 -
 270+ }
 271+
272272 $s = urlencode( $s );
273273 $s = str_ireplace(
274274 $needle,
@@ -402,8 +402,8 @@
403403
404404 /**
405405 * 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
408408 * send lines to the specified port, prefixed by the specified prefix and a space.
409409 */
410410 function wfErrorLog( $text, $file ) {
@@ -537,14 +537,14 @@
538538 # Great, we already have the object (hopefully)!
539539 return $langcode;
540540 }
541 -
 541+
542542 global $wgContLang, $wgLanguageCode;
543543 if( $langcode === true || $langcode === $wgLanguageCode ) {
544544 # $langcode is the language code of the wikis content language object.
545545 # or it is a boolean and value is true
546546 return $wgContLang;
547547 }
548 -
 548+
549549 global $wgLang;
550550 if( $langcode === false || $langcode === $wgLang->getCode() ) {
551551 # $langcode is the language code of user language object.
@@ -709,7 +709,7 @@
710710 global $wgMessageCache;
711711
712712 wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform));
713 -
 713+
714714 if ( !is_object( $wgMessageCache ) ) {
715715 throw new MWException( "Trying to get message before message cache is initialised" );
716716 }
@@ -1075,7 +1075,7 @@
10761076 */
10771077 function wfShowingResultsNum( $offset, $limit, $num ) {
10781078 global $wgLang;
1079 - return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ),
 1079+ return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ),
10801080 $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );
10811081 }
10821082
@@ -1115,7 +1115,7 @@
11161116 $q .= '&'.$query;
11171117 }
11181118 $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
1119 - } else {
 1119+ } else {
11201120 $plink = $prev;
11211121 }
11221122 # Make 'next' link
@@ -1130,7 +1130,7 @@
11311131 $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
11321132 }
11331133 # Make links to set number of items per page
1134 - $nums = $wgLang->pipeList( array(
 1134+ $nums = $wgLang->pipeList( array(
11351135 wfNumLink( $offset, 20, $title, $query ),
11361136 wfNumLink( $offset, 50, $title, $query ),
11371137 wfNumLink( $offset, 100, $title, $query ),
@@ -1149,9 +1149,9 @@
11501150 */
11511151 function wfNumLink( $offset, $limit, $title, $query = '' ) {
11521152 global $wgLang;
1153 - if( $query == '' ) {
 1153+ if( $query == '' ) {
11541154 $q = '';
1155 - } else {
 1155+ } else {
11561156 $q = $query.'&';
11571157 }
11581158 $q .= "limit={$limit}&offset={$offset}";
@@ -1395,7 +1395,7 @@
13961396 * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
13971397 * function puts single quotes in regardless of OS.
13981398 *
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
14001400 * earlier distro releases of PHP)
14011401 */
14021402 function wfEscapeShellArg( ) {
@@ -1519,7 +1519,7 @@
15201520 if ($before == $after) {
15211521 return '';
15221522 }
1523 -
 1523+
15241524 global $wgDiff;
15251525
15261526 # This check may also protect against code injection in
@@ -1538,14 +1538,14 @@
15391539
15401540 fwrite( $oldtextFile, $before ); fclose( $oldtextFile );
15411541 fwrite( $newtextFile, $after ); fclose( $newtextFile );
1542 -
 1542+
15431543 // Get the diff of the two files
15441544 $cmd = "$wgDiff " . $params . ' ' .wfEscapeShellArg( $oldtextName, $newtextName );
1545 -
 1545+
15461546 $h = popen( $cmd, 'r' );
1547 -
 1547+
15481548 $diff = '';
1549 -
 1549+
15501550 do {
15511551 $data = fread( $h, 8192 );
15521552 if ( strlen( $data ) == 0 ) {
@@ -1553,12 +1553,12 @@
15541554 }
15551555 $diff .= $data;
15561556 } while ( true );
1557 -
 1557+
15581558 // Clean up
15591559 pclose( $h );
15601560 unlink( $oldtextName );
15611561 unlink( $newtextName );
1562 -
 1562+
15631563 // Kill the --- and +++ lines. They're not useful.
15641564 $diff_lines = explode( "\n", $diff );
15651565 if (strpos( $diff_lines[0], '---' ) === 0) {
@@ -1567,9 +1567,9 @@
15681568 if (strpos( $diff_lines[1], '+++' ) === 0) {
15691569 unset($diff_lines[1]);
15701570 }
1571 -
 1571+
15721572 $diff = implode( "\n", $diff_lines );
1573 -
 1573+
15741574 return $diff;
15751575 }
15761576
@@ -2103,8 +2103,8 @@
21042104 * variables are then checked in sequence, and if none are set /tmp is
21052105 * returned as the generic Unix default.
21062106 * 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
21092109 * temporary files to avoid race conditions on file creation, etc.
21102110 *
21112111 * @return String
@@ -2125,7 +2125,7 @@
21262126
21272127 /**
21282128 * Make directory, and make all parent directories if they don't exist
2129 - *
 2129+ *
21302130 * @param $dir String: full path to directory to create
21312131 * @param $mode Integer: chmod value to use, default is $wgDirectoryMode
21322132 * @param $caller String: optional caller param for debugging.
@@ -2378,8 +2378,8 @@
23792379 $cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd );
23802380 }
23812381 }
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', '<' ) )
23842384 {
23852385 # This is a hack to work around PHP's flawed invocation of cmd.exe
23862386 # http://news.php.net/php.internals/21796
@@ -2547,14 +2547,14 @@
25482548 /**
25492549 * Merge arrays in the style of getUserPermissionsErrors, with duplicate removal
25502550 * 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' ) ),
25552555 * array( array( 'y') )
25562556 * );
25572557 * returns:
2558 - * array(
 2558+ * array(
25592559 * array( 'x', '2' ),
25602560 * array( 'x' ),
25612561 * array( 'y' )
@@ -2802,7 +2802,7 @@
28032803 * Initialise php session
28042804 */
28052805 function wfSetupSession() {
2806 - global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
 2806+ global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
28072807 $wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler;
28082808 if( $wgSessionsInMemcached ) {
28092809 require_once( 'MemcachedSessions.php' );
@@ -2980,7 +2980,7 @@
29812981 *
29822982 * ignoreRedirect: If true, do not follow file redirects
29832983 *
2984 - * private: If true, return restricted (deleted) files if the current
 2984+ * private: If true, return restricted (deleted) files if the current
29852985 * user is allowed to view them. Otherwise, such files will not
29862986 * be found.
29872987 *
@@ -3193,14 +3193,14 @@
31943194 }
31953195
31963196 /**
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
31983198 * between showing each number. For use in command-line scripts.
31993199 */
32003200 function wfCountDown( $n ) {
32013201 for ( $i = $n; $i >= 0; $i-- ) {
32023202 if ( $i != $n ) {
32033203 echo str_repeat( "\x08", strlen( $i + 1 ) );
3204 - }
 3204+ }
32053205 echo $i;
32063206 flush();
32073207 if ( $i ) {
@@ -3241,29 +3241,29 @@
32423242 // Find the offset of the element to insert after.
32433243 $keys = array_keys($array);
32443244 $offsetByKey = array_flip( $keys );
3245 -
 3245+
32463246 $offset = $offsetByKey[$after];
3247 -
 3247+
32483248 // Insert at the specified offset
32493249 $before = array_slice( $array, 0, $offset + 1, true );
32503250 $after = array_slice( $array, $offset + 1, count($array)-$offset, true );
3251 -
 3251+
32523252 $output = $before + $insert + $after;
3253 -
 3253+
32543254 return $output;
32553255 }
32563256
32573257 /* Recursively converts the parameter (an object) to an array with the same data */
32583258 function wfObjectToArray( $object, $recursive = true ) {
32593259 $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 ) {
32623262 $value = wfObjectToArray( $value );
32633263 }
3264 -
 3264+
32653265 $array[$key] = $value;
32663266 }
3267 -
 3267+
32683268 return $array;
32693269 }
32703270
@@ -3271,8 +3271,7 @@
32723272 * Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit;
32733273 * @return Integer value memory was set to.
32743274 */
3275 -
3276 -function wfMemoryLimit () {
 3275+function wfMemoryLimit() {
32773276 global $wgMemoryLimit;
32783277 $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) );
32793278 $conflimit = wfShorthandToInteger( $wgMemoryLimit );

Status & tagging log