r71069 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71068‎ | r71069 | r71070 >
Date:13:31, 14 August 2010
Author:ashley
Status:ok
Tags:
Comment:
coding style tweaks
Modified paths:
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -8,7 +8,7 @@
99 die( "This file is part of MediaWiki, it is not a valid entry point" );
1010 }
1111
12 -require_once dirname(__FILE__) . '/normal/UtfNormalUtil.php';
 12+require_once dirname( __FILE__ ) . '/normal/UtfNormalUtil.php';
1313
1414 // Hide compatibility functions from Doxygen
1515 /// @cond
@@ -20,15 +20,23 @@
2121 * Re-implementations of newer functions or functions in non-standard
2222 * PHP extensions may be included here.
2323 */
24 -if( !function_exists('iconv') ) {
 24+if( !function_exists( 'iconv' ) ) {
2525 # iconv support is not in the default configuration and so may not be present.
2626 # Assume will only ever use utf-8 and iso-8859-1.
2727 # This will *not* work in all circumstances.
2828 function iconv( $from, $to, $string ) {
29 - if ( substr( $to, -8 ) == '//IGNORE' ) $to = substr( $to, 0, strlen( $to ) - 8 );
30 - if(strcasecmp( $from, $to ) == 0) return $string;
31 - if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
32 - if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
 29+ if ( substr( $to, -8 ) == '//IGNORE' ) {
 30+ $to = substr( $to, 0, strlen( $to ) - 8 );
 31+ }
 32+ if( strcasecmp( $from, $to ) == 0 ) {
 33+ return $string;
 34+ }
 35+ if( strcasecmp( $from, 'utf-8' ) == 0 ) {
 36+ return utf8_decode( $string );
 37+ }
 38+ if( strcasecmp( $to, 'utf-8' ) == 0 ) {
 39+ return utf8_encode( $string );
 40+ }
3341 return $string;
3442 }
3543 }
@@ -71,8 +79,9 @@
7280 // This will cut out most of our slow time on Latin-based text,
7381 // and 1/2 to 1/3 on East European and Asian scripts.
7482 $bytePos = $splitPos;
75 - while ($bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0")
 83+ while ( $bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
7684 ++$bytePos;
 85+ }
7786 $charPos = mb_strlen( substr( $str, 0, $bytePos ) );
7887 } else {
7988 $charPos = 0;
@@ -82,8 +91,9 @@
8392 while( $charPos++ < $splitPos ) {
8493 ++$bytePos;
8594 // Move past any tail bytes
86 - while ($bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0")
 95+ while ( $bytePos < $byteLen && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
8796 ++$bytePos;
 97+ }
8898 }
8999 } else {
90100 $splitPosX = $splitPos + 1;
@@ -92,8 +102,9 @@
93103 while( $bytePos > 0 && $charPos-- >= $splitPosX ) {
94104 --$bytePos;
95105 // Move past any tail bytes
96 - while ($bytePos > 0 && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0")
 106+ while ( $bytePos > 0 && $str{$bytePos} >= "\x80" && $str{$bytePos} < "\xc0" ) {
97107 --$bytePos;
 108+ }
98109 }
99110 }
100111
@@ -108,7 +119,7 @@
109120 * @param string $enc optional encoding; ignored
110121 * @return int
111122 */
112 - function mb_strlen( $str, $enc="" ) {
 123+ function mb_strlen( $str, $enc = '' ) {
113124 $counts = count_chars( $str );
114125 $total = 0;
115126
@@ -135,11 +146,11 @@
136147 * @param $encoding String: optional encoding; ignored
137148 * @return int
138149 */
139 - function mb_strpos( $haystack, $needle, $offset = 0, $encoding="" ) {
 150+ function mb_strpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
140151 $needle = preg_quote( $needle, '/' );
141152
142153 $ar = array();
143 - preg_match( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
 154+ preg_match( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
144155
145156 if( isset( $ar[0][1] ) ) {
146157 return $ar[0][1];
@@ -158,15 +169,15 @@
159170 * @param $encoding String: optional encoding; ignored
160171 * @return int
161172 */
162 - function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = "" ) {
 173+ function mb_strrpos( $haystack, $needle, $offset = 0, $encoding = '' ) {
163174 $needle = preg_quote( $needle, '/' );
164175
165176 $ar = array();
166 - preg_match_all( '/'.$needle.'/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
 177+ preg_match_all( '/' . $needle . '/u', $haystack, $ar, PREG_OFFSET_CAPTURE, $offset );
167178
168179 if( isset( $ar[0] ) && count( $ar[0] ) > 0 &&
169 - isset( $ar[0][count($ar[0])-1][1] ) ) {
170 - return $ar[0][count($ar[0])-1][1];
 180+ isset( $ar[0][count( $ar[0] ) - 1][1] ) ) {
 181+ return $ar[0][count( $ar[0] ) - 1][1];
171182 } else {
172183 return false;
173184 }
@@ -232,7 +243,7 @@
233244 # The maximum random value is "only" 2^31-1, so get two random
234245 # values to reduce the chance of dupes
235246 $max = mt_getrandmax() + 1;
236 - $rand = number_format( (mt_rand() * $max + mt_rand())
 247+ $rand = number_format( ( mt_rand() * $max + mt_rand() )
237248 / $max / $max, 12, '.', '' );
238249 return $rand;
239250 }
@@ -262,8 +273,8 @@
263274 function wfUrlencode( $s ) {
264275 static $needle;
265276 if ( is_null( $needle ) ) {
266 - $needle = array( '%3B','%40','%24','%21','%2A','%28','%29','%2C','%2F' );
267 - if (! isset($_SERVER['SERVER_SOFTWARE']) || ( strpos($_SERVER['SERVER_SOFTWARE'], "Microsoft-IIS/7") === false)) {
 277+ $needle = array( '%3B', '%40', '%24', '%21', '%2A', '%28', '%29', '%2C', '%2F' );
 278+ if ( !isset( $_SERVER['SERVER_SOFTWARE'] ) || ( strpos( $_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS/7' ) === false ) ) {
268279 $needle[] = '%3A';
269280 }
270281 }
@@ -271,7 +282,7 @@
272283 $s = urlencode( $s );
273284 $s = str_ireplace(
274285 $needle,
275 - array( ';', '@', '$', '!', '*', '(', ')', ',', '/', ':' ),
 286+ array( ';', '@', '$', '!', '*', '(', ')', ',', '/', ':' ),
276287 $s
277288 );
278289
@@ -334,7 +345,9 @@
335346
336347 function wfDebugTimer() {
337348 global $wgDebugTimestamps;
338 - if ( !$wgDebugTimestamps ) return '';
 349+ if ( !$wgDebugTimestamps ) {
 350+ return '';
 351+ }
339352 static $start = null;
340353
341354 if ( $start === null ) {
@@ -372,7 +385,7 @@
373386 */
374387 function wfDebugLog( $logGroup, $text, $public = true ) {
375388 global $wgDebugLogGroups, $wgShowHostnames;
376 - $text = trim($text)."\n";
 389+ $text = trim( $text ) . "\n";
377390 if( isset( $wgDebugLogGroups[$logGroup] ) ) {
378391 $time = wfTimestamp( TS_DB );
379392 $wiki = wfWikiID();
@@ -382,7 +395,7 @@
383396 $host = '';
384397 }
385398 wfErrorLog( "$time $host $wiki: $text", $wgDebugLogGroups[$logGroup] );
386 - } else if ( $public === true ) {
 399+ } elseif ( $public === true ) {
387400 wfDebug( $text, true );
388401 }
389402 }
@@ -395,7 +408,7 @@
396409 global $wgDBerrorLog, $wgDBname;
397410 if ( $wgDBerrorLog ) {
398411 $host = trim(`hostname`);
399 - $text = date('D M j G:i:s T Y') . "\t$host\t$wgDBname\t$text";
 412+ $text = date( 'D M j G:i:s T Y' ) . "\t$host\t$wgDBname\t$text";
400413 wfErrorLog( $text, $wgDBerrorLog );
401414 }
402415 }
@@ -426,7 +439,7 @@
427440 $prefix = isset( $m[4] ) ? $m[4] : false;
428441 $domain = AF_INET;
429442 } else {
430 - throw new MWException( __METHOD__.": Invalid UDP specification" );
 443+ throw new MWException( __METHOD__ . ': Invalid UDP specification' );
431444 }
432445 // Clean it up for the multiplexer
433446 if ( strval( $prefix ) !== '' ) {
@@ -460,29 +473,38 @@
461474 global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
462475 global $wgProfiler, $wgProfileLimit, $wgUser;
463476 # Profiling must actually be enabled...
464 - if( is_null( $wgProfiler ) ) return;
 477+ if( is_null( $wgProfiler ) ) {
 478+ return;
 479+ }
465480 # Get total page request time
466481 $now = wfTime();
467482 $elapsed = $now - $wgRequestTime;
468483 # Only show pages that longer than $wgProfileLimit time (default is 0)
469 - if( $elapsed <= $wgProfileLimit ) return;
 484+ if( $elapsed <= $wgProfileLimit ) {
 485+ return;
 486+ }
470487 $prof = wfGetProfilingOutput( $wgRequestTime, $elapsed );
471488 $forward = '';
472 - if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
 489+ if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
473490 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
474 - if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
 491+ }
 492+ if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
475493 $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
476 - if( !empty( $_SERVER['HTTP_FROM'] ) )
 494+ }
 495+ if( !empty( $_SERVER['HTTP_FROM'] ) ) {
477496 $forward .= ' from ' . $_SERVER['HTTP_FROM'];
478 - if( $forward )
 497+ }
 498+ if( $forward ) {
479499 $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
 500+ }
480501 // Don't unstub $wgUser at this late stage just for statistics purposes
481 - if( StubObject::isRealObject($wgUser) && $wgUser->isAnon() )
 502+ if( StubObject::isRealObject( $wgUser ) && $wgUser->isAnon() ) {
482503 $forward .= ' anon';
 504+ }
483505 $log = sprintf( "%s\t%04.3f\t%s\n",
484 - gmdate( 'YmdHis' ), $elapsed,
485 - urldecode( $wgRequest->getRequestURL() . $forward ) );
486 - if ( $wgDebugLogFile != '' && ( $wgRequest->getVal('action') != 'raw' || $wgDebugRawPage ) ) {
 506+ gmdate( 'YmdHis' ), $elapsed,
 507+ urldecode( $wgRequest->getRequestURL() . $forward ) );
 508+ if ( $wgDebugLogFile != '' && ( $wgRequest->getVal( 'action' ) != 'raw' || $wgDebugRawPage ) ) {
487509 wfErrorLog( $log . $prof, $wgDebugLogFile );
488510 }
489511 }
@@ -607,7 +629,7 @@
608630 * Get a message from anywhere, for the current global language
609631 * set with $wgLanguageCode.
610632 *
611 - * Use this if the message should NOT change dependent on the
 633+ * Use this if the message should NOT change dependent on the
612634 * language set in the user's preferences. This is the case for
613635 * most text written into logs, as well as link targets (such as
614636 * the name of the copyright policy page). Link titles, on the
@@ -632,7 +654,9 @@
633655 $forcontent = true;
634656 if( is_array( $wgForceUIMsgAsContentMsg ) &&
635657 in_array( $key, $wgForceUIMsgAsContentMsg ) )
 658+ {
636659 $forcontent = false;
 660+ }
637661 return wfMsgReal( $key, $args, true, $forcontent );
638662 }
639663
@@ -646,7 +670,9 @@
647671 $forcontent = true;
648672 if( is_array( $wgForceUIMsgAsContentMsg ) &&
649673 in_array( $key, $wgForceUIMsgAsContentMsg ) )
 674+ {
650675 $forcontent = false;
 676+ }
651677 return wfMsgReal( $key, $args, true, $forcontent, false );
652678 }
653679
@@ -669,7 +695,9 @@
670696 $forcontent = true;
671697 if( is_array( $wgForceUIMsgAsContentMsg ) &&
672698 in_array( $key, $wgForceUIMsgAsContentMsg ) )
 699+ {
673700 $forcontent = false;
 701+ }
674702 return wfMsgReal( $key, $args, false, $forcontent );
675703 }
676704
@@ -697,10 +725,11 @@
698726 */
699727 function wfMsgWeirdKey( $key ) {
700728 $source = wfMsgGetKey( $key, false, true, false );
701 - if ( wfEmptyMsg( $key, $source ) )
702 - return "";
703 - else
 729+ if ( wfEmptyMsg( $key, $source ) ) {
 730+ return '';
 731+ } else {
704732 return $source;
 733+ }
705734 }
706735
707736 /**
@@ -715,14 +744,14 @@
716745 function wfMsgGetKey( $key, $useDB, $langCode = false, $transform = true ) {
717746 global $wgMessageCache;
718747
719 - wfRunHooks('NormalizeMessageKey', array(&$key, &$useDB, &$langCode, &$transform));
 748+ wfRunHooks( 'NormalizeMessageKey', array( &$key, &$useDB, &$langCode, &$transform ) );
720749
721750 if ( !is_object( $wgMessageCache ) ) {
722 - throw new MWException( "Trying to get message before message cache is initialised" );
 751+ throw new MWException( 'Trying to get message before message cache is initialised' );
723752 }
724753
725754 $message = $wgMessageCache->get( $key, $useDB, $langCode );
726 - if( $message === false ){
 755+ if( $message === false ) {
727756 $message = '&lt;' . htmlspecialchars( $key ) . '&gt;';
728757 } elseif ( $transform ) {
729758 $message = $wgMessageCache->transform( $message );
@@ -750,7 +779,7 @@
751780 }
752781 $replacementKeys = array();
753782 foreach( $args as $n => $param ) {
754 - $replacementKeys['$' . ($n + 1)] = $param;
 783+ $replacementKeys['$' . ( $n + 1 )] = $param;
755784 }
756785 $message = strtr( $message, $replacementKeys );
757786 }
@@ -797,8 +826,8 @@
798827 * Returns message in the requested format
799828 * @param $key String: key of the message
800829 * @param $options Array: processing rules. Can take the following options:
801 - * <i>parse</i>: parses wikitext to html
802 - * <i>parseinline</i>: parses wikitext to html and removes the surrounding
 830+ * <i>parse</i>: parses wikitext to HTML
 831+ * <i>parseinline</i>: parses wikitext to HTML and removes the surrounding
803832 * p's added by parser or tidy
804833 * <i>escape</i>: filters message through htmlspecialchars
805834 * <i>escapenoentities</i>: same, but allows entity references like &#160; through
@@ -831,10 +860,10 @@
832861 }
833862 }
834863
835 - if( in_array('content', $options, true ) ) {
 864+ if( in_array( 'content', $options, true ) ) {
836865 $forContent = true;
837866 $langCode = true;
838 - } elseif( array_key_exists('language', $options) ) {
 867+ } elseif( array_key_exists( 'language', $options ) ) {
839868 $forContent = false;
840869 $langCode = wfGetLangObj( $options['language'] );
841870 } else {
@@ -844,19 +873,19 @@
845874
846875 $string = wfMsgGetKey( $key, /*DB*/true, $langCode, /*Transform*/false );
847876
848 - if( !in_array('replaceafter', $options, true ) ) {
 877+ if( !in_array( 'replaceafter', $options, true ) ) {
849878 $string = wfMsgReplaceArgs( $string, $args );
850879 }
851880
852 - if( in_array('parse', $options, true ) ) {
 881+ if( in_array( 'parse', $options, true ) ) {
853882 $string = $wgOut->parse( $string, true, !$forContent );
854 - } elseif ( in_array('parseinline', $options, true ) ) {
 883+ } elseif ( in_array( 'parseinline', $options, true ) ) {
855884 $string = $wgOut->parse( $string, true, !$forContent );
856885 $m = array();
857886 if( preg_match( '/^<p>(.*)\n?<\/p>\n?$/sU', $string, $m ) ) {
858887 $string = $m[1];
859888 }
860 - } elseif ( in_array('parsemag', $options, true ) ) {
 889+ } elseif ( in_array( 'parsemag', $options, true ) ) {
861890 global $wgMessageCache;
862891 if ( isset( $wgMessageCache ) ) {
863892 $string = $wgMessageCache->transform( $string,
@@ -865,13 +894,13 @@
866895 }
867896 }
868897
869 - if ( in_array('escape', $options, true ) ) {
 898+ if ( in_array( 'escape', $options, true ) ) {
870899 $string = htmlspecialchars ( $string );
871 - } elseif ( in_array( 'escapenoentities', $options, true ) ) {
 900+ } elseif ( in_array( 'escapenoentities', $options, true ) ) {
872901 $string = Sanitizer::escapeHtmlAllowEntities( $string );
873902 }
874903
875 - if( in_array('replaceafter', $options, true ) ) {
 904+ if( in_array( 'replaceafter', $options, true ) ) {
876905 $string = wfMsgReplaceArgs( $string, $args );
877906 }
878907
@@ -885,22 +914,22 @@
886915 *
887916 * @deprecated Please return control to the caller or throw an exception
888917 */
889 -function wfAbruptExit( $error = false ){
 918+function wfAbruptExit( $error = false ) {
890919 static $called = false;
891 - if ( $called ){
 920+ if ( $called ) {
892921 exit( -1 );
893922 }
894923 $called = true;
895924
896925 $bt = wfDebugBacktrace();
897926 if( $bt ) {
898 - for($i = 0; $i < count($bt) ; $i++){
899 - $file = isset($bt[$i]['file']) ? $bt[$i]['file'] : "unknown";
900 - $line = isset($bt[$i]['line']) ? $bt[$i]['line'] : "unknown";
901 - wfDebug("WARNING: Abrupt exit in $file at line $line\n");
 927+ for( $i = 0; $i < count( $bt ); $i++ ) {
 928+ $file = isset( $bt[$i]['file'] ) ? $bt[$i]['file'] : 'unknown';
 929+ $line = isset( $bt[$i]['line'] ) ? $bt[$i]['line'] : 'unknown';
 930+ wfDebug( "WARNING: Abrupt exit in $file at line $line\n");
902931 }
903932 } else {
904 - wfDebug("WARNING: Abrupt exit\n");
 933+ wfDebug( "WARNING: Abrupt exit\n" );
905934 }
906935
907936 wfLogProfilingData();
@@ -923,7 +952,7 @@
924953 * Plain die() fails to return nonzero to the shell if you pass a string.
925954 * @param $msg String
926955 */
927 -function wfDie( $msg='' ) {
 956+function wfDie( $msg = '' ) {
928957 echo $msg;
929958 die( 1 );
930959 }
@@ -978,8 +1007,8 @@
9791008 $elapsed = $now - $wgRequestTime;
9801009
9811010 return $wgShowHostnames
982 - ? sprintf( "<!-- Served by %s in %01.3f secs. -->", wfHostname(), $elapsed )
983 - : sprintf( "<!-- Served in %01.3f secs. -->", $elapsed );
 1011+ ? sprintf( '<!-- Served by %s in %01.3f secs. -->', wfHostname(), $elapsed )
 1012+ : sprintf( '<!-- Served in %01.3f secs. -->', $elapsed );
9841013 }
9851014
9861015 /**
@@ -1032,7 +1061,7 @@
10331062 foreach( $backtrace as $call ) {
10341063 if( isset( $call['file'] ) ) {
10351064 $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
1036 - $file = $f[count($f)-1];
 1065+ $file = $f[count( $f ) - 1];
10371066 } else {
10381067 $file = '-';
10391068 }
@@ -1046,7 +1075,9 @@
10471076 } else {
10481077 $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
10491078 }
1050 - if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
 1079+ if( !empty( $call['class'] ) ) {
 1080+ $msg .= $call['class'] . '::';
 1081+ }
10511082 $msg .= $call['function'] . '()';
10521083
10531084 if ( $wgCommandLineMode ) {
@@ -1073,8 +1104,12 @@
10741105 */
10751106 function wfShowingResults( $offset, $limit ) {
10761107 global $wgLang;
1077 - return wfMsgExt( 'showingresults', array( 'parseinline' ), $wgLang->formatNum( $limit ),
1078 - $wgLang->formatNum( $offset+1 ) );
 1108+ return wfMsgExt(
 1109+ 'showingresults',
 1110+ array( 'parseinline' ),
 1111+ $wgLang->formatNum( $limit ),
 1112+ $wgLang->formatNum( $offset + 1 )
 1113+ );
10791114 }
10801115
10811116 /**
@@ -1082,8 +1117,13 @@
10831118 */
10841119 function wfShowingResultsNum( $offset, $limit, $num ) {
10851120 global $wgLang;
1086 - return wfMsgExt( 'showingresultsnum', array( 'parseinline' ), $wgLang->formatNum( $limit ),
1087 - $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );
 1121+ return wfMsgExt(
 1122+ 'showingresultsnum',
 1123+ array( 'parseinline' ),
 1124+ $wgLang->formatNum( $limit ),
 1125+ $wgLang->formatNum( $offset + 1 ),
 1126+ $wgLang->formatNum( $num )
 1127+ );
10881128 }
10891129
10901130 /**
@@ -1099,11 +1139,11 @@
11001140 $fmtLimit = $wgLang->formatNum( $limit );
11011141 // FIXME: Why on earth this needs one message for the text and another one for tooltip??
11021142 # Get prev/next link display text
1103 - $prev = wfMsgExt( 'prevn', array('parsemag','escape'), $fmtLimit );
1104 - $next = wfMsgExt( 'nextn', array('parsemag','escape'), $fmtLimit );
 1143+ $prev = wfMsgExt( 'prevn', array( 'parsemag', 'escape' ), $fmtLimit );
 1144+ $next = wfMsgExt( 'nextn', array( 'parsemag', 'escape' ), $fmtLimit );
11051145 # Get prev/next link title text
1106 - $pTitle = wfMsgExt( 'prevn-title', array('parsemag','escape'), $fmtLimit );
1107 - $nTitle = wfMsgExt( 'nextn-title', array('parsemag','escape'), $fmtLimit );
 1146+ $pTitle = wfMsgExt( 'prevn-title', array( 'parsemag', 'escape' ), $fmtLimit );
 1147+ $nTitle = wfMsgExt( 'nextn-title', array( 'parsemag', 'escape' ), $fmtLimit );
11081148 # Fetch the title object
11091149 if( is_object( $link ) ) {
11101150 $title =& $link;
@@ -1116,12 +1156,12 @@
11171157 # Make 'previous' link
11181158 if( 0 != $offset ) {
11191159 $po = $offset - $limit;
1120 - $po = max($po,0);
 1160+ $po = max( $po, 0 );
11211161 $q = "limit={$limit}&offset={$po}";
11221162 if( $query != '' ) {
1123 - $q .= '&'.$query;
 1163+ $q .= '&' . $query;
11241164 }
1125 - $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
 1165+ $plink = '<a href="' . $title->escapeLocalURL( $q ) . "\" title=\"{$pTitle}\" class=\"mw-prevlink\">{$prev}</a>";
11261166 } else {
11271167 $plink = $prev;
11281168 }
@@ -1129,12 +1169,12 @@
11301170 $no = $offset + $limit;
11311171 $q = "limit={$limit}&offset={$no}";
11321172 if( $query != '' ) {
1133 - $q .= '&'.$query;
 1173+ $q .= '&' . $query;
11341174 }
11351175 if( $atend ) {
11361176 $nlink = $next;
11371177 } else {
1138 - $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
 1178+ $nlink = '<a href="' . $title->escapeLocalURL( $q ) . "\" title=\"{$nTitle}\" class=\"mw-nextlink\">{$next}</a>";
11391179 }
11401180 # Make links to set number of items per page
11411181 $nums = $wgLang->pipeList( array(
@@ -1163,8 +1203,8 @@
11641204 }
11651205 $q .= "limit={$limit}&offset={$offset}";
11661206 $fmtLimit = $wgLang->formatNum( $limit );
1167 - $lTitle = wfMsgExt('shown-title',array('parsemag','escape'),$limit);
1168 - $s = '<a href="' . $title->escapeLocalUrl( $q ) . "\" title=\"{$lTitle}\" class=\"mw-numlink\">{$fmtLimit}</a>";
 1207+ $lTitle = wfMsgExt( 'shown-title', array( 'parsemag', 'escape' ), $limit );
 1208+ $s = '<a href="' . $title->escapeLocalURL( $q ) . "\" title=\"{$lTitle}\" class=\"mw-numlink\">{$fmtLimit}</a>";
11691209 return $s;
11701210 }
11711211
@@ -1181,8 +1221,12 @@
11821222 if( preg_match(
11831223 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
11841224 $_SERVER['HTTP_ACCEPT_ENCODING'],
1185 - $m ) ) {
1186 - if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false;
 1225+ $m )
 1226+ )
 1227+ {
 1228+ if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) {
 1229+ return false;
 1230+ }
11871231 wfDebug( " accepts gzip\n" );
11881232 return true;
11891233 }
@@ -1218,7 +1262,8 @@
12191263 $text = str_replace(
12201264 array( '[', '|', ']', '\'', 'ISBN ', 'RFC ', '://', "\n=", '{{' ), # }}
12211265 array( '&#91;', '&#124;', '&#93;', '&#39;', 'ISBN&#32;', 'RFC&#32;', '&#58;//', "\n&#61;", '&#123;&#123;' ),
1222 - htmlspecialchars($text) );
 1266+ htmlspecialchars( $text )
 1267+ );
12231268 return $text;
12241269 }
12251270
@@ -1236,7 +1281,9 @@
12371282
12381283 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
12391284 $replace = $illegal . '\t ?_';
1240 - if( !preg_match( "/[$illegal]/", $string ) ) return $string;
 1285+ if( !preg_match( "/[$illegal]/", $string ) ) {
 1286+ return $string;
 1287+ }
12411288 $out = "=?$charset?Q?";
12421289 $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
12431290 $out .= '?=';
@@ -1249,7 +1296,7 @@
12501297 * @return float
12511298 */
12521299 function wfTime() {
1253 - return microtime(true);
 1300+ return microtime( true );
12541301 }
12551302
12561303 /**
@@ -1268,7 +1315,7 @@
12691316 * As for wfSetVar except setting a bit
12701317 */
12711318 function wfSetBit( &$dest, $bit, $state = true ) {
1272 - $temp = (bool)($dest & $bit );
 1319+ $temp = (bool)( $dest & $bit );
12731320 if ( !is_null( $state ) ) {
12741321 if ( $state ) {
12751322 $dest |= $bit;
@@ -1284,8 +1331,7 @@
12851332 * "days=7&limit=100". Options in the first array override options in the second.
12861333 * Options set to "" will not be output.
12871334 */
1288 -function wfArrayToCGI( $array1, $array2 = null )
1289 -{
 1335+function wfArrayToCGI( $array1, $array2 = null ) {
12901336 if ( !is_null( $array2 ) ) {
12911337 $array1 = $array1 + $array2;
12921338 }
@@ -1327,7 +1373,7 @@
13281374 * @return array Array version of input
13291375 */
13301376 function wfCgiToArray( $query ) {
1331 - if( isset( $query[0] ) and $query[0] == '?' ) {
 1377+ if( isset( $query[0] ) && $query[0] == '?' ) {
13321378 $query = substr( $query, 1 );
13331379 }
13341380 $bits = explode( '&', $query );
@@ -1393,7 +1439,7 @@
13941440 * This is obsolete, use SquidUpdate::purge()
13951441 * @deprecated
13961442 */
1397 -function wfPurgeSquidServers ($urlArr) {
 1443+function wfPurgeSquidServers( $urlArr ) {
13981444 SquidUpdate::purge( $urlArr );
13991445 }
14001446
@@ -1429,7 +1475,7 @@
14301476 if ( $iteration % 2 == 1 ) {
14311477 // Delimiter, a double quote preceded by zero or more slashes
14321478 $arg .= str_replace( '\\', '\\\\', substr( $token, 0, -1 ) ) . '\\"';
1433 - } else if ( $iteration % 4 == 2 ) {
 1479+ } elseif ( $iteration % 4 == 2 ) {
14341480 // ^ in $token will be outside quotes, need to be escaped
14351481 $arg .= str_replace( '^', '^^', $token );
14361482 } else { // $iteration % 4 == 0
@@ -1458,7 +1504,7 @@
14591505 * wfMerge attempts to merge differences between three texts.
14601506 * Returns true for a clean merge and false for failure or a conflict.
14611507 */
1462 -function wfMerge( $old, $mine, $yours, &$result ){
 1508+function wfMerge( $old, $mine, $yours, &$result ) {
14631509 global $wgDiff3;
14641510
14651511 # This check may also protect against code injection in
@@ -1474,18 +1520,21 @@
14751521 $mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
14761522 $yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
14771523
1478 - fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
1479 - fwrite( $mytextFile, $mine ); fclose( $mytextFile );
1480 - fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
 1524+ fwrite( $oldtextFile, $old );
 1525+ fclose( $oldtextFile );
 1526+ fwrite( $mytextFile, $mine );
 1527+ fclose( $mytextFile );
 1528+ fwrite( $yourtextFile, $yours );
 1529+ fclose( $yourtextFile );
14811530
14821531 # Check for a conflict
14831532 $cmd = $wgDiff3 . ' -a --overlap-only ' .
1484 - wfEscapeShellArg( $mytextName ) . ' ' .
1485 - wfEscapeShellArg( $oldtextName ) . ' ' .
1486 - wfEscapeShellArg( $yourtextName );
 1533+ wfEscapeShellArg( $mytextName ) . ' ' .
 1534+ wfEscapeShellArg( $oldtextName ) . ' ' .
 1535+ wfEscapeShellArg( $yourtextName );
14871536 $handle = popen( $cmd, 'r' );
14881537
1489 - if( fgets( $handle, 1024 ) ){
 1538+ if( fgets( $handle, 1024 ) ) {
14901539 $conflict = true;
14911540 } else {
14921541 $conflict = false;
@@ -1494,7 +1543,7 @@
14951544
14961545 # Merge differences
14971546 $cmd = $wgDiff3 . ' -a -e --merge ' .
1498 - wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
 1547+ wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
14991548 $handle = popen( $cmd, 'r' );
15001549 $result = '';
15011550 do {
@@ -1505,13 +1554,15 @@
15061555 $result .= $data;
15071556 } while ( true );
15081557 pclose( $handle );
1509 - unlink( $mytextName ); unlink( $oldtextName ); unlink( $yourtextName );
 1558+ unlink( $mytextName );
 1559+ unlink( $oldtextName );
 1560+ unlink( $yourtextName );
15101561
15111562 if ( $result === '' && $old !== '' && !$conflict ) {
15121563 wfDebug( "Unexpected null result from diff3. Command: $cmd\n" );
15131564 $conflict = true;
15141565 }
1515 - return ! $conflict;
 1566+ return !$conflict;
15161567 }
15171568
15181569 /**
@@ -1523,7 +1574,7 @@
15241575 * @return String: unified diff of $before and $after
15251576 */
15261577 function wfDiff( $before, $after, $params = '-u' ) {
1527 - if ($before == $after) {
 1578+ if ( $before == $after ) {
15281579 return '';
15291580 }
15301581
@@ -1531,7 +1582,7 @@
15321583
15331584 # This check may also protect against code injection in
15341585 # case of broken installations.
1535 - if( !file_exists( $wgDiff ) ){
 1586+ if( !file_exists( $wgDiff ) ) {
15361587 wfDebug( "diff executable not found\n" );
15371588 $diffs = new Diff( explode( "\n", $before ), explode( "\n", $after ) );
15381589 $format = new UnifiedDiffFormatter();
@@ -1543,11 +1594,13 @@
15441595 $oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
15451596 $newtextFile = fopen( $newtextName = tempnam( $td, 'merge-your-' ), 'w' );
15461597
1547 - fwrite( $oldtextFile, $before ); fclose( $oldtextFile );
1548 - fwrite( $newtextFile, $after ); fclose( $newtextFile );
 1598+ fwrite( $oldtextFile, $before );
 1599+ fclose( $oldtextFile );
 1600+ fwrite( $newtextFile, $after );
 1601+ fclose( $newtextFile );
15491602
15501603 // Get the diff of the two files
1551 - $cmd = "$wgDiff " . $params . ' ' .wfEscapeShellArg( $oldtextName, $newtextName );
 1604+ $cmd = "$wgDiff " . $params . ' ' . wfEscapeShellArg( $oldtextName, $newtextName );
15521605
15531606 $h = popen( $cmd, 'r' );
15541607
@@ -1568,11 +1621,11 @@
15691622
15701623 // Kill the --- and +++ lines. They're not useful.
15711624 $diff_lines = explode( "\n", $diff );
1572 - if (strpos( $diff_lines[0], '---' ) === 0) {
1573 - unset($diff_lines[0]);
 1625+ if ( strpos( $diff_lines[0], '---' ) === 0 ) {
 1626+ unset( $diff_lines[0] );
15741627 }
1575 - if (strpos( $diff_lines[1], '+++' ) === 0) {
1576 - unset($diff_lines[1]);
 1628+ if ( strpos( $diff_lines[1], '+++' ) === 0 ) {
 1629+ unset( $diff_lines[1] );
15771630 }
15781631
15791632 $diff = implode( "\n", $diff_lines );
@@ -1588,7 +1641,7 @@
15891642 */
15901643 function wfVarDump( $var ) {
15911644 global $wgOut;
1592 - $s = str_replace("\n","<br />\n", var_export( $var, true ) . "\n");
 1645+ $s = str_replace( "\n", "<br />\n", var_export( $var, true ) . "\n" );
15931646 if ( headers_sent() || !@is_object( $wgOut ) ) {
15941647 print $s;
15951648 } else {
@@ -1608,11 +1661,11 @@
16091662
16101663 header( 'Content-type: text/html; charset=utf-8' );
16111664 print "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">".
1612 - "<html><head><title>" .
 1665+ '<html><head><title>' .
16131666 htmlspecialchars( $label ) .
1614 - "</title></head><body><h1>" .
 1667+ '</title></head><body><h1>' .
16151668 htmlspecialchars( $label ) .
1616 - "</h1><p>" .
 1669+ '</h1><p>' .
16171670 nl2br( htmlspecialchars( $desc ) ) .
16181671 "</p></body></html>\n";
16191672 }
@@ -1634,7 +1687,7 @@
16351688 *
16361689 * @param $resetGzipEncoding Bool
16371690 */
1638 -function wfResetOutputBuffers( $resetGzipEncoding=true ) {
 1691+function wfResetOutputBuffers( $resetGzipEncoding = true ) {
16391692 if( $resetGzipEncoding ) {
16401693 // Suppress Content-Encoding and Content-Length
16411694 // headers from 1.10+s wfOutputHandler
@@ -1703,7 +1756,7 @@
17041757 if( !isset( $qpart ) ) {
17051758 $prefs[$value] = 1.0;
17061759 } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
1707 - $prefs[$value] = floatval($match[1]);
 1760+ $prefs[$value] = floatval( $match[1] );
17081761 }
17091762 }
17101763
@@ -1723,7 +1776,7 @@
17241777 * @private
17251778 */
17261779 function mimeTypeMatch( $type, $avail ) {
1727 - if( array_key_exists($type, $avail) ) {
 1780+ if( array_key_exists( $type, $avail ) ) {
17281781 return $type;
17291782 } else {
17301783 $parts = explode( '/', $type );
@@ -1840,29 +1893,29 @@
18411894 /**
18421895 * Unix time - the number of seconds since 1970-01-01 00:00:00 UTC
18431896 */
1844 -define('TS_UNIX', 0);
 1897+define( 'TS_UNIX', 0 );
18451898
18461899 /**
18471900 * MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
18481901 */
1849 -define('TS_MW', 1);
 1902+define( 'TS_MW', 1 );
18501903
18511904 /**
18521905 * MySQL DATETIME (YYYY-MM-DD HH:MM:SS)
18531906 */
1854 -define('TS_DB', 2);
 1907+define( 'TS_DB', 2 );
18551908
18561909 /**
18571910 * RFC 2822 format, for E-mail and HTTP headers
18581911 */
1859 -define('TS_RFC2822', 3);
 1912+define( 'TS_RFC2822', 3 );
18601913
18611914 /**
18621915 * ISO 8601 format with no timezone: 1986-02-09T20:00:00Z
18631916 *
18641917 * This is used by Special:Export
18651918 */
1866 -define('TS_ISO_8601', 4);
 1919+define( 'TS_ISO_8601', 4 );
18671920
18681921 /**
18691922 * An Exif timestamp (YYYY:MM:DD HH:MM:SS)
@@ -1871,22 +1924,22 @@
18721925 * DateTime tag and page 36 for the DateTimeOriginal and
18731926 * DateTimeDigitized tags.
18741927 */
1875 -define('TS_EXIF', 5);
 1928+define( 'TS_EXIF', 5 );
18761929
18771930 /**
18781931 * Oracle format time.
18791932 */
1880 -define('TS_ORACLE', 6);
 1933+define( 'TS_ORACLE', 6 );
18811934
18821935 /**
18831936 * Postgres format time.
18841937 */
1885 -define('TS_POSTGRES', 7);
 1938+define( 'TS_POSTGRES', 7 );
18861939
18871940 /**
18881941 * DB2 format time
18891942 */
1890 -define('TS_DB2', 8);
 1943+define( 'TS_DB2', 8 );
18911944
18921945 /**
18931946 * @param $outputtype Mixed: A timestamp in one of the supported formats, the
@@ -1898,26 +1951,26 @@
18991952 function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
19001953 $uts = 0;
19011954 $da = array();
1902 - if ($ts==0) {
1903 - $uts=time();
1904 - } elseif (preg_match('/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D',$ts,$da)) {
 1955+ if ( $ts == 0 ) {
 1956+ $uts = time();
 1957+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
19051958 # TS_DB
1906 - } elseif (preg_match('/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/D',$ts,$da)) {
 1959+ } elseif ( preg_match( '/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
19071960 # TS_EXIF
1908 - } elseif (preg_match('/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D',$ts,$da)) {
 1961+ } elseif ( preg_match( '/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/D', $ts, $da ) ) {
19091962 # TS_MW
1910 - } elseif (preg_match('/^-?\d{1,13}$/D',$ts)) {
 1963+ } elseif ( preg_match( '/^-?\d{1,13}$/D', $ts ) ) {
19111964 # TS_UNIX
19121965 $uts = $ts;
1913 - } elseif (preg_match('/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts)) {
 1966+ } elseif ( preg_match( '/^\d{2}-\d{2}-\d{4} \d{2}:\d{2}:\d{2}.\d{6}$/', $ts ) ) {
19141967 # TS_ORACLE // session altered to DD-MM-YYYY HH24:MI:SS.FF6
1915 - $uts = strtotime(preg_replace('/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
1916 - str_replace("+00:00", "UTC", $ts)));
1917 - } elseif (preg_match('/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da)) {
 1968+ $uts = strtotime( preg_replace( '/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
 1969+ str_replace( '+00:00', 'UTC', $ts ) ) );
 1970+ } elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
19181971 # TS_ISO_8601
1919 - } elseif (preg_match('/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/',$ts,$da)) {
 1972+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
19201973 # TS_POSTGRES
1921 - } elseif (preg_match('/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/',$ts,$da)) {
 1974+ } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
19221975 # TS_POSTGRES
19231976 } else {
19241977 # Bogus value; fall back to the epoch...
@@ -1928,11 +1981,11 @@
19291982 if (count( $da ) ) {
19301983 // Warning! gmmktime() acts oddly if the month or day is set to 0
19311984 // We may want to handle that explicitly at some point
1932 - $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
1933 - (int)$da[2],(int)$da[3],(int)$da[1]);
 1985+ $uts = gmmktime( (int)$da[4], (int)$da[5], (int)$da[6],
 1986+ (int)$da[2], (int)$da[3], (int)$da[1] );
19341987 }
19351988
1936 - switch($outputtype) {
 1989+ switch( $outputtype ) {
19371990 case TS_UNIX:
19381991 return $uts;
19391992 case TS_MW:
@@ -1943,18 +1996,18 @@
19441997 return gmdate( 'Y-m-d\TH:i:s\Z', $uts );
19451998 // This shouldn't ever be used, but is included for completeness
19461999 case TS_EXIF:
1947 - return gmdate( 'Y:m:d H:i:s', $uts );
 2000+ return gmdate( 'Y:m:d H:i:s', $uts );
19482001 case TS_RFC2822:
19492002 return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
19502003 case TS_ORACLE:
1951 - return gmdate( 'd-m-Y H:i:s.000000', $uts);
1952 - //return gmdate( 'd-M-y h.i.s A', $uts) . ' +00:00';
 2004+ return gmdate( 'd-m-Y H:i:s.000000', $uts );
 2005+ //return gmdate( 'd-M-y h.i.s A', $uts ) . ' +00:00';
19532006 case TS_POSTGRES:
1954 - return gmdate( 'Y-m-d H:i:s', $uts) . ' GMT';
 2007+ return gmdate( 'Y-m-d H:i:s', $uts ) . ' GMT';
19552008 case TS_DB2:
1956 - return gmdate( 'Y-m-d H:i:s', $uts);
 2009+ return gmdate( 'Y-m-d H:i:s', $uts );
19572010 default:
1958 - throw new MWException( 'wfTimestamp() called with illegal output type.');
 2011+ throw new MWException( 'wfTimestamp() called with illegal output type.' );
19592012 }
19602013 }
19612014
@@ -1979,7 +2032,7 @@
19802033 * @return Bool: true if it's Windows, False otherwise.
19812034 */
19822035 function wfIsWindows() {
1983 - if (substr(php_uname(), 0, 7) == 'Windows') {
 2036+ if ( substr( php_uname(), 0, 7 ) == 'Windows' ) {
19842037 return true;
19852038 } else {
19862039 return false;
@@ -2037,11 +2090,11 @@
20382091 $parserMemc->set( $key, array( 'html' => $parsed, 'hash' => md5( $notice ) ), 600 );
20392092 $notice = $parsed;
20402093 } else {
2041 - wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available'."\n" );
 2094+ wfDebug( 'wfGetCachedNotice called for ' . $name . ' with no $wgOut available' . "\n" );
20422095 $notice = '';
20432096 }
20442097 }
2045 - $notice = '<div id="localNotice">'.$notice.'</div>';
 2098+ $notice = '<div id="localNotice">' .$notice . '</div>';
20462099 wfProfileOut( $fname );
20472100 return $notice;
20482101 }
@@ -2050,18 +2103,19 @@
20512104 global $wgTitle;
20522105
20532106 # Paranoia
2054 - if ( !isset( $wgTitle ) || !is_object( $wgTitle ) )
2055 - return "";
 2107+ if ( !isset( $wgTitle ) || !is_object( $wgTitle ) ) {
 2108+ return '';
 2109+ }
20562110
20572111 $fname = 'wfGetNamespaceNotice';
20582112 wfProfileIn( $fname );
20592113
2060 - $key = "namespacenotice-" . $wgTitle->getNsText();
 2114+ $key = 'namespacenotice-' . $wgTitle->getNsText();
20612115 $namespaceNotice = wfGetCachedNotice( $key );
2062 - if ( $namespaceNotice && substr ( $namespaceNotice , 0 ,7 ) != "<p>&lt;" ) {
2063 - $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . "</div>";
 2116+ if ( $namespaceNotice && substr( $namespaceNotice, 0, 7 ) != '<p>&lt;' ) {
 2117+ $namespaceNotice = '<div id="namespacebanner">' . $namespaceNotice . '</div>';
20642118 } else {
2065 - $namespaceNotice = "";
 2119+ $namespaceNotice = '';
20662120 }
20672121
20682122 wfProfileOut( $fname );
@@ -2145,17 +2199,19 @@
21462200 wfDebug( "$caller: called wfMkdirParents($dir)" );
21472201 }
21482202
2149 - if( strval( $dir ) === '' || file_exists( $dir ) )
 2203+ if( strval( $dir ) === '' || file_exists( $dir ) ) {
21502204 return true;
 2205+ }
21512206
21522207 $dir = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $dir );
21532208
2154 - if ( is_null( $mode ) )
 2209+ if ( is_null( $mode ) ) {
21552210 $mode = $wgDirectoryMode;
 2211+ }
21562212
21572213 // Turn off the normal warning, we're doing our own below
21582214 wfSuppressWarnings();
2159 - $ok = mkdir( $dir, $mode, true ); // PHP5 <3
 2215+ $ok = mkdir( $dir, $mode, true ); // PHP5 <3
21602216 wfRestoreWarnings();
21612217
21622218 if( !$ok ) {
@@ -2174,13 +2230,27 @@
21752231 if( $wgStatsMethod == 'udp' ) {
21762232 global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgDBname;
21772233 static $socket;
2178 - if (!$socket) {
2179 - $socket=socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
2180 - $statline="stats/{$wgDBname} - 1 1 1 1 1 -total\n";
2181 - socket_sendto($socket,$statline,strlen($statline),0,$wgUDPProfilerHost,$wgUDPProfilerPort);
 2234+ if ( !$socket ) {
 2235+ $socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP );
 2236+ $statline = "stats/{$wgDBname} - 1 1 1 1 1 -total\n";
 2237+ socket_sendto(
 2238+ $socket,
 2239+ $statline,
 2240+ strlen( $statline ),
 2241+ 0,
 2242+ $wgUDPProfilerHost,
 2243+ $wgUDPProfilerPort
 2244+ );
21822245 }
2183 - $statline="stats/{$wgDBname} - 1 1 1 1 1 {$key}\n";
2184 - @socket_sendto($socket,$statline,strlen($statline),0,$wgUDPProfilerHost,$wgUDPProfilerPort);
 2246+ $statline = "stats/{$wgDBname} - 1 1 1 1 1 {$key}\n";
 2247+ @socket_sendto(
 2248+ $socket,
 2249+ $statline,
 2250+ strlen( $statline ),
 2251+ 0,
 2252+ $wgUDPProfilerHost,
 2253+ $wgUDPProfilerPort
 2254+ );
21852255 } elseif( $wgStatsMethod == 'cache' ) {
21862256 global $wgMemc;
21872257 $key = wfMemcKey( 'stats', $key );
@@ -2214,7 +2284,7 @@
22152285 function wfEncryptPassword( $userid, $password ) {
22162286 wfDeprecated(__FUNCTION__);
22172287 # Just wrap around User::oldCrypt()
2218 - return User::oldCrypt($password, $userid);
 2288+ return User::oldCrypt( $password, $userid );
22192289 }
22202290
22212291 /**
@@ -2222,7 +2292,7 @@
22232293 */
22242294 function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
22252295 if ( is_null( $changed ) ) {
2226 - throw new MWException('GlobalFunctions::wfAppendToArrayIfNotDefault got null');
 2296+ throw new MWException( 'GlobalFunctions::wfAppendToArrayIfNotDefault got null' );
22272297 }
22282298 if ( $default[$key] !== $value ) {
22292299 $changed[$key] = $value;
@@ -2255,7 +2325,7 @@
22562326
22572327 function wfSpecialList( $page, $details ) {
22582328 global $wgContLang;
2259 - $details = $details ? ' ' . $wgContLang->getDirMark() . "($details)" : "";
 2329+ $details = $details ? ' ' . $wgContLang->getDirMark() . "($details)" : '';
22602330 return $page . $details;
22612331 }
22622332
@@ -2268,15 +2338,17 @@
22692339 global $wgUrlProtocols;
22702340
22712341 static $retval = null;
2272 - if ( !is_null( $retval ) )
 2342+ if ( !is_null( $retval ) ) {
22732343 return $retval;
 2344+ }
22742345
22752346 // Support old-style $wgUrlProtocols strings, for backwards compatibility
22762347 // with LocalSettings files from 1.5
22772348 if ( is_array( $wgUrlProtocols ) ) {
22782349 $protocols = array();
2279 - foreach ($wgUrlProtocols as $protocol)
 2350+ foreach ( $wgUrlProtocols as $protocol ) {
22802351 $protocols[] = preg_quote( $protocol, '/' );
 2352+ }
22812353
22822354 $retval = implode( '|', $protocols );
22832355 } else {
@@ -2349,7 +2421,7 @@
23502422 * (non-zero is usually failure)
23512423 * @return collected stdout as a string (trailing newlines stripped)
23522424 */
2353 -function wfShellExec( $cmd, &$retval=null ) {
 2425+function wfShellExec( $cmd, &$retval = null ) {
23542426 global $IP, $wgMaxShellMemory, $wgMaxShellFileSize, $wgMaxShellTime;
23552427
23562428 static $disabled;
@@ -2369,7 +2441,7 @@
23702442 }
23712443 if ( $disabled ) {
23722444 $retval = 1;
2373 - return "Unable to run external programs in safe mode.";
 2445+ return 'Unable to run external programs in safe mode.';
23742446 }
23752447
23762448 wfInitShellLocale();
@@ -2413,7 +2485,9 @@
24142486 */
24152487 function wfInitShellLocale() {
24162488 static $done = false;
2417 - if ( $done ) return;
 2489+ if ( $done ) {
 2490+ return;
 2491+ }
24182492 $done = true;
24192493 global $wgShellLocale;
24202494 if ( !wfIniGetBool( 'safe_mode' ) ) {
@@ -2440,8 +2514,9 @@
24412515 function wfUsePHP( $req_ver ) {
24422516 $php_ver = PHP_VERSION;
24432517
2444 - if ( version_compare( $php_ver, (string)$req_ver, '<' ) )
2445 - throw new MWException( "PHP $req_ver required--this is only $php_ver" );
 2518+ if ( version_compare( $php_ver, (string)$req_ver, '<' ) ) {
 2519+ throw new MWException( "PHP $req_ver required--this is only $php_ver" );
 2520+ }
24462521 }
24472522
24482523 /**
@@ -2460,8 +2535,9 @@
24612536 function wfUseMW( $req_ver ) {
24622537 global $wgVersion;
24632538
2464 - if ( version_compare( $wgVersion, (string)$req_ver, '<' ) )
 2539+ if ( version_compare( $wgVersion, (string)$req_ver, '<' ) ) {
24652540 throw new MWException( "MediaWiki $req_ver required--this is only $wgVersion" );
 2541+ }
24662542 }
24672543
24682544 /**
@@ -2476,8 +2552,8 @@
24772553 * @param $suffix String: to remove if present
24782554 * @return String
24792555 */
2480 -function wfBaseName( $path, $suffix='' ) {
2481 - $encSuffix = ($suffix == '')
 2556+function wfBaseName( $path, $suffix = '' ) {
 2557+ $encSuffix = ( $suffix == '' )
24822558 ? ''
24832559 : ( '(?:' . preg_quote( $suffix, '#' ) . ')?' );
24842560 $matches = array();
@@ -2506,7 +2582,7 @@
25072583 $path = rtrim( $path, DIRECTORY_SEPARATOR );
25082584 $from = rtrim( $from, DIRECTORY_SEPARATOR );
25092585
2510 - $pieces = explode( DIRECTORY_SEPARATOR, dirname( $path ) );
 2586+ $pieces = explode( DIRECTORY_SEPARATOR, dirname( $path ) );
25112587 $against = explode( DIRECTORY_SEPARATOR, $from );
25122588
25132589 if( $pieces[0] !== $against[0] ) {
@@ -2607,7 +2683,7 @@
26082684 $bits['delimiter'] = ':';
26092685 // parse_url detects for news: and mailto: the host part of an url as path
26102686 // We have to correct this wrong detection
2611 - if ( isset ( $bits['path'] ) ) {
 2687+ if ( isset( $bits['path'] ) ) {
26122688 $bits['host'] = $bits['path'];
26132689 $bits['path'] = '';
26142690 }
@@ -2628,7 +2704,7 @@
26292705 // For emails reverse domainpart only
26302706 if ( $bits['scheme'] == 'mailto' ) {
26312707 $mailparts = explode( '@', $bits['host'], 2 );
2632 - if ( count($mailparts) === 2 ) {
 2708+ if ( count( $mailparts ) === 2 ) {
26332709 $domainpart = strtolower( implode( '.', array_reverse( explode( '.', $mailparts[1] ) ) ) );
26342710 } else {
26352711 // No domain specified, don't mangle it
@@ -2647,14 +2723,20 @@
26482724 $prot = $bits['scheme'];
26492725 $index = $prot . $bits['delimiter'] . $reversedHost;
26502726 // Leave out user and password. Add the port, path, query and fragment
2651 - if ( isset( $bits['port'] ) ) $index .= ':' . $bits['port'];
 2727+ if ( isset( $bits['port'] ) ) {
 2728+ $index .= ':' . $bits['port'];
 2729+ }
26522730 if ( isset( $bits['path'] ) ) {
26532731 $index .= $bits['path'];
26542732 } else {
26552733 $index .= '/';
26562734 }
2657 - if ( isset( $bits['query'] ) ) $index .= '?' . $bits['query'];
2658 - if ( isset( $bits['fragment'] ) ) $index .= '#' . $bits['fragment'];
 2735+ if ( isset( $bits['query'] ) ) {
 2736+ $index .= '?' . $bits['query'];
 2737+ }
 2738+ if ( isset( $bits['fragment'] ) ) {
 2739+ $index .= '#' . $bits['fragment'];
 2740+ }
26592741 return $index;
26602742 }
26612743
@@ -2662,8 +2744,7 @@
26632745 * Do any deferred updates and clear the list
26642746 * TODO: This could be in Wiki.php if that class made any sense at all
26652747 */
2666 -function wfDoUpdates()
2667 -{
 2748+function wfDoUpdates() {
26682749 global $wgPostCommitUpdateList, $wgDeferredUpdateList;
26692750 foreach ( $wgDeferredUpdateList as $update ) {
26702751 $update->doUpdate();
@@ -2689,7 +2770,7 @@
26902771 * @param $lowercase Boolean
26912772 * @return String or false on invalid input
26922773 */
2693 -function wfBaseConvert( $input, $sourceBase, $destBase, $pad=1, $lowercase=true ) {
 2774+function wfBaseConvert( $input, $sourceBase, $destBase, $pad = 1, $lowercase = true ) {
26942775 $input = strval( $input );
26952776 if( $sourceBase < 2 ||
26962777 $sourceBase > 36 ||
@@ -2703,7 +2784,7 @@
27042785 $input == '' ) {
27052786 return false;
27062787 }
2707 - $digitChars = ( $lowercase ) ? '0123456789abcdefghijklmnopqrstuvwxyz' : '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
 2788+ $digitChars = ( $lowercase ) ? '0123456789abcdefghijklmnopqrstuvwxyz' : '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
27082789 $inDigits = array();
27092790 $outChars = '';
27102791
@@ -2767,7 +2848,7 @@
27682849 * @param $name String
27692850 * @param $p Array: parameters
27702851 */
2771 -function wfCreateObject( $name, $p ){
 2852+function wfCreateObject( $name, $p ) {
27722853 $p = array_values( $p );
27732854 switch ( count( $p ) ) {
27742855 case 0:
@@ -2785,14 +2866,15 @@
27862867 case 6:
27872868 return new $name( $p[0], $p[1], $p[2], $p[3], $p[4], $p[5] );
27882869 default:
2789 - throw new MWException( "Too many arguments to construtor in wfCreateObject" );
 2870+ throw new MWException( 'Too many arguments to construtor in wfCreateObject' );
27902871 }
27912872 }
27922873
27932874 function wfHttpOnlySafe() {
27942875 global $wgHttpOnlyBlacklist;
2795 - if( !version_compare("5.2", PHP_VERSION, "<") )
 2876+ if( !version_compare( '5.2', PHP_VERSION, '<' ) ) {
27962877 return false;
 2878+ }
27972879
27982880 if( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
27992881 foreach( $wgHttpOnlyBlacklist as $regex ) {
@@ -2816,7 +2898,7 @@
28172899 } elseif( $wgSessionHandler && $wgSessionHandler != ini_get( 'session.save_handler' ) ) {
28182900 # Only set this if $wgSessionHandler isn't null and session.save_handler
28192901 # hasn't already been set to the desired value (that causes errors)
2820 - ini_set ( 'session.save_handler', $wgSessionHandler );
 2902+ ini_set( 'session.save_handler', $wgSessionHandler );
28212903 }
28222904 $httpOnlySafe = wfHttpOnlySafe();
28232905 wfDebugLog( 'cookie',
@@ -2860,7 +2942,7 @@
28612943 function wfGetCaller( $level = 2 ) {
28622944 $backtrace = wfDebugBacktrace();
28632945 if ( isset( $backtrace[$level] ) ) {
2864 - return wfFormatStackFrame($backtrace[$level]);
 2946+ return wfFormatStackFrame( $backtrace[$level] );
28652947 } else {
28662948 $caller = 'unknown';
28672949 }
@@ -2886,10 +2968,10 @@
28872969 /**
28882970 * Return a string representation of frame
28892971 */
2890 -function wfFormatStackFrame($frame) {
2891 - return isset( $frame["class"] )?
2892 - $frame["class"]."::".$frame["function"]:
2893 - $frame["function"];
 2972+function wfFormatStackFrame( $frame ) {
 2973+ return isset( $frame['class'] ) ?
 2974+ $frame['class'] . '::' . $frame['function'] :
 2975+ $frame['function'];
28942976 }
28952977
28962978 /**
@@ -2939,7 +3021,7 @@
29403022 return $bits;
29413023 }
29423024
2943 -/*
 3025+/**
29443026 * Get a Database object.
29453027 * @param $db Integer: index of the connection to get. May be DB_MASTER for the
29463028 * master (for write queries), DB_SLAVE for potentially lagged read
@@ -2954,7 +3036,7 @@
29553037 * Note: multiple calls to wfGetDB(DB_SLAVE) during the course of one request
29563038 * will always return the same object, unless the underlying connection or load
29573039 * balancer is manually destroyed.
2958 - *
 3040+ *
29593041 * @return DatabaseBase
29603042 */
29613043 function &wfGetDB( $db, $groups = array(), $wiki = false ) {
@@ -3035,12 +3117,13 @@
30363118 global $wgScriptPath, $wgScriptExtension;
30373119 return "{$wgScriptPath}/{$script}{$wgScriptExtension}";
30383120 }
 3121+
30393122 /**
3040 - * Get the script url.
 3123+ * Get the script URL.
30413124 *
3042 - * @return script url
 3125+ * @return script URL
30433126 */
3044 -function wfGetScriptUrl(){
 3127+function wfGetScriptUrl() {
30453128 if( isset( $_SERVER['SCRIPT_NAME'] ) ) {
30463129 #
30473130 # as it was called, minus the query string.
@@ -3133,17 +3216,18 @@
31343217 */
31353218 function wfWarn( $msg, $callerOffset = 1, $level = E_USER_NOTICE ) {
31363219 $callers = wfDebugBacktrace();
3137 - if( isset( $callers[$callerOffset+1] ) ){
3138 - $callerfunc = $callers[$callerOffset+1];
 3220+ if( isset( $callers[$callerOffset + 1] ) ){
 3221+ $callerfunc = $callers[$callerOffset + 1];
31393222 $callerfile = $callers[$callerOffset];
3140 - if( isset( $callerfile['file'] ) && isset( $callerfile['line'] ) ){
 3223+ if( isset( $callerfile['file'] ) && isset( $callerfile['line'] ) ) {
31413224 $file = $callerfile['file'] . ' at line ' . $callerfile['line'];
31423225 } else {
31433226 $file = '(internal function)';
31443227 }
31453228 $func = '';
3146 - if( isset( $callerfunc['class'] ) )
 3229+ if( isset( $callerfunc['class'] ) ) {
31473230 $func .= $callerfunc['class'] . '::';
 3231+ }
31483232 $func .= @$callerfunc['function'];
31493233 $msg .= " [Called from $func in $file]";
31503234 }
@@ -3180,7 +3264,7 @@
31813265 $host = $name;
31823266 }
31833267 print "Waiting for $host (lagged $lag seconds)...\n";
3184 - sleep($maxLag);
 3268+ sleep( $maxLag );
31853269 list( $host, $lag ) = $lb->getMaxLag();
31863270 }
31873271 }
@@ -3218,12 +3302,13 @@
32193303 echo "\n";
32203304 }
32213305
3222 -/** Generate a random 32-character hexadecimal token.
 3306+/**
 3307+ * Generate a random 32-character hexadecimal token.
32233308 * @param $salt Mixed: some sort of salt, if necessary, to add to random
32243309 * characters before hashing.
32253310 */
32263311 function wfGenerateToken( $salt = '' ) {
3227 - $salt = serialize($salt);
 3312+ $salt = serialize( $salt );
32283313
32293314 return md5( mt_rand( 0, 0x7fffffff ) . $salt );
32303315 }
@@ -3235,7 +3320,13 @@
32363321 function wfStripIllegalFilenameChars( $name ) {
32373322 global $wgIllegalFileChars;
32383323 $name = wfBaseName( $name );
3239 - $name = preg_replace("/[^".Title::legalChars()."]".($wgIllegalFileChars ? "|[".$wgIllegalFileChars."]":"")."/",'-',$name);
 3324+ $name = preg_replace(
 3325+ "/[^" . Title::legalChars() . "]" .
 3326+ ( $wgIllegalFileChars ? "|[" . $wgIllegalFileChars . "]" : '' ) .
 3327+ "/",
 3328+ '-',
 3329+ $name
 3330+ );
32403331 return $name;
32413332 }
32423333
@@ -3247,14 +3338,14 @@
32483339 */
32493340 function wfArrayInsertAfter( $array, $insert, $after ) {
32503341 // Find the offset of the element to insert after.
3251 - $keys = array_keys($array);
 3342+ $keys = array_keys( $array );
32523343 $offsetByKey = array_flip( $keys );
32533344
32543345 $offset = $offsetByKey[$after];
32553346
32563347 // Insert at the specified offset
32573348 $before = array_slice( $array, 0, $offset + 1, true );
3258 - $after = array_slice( $array, $offset + 1, count($array)-$offset, true );
 3349+ $after = array_slice( $array, $offset + 1, count( $array ) - $offset, true );
32593350
32603351 $output = $before + $insert + $after;
32613352
@@ -3281,19 +3372,19 @@
32823373 */
32833374 function wfMemoryLimit() {
32843375 global $wgMemoryLimit;
3285 - $memlimit = wfShorthandToInteger( ini_get( "memory_limit" ) );
 3376+ $memlimit = wfShorthandToInteger( ini_get( 'memory_limit' ) );
32863377 $conflimit = wfShorthandToInteger( $wgMemoryLimit );
32873378 if( $memlimit != -1 ) {
32883379 if( $conflimit == -1 ) {
32893380 wfDebug( "Removing PHP's memory limit\n" );
32903381 wfSuppressWarnings();
3291 - ini_set( "memory_limit", $conflimit );
 3382+ ini_set( 'memory_limit', $conflimit );
32923383 wfRestoreWarnings();
32933384 return $conflimit;
32943385 } elseif ( $conflimit > $memlimit ) {
32953386 wfDebug( "Raising PHP's memory limit to $conflimit bytes\n" );
32963387 wfSuppressWarnings();
3297 - ini_set( "memory_limit", $conflimit );
 3388+ ini_set( 'memory_limit', $conflimit );
32983389 wfRestoreWarnings();
32993390 return $conflimit;
33003391 }
@@ -3306,12 +3397,14 @@
33073398 * @param $string String
33083399 * @return Integer
33093400 */
3310 -function wfShorthandToInteger ( $string = '' ) {
3311 - $string = trim($string);
3312 - if( empty($string) ) { return -1; }
3313 - $last = strtolower($string[strlen($string)-1]);
3314 - $val = intval($string);
3315 - switch($last) {
 3401+function wfShorthandToInteger( $string = '' ) {
 3402+ $string = trim( $string );
 3403+ if( empty( $string ) ) {
 3404+ return -1;
 3405+ }
 3406+ $last = strtolower( $string[strlen( $string ) - 1] );
 3407+ $val = intval( $string );
 3408+ switch( $last ) {
33163409 case 'g':
33173410 $val *= 1024;
33183411 case 'm':
@@ -3323,7 +3416,8 @@
33243417 return $val;
33253418 }
33263419
3327 -/* Get the normalised IETF language tag
 3420+/**
 3421+ * Get the normalised IETF language tag
33283422 * @param $code String: The language code.
33293423 * @return $langCode String: The language code which complying with BCP 47 standards.
33303424 */
@@ -3332,20 +3426,21 @@
33333427 foreach ( $codeSegment as $segNo => $seg ) {
33343428 if ( count( $codeSegment ) > 0 ) {
33353429 // ISO 3166 country code
3336 - if ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) )
 3430+ if ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) {
33373431 $codeBCP[$segNo] = strtoupper( $seg );
33383432 // ISO 15924 script code
3339 - else if ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) )
 3433+ } elseif ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) {
33403434 $codeBCP[$segNo] = ucfirst( $seg );
33413435 // Use lowercase for other cases
3342 - else
 3436+ } else {
33433437 $codeBCP[$segNo] = strtolower( $seg );
 3438+ }
33443439 } else {
33453440 // Use lowercase for single segment
33463441 $codeBCP[$segNo] = strtolower( $seg );
33473442 }
33483443 }
3349 - $langCode = implode ( '-' , $codeBCP );
 3444+ $langCode = implode( '-', $codeBCP );
33503445 return $langCode;
33513446 }
33523447

Status & tagging log