# Exists in PHP 4.2.0+
function is_a( $object, $class_name ) {
return
- (strcasecmp( get_class( $object, $class_name ) == 0) ||
- is_subclass_of( $object, $class_name ) );
+ (strcasecmp( get_class( $object ), $class_name ) == 0) ||
+ is_subclass_of( $object, $class_name );
}
}
}
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);
}
}
+# Log for database errors
+function wfLogDBError( $text ) {
+ global $wgDBerrorLog;
+ if ( $wgDBerrorLog ) {
+ $text = date("D M j G:i:s T Y") . "\t$text";
+ error_log( $text, 3, $wgDBerrorLog );
+ }
+}
+
function logProfilingData()
{
global $wgRequestTime, $wgDebugLogFile;
}
function wfDebugDieBacktrace( $msg = '' ) {
- $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
- $backtrace = debug_backtrace();
- foreach( $backtrace as $call ) {
- $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
- $file = $f[count($f)-1];
- $msg .= '<li>' . $file . " line " . $call['line'] . ', in ';
- if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
- $msg .= $call['function'] . "()</li>\n";
- }
- die( $msg );
+ global $wgCommandLineMode;
+
+ if ( function_exists( 'debug_backtrace' ) ) {
+ if ( $wgCommandLineMode ) {
+ $msg .= "\nBacktrace:\n";
+ } else {
+ $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
+ }
+ $backtrace = debug_backtrace();
+ foreach( $backtrace as $call ) {
+ $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
+ $file = $f[count($f)-1];
+ if ( $wgCommandLineMode ) {
+ $msg .= "$file line {$call['line']}, in ";
+ } else {
+ $msg .= '<li>' . $file . " line " . $call['line'] . ', in ';
+ }
+ if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
+ $msg .= $call['function'] . "()";
+
+ if ( $wgCommandLineMode ) {
+ $msg .= "\n";
+ } else {
+ $msg .= "</li>\n";
+ }
+ }
+ }
+ die( $msg );
}
function wfNumberOfArticles()
if ( $wgUseCopyrightUpload )
{
- $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
- '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
- '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
+ $textdesc = '== ' . wfMsg ( 'filedesc' ) . " ==\n" . $desc . "\n" .
+ '== ' . wfMsg ( 'filestatus' ) . " ==\n" . $copyStatus . "\n" .
+ '== ' . wfMsg ( 'filesource' ) . " ==\n" . $source ;
}
else $textdesc = $desc ;
wfStrencode( $name ) . "'";
$res = wfQuery( $sql, DB_READ, $fname );
if ( 0 == wfNumRows( $res ) ) {
- $common =
+ $common =
Namespace::getImage() . ",'" .
wfStrencode( $name ) . "','" .
wfStrencode( $desc ) . "','" . $wgUser->getID() . "','" .
function wfEscapeWikiText( $text )
{
$text = str_replace(
- array( '[', '|', "'", 'ISBN ' , '://' , "\n=" ),
+ array( '[', '|', "'", 'ISBN ' , '://' , "\n=" ),
array( '[', '|', ''', 'ISBN ', '://' , "\n=" ),
htmlspecialchars($text) );
return $text;
}
# Sets dest to a reference to source and returns the original dest
+# Pity that doesn't work in PHP
function &wfSetRef( &$dest, &$source )
{
- $temp =& $dest;
- $dest =& $source;
- return $temp;
+ die( "You can't rebind a variable in the caller's scope" );
}
# This function takes two arrays as input, and returns a CGI-style string, e.g.
$first = false;
}
- if (substr(php_uname(), 0, 7) == 'Windows') {
+ if ( wfIsWindows() ) {
$retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
} else {
$retVal .= escapeshellarg( $arg );
fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
# Check for a conflict
- $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
- wfEscapeShellArg( $mytextName ) . ' ' .
- wfEscapeShellArg( $oldtextName ) . ' ' .
- wfEscapeShellArg( $yourtextName );
- $handle = popen( $cmd, 'r' );
+ $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
+ wfEscapeShellArg( $mytextName ) . ' ' .
+ wfEscapeShellArg( $oldtextName ) . ' ' .
+ wfEscapeShellArg( $yourtextName );
+ $handle = popen( $cmd, 'r' );
if( fgets( $handle ) ){
$conflict = true;
return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
}
+# Since Windows is so different to any of the other popular OSes, it seems appropriate
+# to have a simple way to test for its presence
+function wfIsWindows() {
+ if (substr(php_uname(), 0, 7) == 'Windows') {
+ return true;
+ } else {
+ return false;
+ }
+}
+
?>