X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=includes%2FGlobalFunctions.php;h=7e4d9117a012b63d621c73fe4800ba23e78286ff;hb=5cc5b123cd49440dc5a3c6ab1af356494febecf5;hp=515dd68beda8d64eb4b9f5eb080f875fe8da8b9a;hpb=e3676a470c57d61b0380238e47b66902e429fbb9;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 515dd68bed..7e4d9117a0 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -5,9 +5,9 @@ $wgNumberOfArticles = -1; # Unset $wgTotalViews = -1; $wgTotalEdits = -1; -require_once( "DatabaseFunctions.php" ); -require_once( "UpdateClasses.php" ); -require_once( "LogPage.php" ); +require_once( 'DatabaseFunctions.php' ); +require_once( 'UpdateClasses.php' ); +require_once( 'LogPage.php' ); /* * Compatibility functions @@ -23,8 +23,8 @@ if( !function_exists('iconv') ) { # This will *not* work in all circumstances. function iconv( $from, $to, $string ) { if(strcasecmp( $from, $to ) == 0) return $string; - if(strcasecmp( $from, "utf-8" ) == 0) return utf8_decode( $string ); - if(strcasecmp( $to, "utf-8" ) == 0) return utf8_encode( $string ); + if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string ); + if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string ); return $string; } } @@ -32,7 +32,7 @@ if( !function_exists('iconv') ) { if( !function_exists('file_get_contents') ) { # Exists in PHP 4.3.0+ function file_get_contents( $filename ) { - return implode( "", file( $filename ) ); + return implode( '', file( $filename ) ); } } @@ -47,15 +47,15 @@ if( !function_exists('is_a') ) { # html_entity_decode exists in PHP 4.3.0+ but is FATALLY BROKEN even then, # with no UTF-8 support. -function do_html_entity_decode( $string, $quote_style=ENT_COMPAT, $charset="ISO-8859-1" ) { +function do_html_entity_decode( $string, $quote_style=ENT_COMPAT, $charset='ISO-8859-1' ) { static $trans; if( !isset( $trans ) ) { $trans = array_flip( get_html_translation_table( HTML_ENTITIES, $quote_style ) ); # Assumes $charset will always be the same through a run, and only understands # utf-8 or default. Note - mixing latin1 named entities and unicode numbered # ones will result in a bad link. - if( strcasecmp( "utf-8", $charset ) == 0 ) { - $trans = array_map( "utf8_encode", $trans ); + if( strcasecmp( 'utf-8', $charset ) == 0 ) { + $trans = array_map( 'utf8_encode', $trans ); } } return strtr( $string, $trans ); @@ -77,40 +77,40 @@ function wfSeedRandom() # Generates a URL from a URL-encoded title and a query string # Title::getLocalURL() is preferred in most cases # -function wfLocalUrl( $a, $q = "" ) +function wfLocalUrl( $a, $q = '' ) { global $wgServer, $wgScript, $wgArticlePath; - $a = str_replace( " ", "_", $a ); + $a = str_replace( ' ', '_', $a ); - if ( "" == $a ) { - if( "" == $q ) { + if ( '' == $a ) { + if( '' == $q ) { $a = $wgScript; } else { $a = "{$wgScript}?{$q}"; } - } else if ( "" == $q ) { + } else if ( '' == $q ) { $a = str_replace( "$1", $a, $wgArticlePath ); } else if ($wgScript != '' ) { $a = "{$wgScript}?title={$a}&{$q}"; - } else { //XXX ugly hack for toplevel wikis - $a = "/{$a}&{$q}"; + } else { //XXX hackish solution for toplevel wikis + $a = "/{$a}?{$q}"; } return $a; } -function wfLocalUrlE( $a, $q = "" ) +function wfLocalUrlE( $a, $q = '' ) { return wfEscapeHTML( wfLocalUrl( $a, $q ) ); # die( "Call to obsolete function wfLocalUrlE()" ); } -function wfFullUrl( $a, $q = "" ) { - wfDebugDieBacktrace( "Call to obsolete function wfFullUrl(); use Title::getFullURL" ); +function wfFullUrl( $a, $q = '' ) { + wfDebugDieBacktrace( 'Call to obsolete function wfFullUrl(); use Title::getFullURL' ); } -function wfFullUrlE( $a, $q = "" ) { - wfDebugDieBacktrace( "Call to obsolete function wfFullUrlE(); use Title::getFullUrlE" ); +function wfFullUrlE( $a, $q = '' ) { + wfDebugDieBacktrace( 'Call to obsolete function wfFullUrlE(); use Title::getFullUrlE' ); } @@ -143,27 +143,28 @@ function wfImageArchiveUrl( $name ) function wfUrlencode ( $s ) { $s = urlencode( $s ); - $s = preg_replace( "/%3[Aa]/", ":", $s ); - $s = preg_replace( "/%2[Ff]/", "/", $s ); + $s = preg_replace( '/%3[Aa]/', ':', $s ); + $s = preg_replace( '/%2[Ff]/', '/', $s ); return $s; } function wfUtf8Sequence($codepoint) { - if($codepoint < 0x80) return chr($codepoint); - if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f | 0xc0) . - chr($codepoint & 0x3f | 0x80); - if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f | 0xe0) . - chr($codepoint >> 6 & 0x3f | 0x80) . - chr($codepoint & 0x3f | 0x80); + if($codepoint < 0x80) return chr($codepoint); + if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f | 0xc0) . + chr($codepoint & 0x3f | 0x80); + if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f | 0xe0) . + chr($codepoint >> 6 & 0x3f | 0x80) . + chr($codepoint & 0x3f | 0x80); if($codepoint < 0x100000) return chr($codepoint >> 18 & 0x07 | 0xf0) . # Double-check this - chr($codepoint >> 12 & 0x3f | 0x80) . - chr($codepoint >> 6 & 0x3f | 0x80) . - chr($codepoint & 0x3f | 0x80); + chr($codepoint >> 12 & 0x3f | 0x80) . + chr($codepoint >> 6 & 0x3f | 0x80) . + chr($codepoint & 0x3f | 0x80); # Doesn't yet handle outside the BMP return "&#$codepoint;"; } +# Converts numeric character entities to UTF-8 function wfMungeToUtf8($string) { global $wgInputEncoding; # This is debatable #$string = iconv($wgInputEncoding, "UTF-8", $string); @@ -174,7 +175,8 @@ function wfMungeToUtf8($string) { } # Converts a single UTF-8 character into the corresponding HTML character entity -function wfUtf8Entity( $char ) { +function wfUtf8Entity( $matches ) { + $char = $matches[0]; # Find the length $z = ord( $char{0} ); if ( $z & 0x80 ) { @@ -188,7 +190,7 @@ function wfUtf8Entity( $char ) { } if ( $length != strlen( $char ) ) { - return ""; + return ''; } if ( $length == 1 ) { return $char; @@ -234,23 +236,25 @@ function logProfilingData() list( $usec, $sec ) = explode( " ", $wgRequestTime ); $start = (float)$sec + (float)$usec; $elapsed = $now - $start; - if ( "" != $wgDebugLogFile ) { + if ( $wgProfiling ) { $prof = wfGetProfilingOutput( $start, $elapsed ); - $forward = ""; + $forward = ''; if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) - $forward = " forwarded for " . $_SERVER['HTTP_X_FORWARDED_FOR']; + $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR']; if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) - $forward .= " client IP " . $_SERVER['HTTP_CLIENT_IP']; + $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP']; if( !empty( $_SERVER['HTTP_FROM'] ) ) - $forward .= " from " . $_SERVER['HTTP_FROM']; + $forward .= ' from ' . $_SERVER['HTTP_FROM']; if( $forward ) $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})"; if($wgUser->getId() == 0) - $forward .= " anon"; + $forward .= ' anon'; $log = sprintf( "%s\t%04.3f\t%s\n", - gmdate( "YmdHis" ), $elapsed, + gmdate( 'YmdHis' ), $elapsed, urldecode( $_SERVER['REQUEST_URI'] . $forward ) ); - error_log( $log . $prof, 3, $wgDebugLogFile ); + if ( '' != $wgDebugLogFile ) { + error_log( $log . $prof, 3, $wgDebugLogFile ); + } } } @@ -287,7 +291,7 @@ function wfMsgNoDB( $key ) { function wfMsgReal( $key, $args, $useDB ) { global $wgReplacementKeys, $wgMessageCache, $wgLang; - $fname = "wfMsg"; + $fname = 'wfMsg'; wfProfileIn( $fname ); if ( $wgMessageCache ) { $message = $wgMessageCache->get( $key, $useDB ); @@ -308,28 +312,28 @@ function wfMsgReal( $key, $args, $useDB ) { function wfCleanFormFields( $fields ) { - wfDebugDieBacktrace( "Call to obsolete wfCleanFormFields(). Use wgRequest instead..." ); + wfDebugDieBacktrace( 'Call to obsolete wfCleanFormFields(). Use wgRequest instead...' ); } function wfMungeQuotes( $in ) { - $out = str_replace( "%", "%25", $in ); - $out = str_replace( "'", "%27", $out ); - $out = str_replace( "\"", "%22", $out ); + $out = str_replace( '%', '%25', $in ); + $out = str_replace( "'", '%27', $out ); + $out = str_replace( '"', '%22', $out ); return $out; } function wfDemungeQuotes( $in ) { - $out = str_replace( "%22", "\"", $in ); - $out = str_replace( "%27", "'", $out ); - $out = str_replace( "%25", "%", $out ); + $out = str_replace( '%22', '"', $in ); + $out = str_replace( '%27', "'", $out ); + $out = str_replace( '%25', '%', $out ); return $out; } function wfCleanQueryVar( $var ) { - wfDebugDieBacktrace( "Call to obsolete function wfCleanQueryVar(); use wgRequest instead" ); + wfDebugDieBacktrace( 'Call to obsolete function wfCleanQueryVar(); use wgRequest instead' ); } function wfSearch( $s ) @@ -352,30 +356,32 @@ function wfAbruptExit(){ } $called = true; - if( function_exists( "debug_backtrace" ) ){ // PHP >= 4.3 + if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3 $bt = debug_backtrace(); for($i = 0; $i < count($bt) ; $i++){ - $file = $bt[$i]["file"]; - $line = $bt[$i]["line"]; + $file = $bt[$i]['file']; + $line = $bt[$i]['line']; wfDebug("WARNING: Abrupt exit in $file at line $line\n"); } } else { - wfDebug("WARNING: Abrupt exit\n"); + wfDebug('WARNING: Abrupt exit\n'); } exit(); } -function wfDebugDieBacktrace( $msg = "" ) { - $msg .= "\n

Backtrace:

\n