5 * Global functions used everywhere
10 * Some globals and requires needed
14 * Total number of articles
15 * @global integer $wgNumberOfArticles
17 $wgNumberOfArticles = -1; # Unset
19 * Total number of views
20 * @global integer $wgTotalViews
24 * Total number of edits
25 * @global integer $wgTotalEdits
31 * in "zh", whether conversion of messages should take place
33 $wgDoZhMessageConversion = true;
35 require_once( 'DatabaseFunctions.php' );
36 require_once( 'UpdateClasses.php' );
37 require_once( 'LogPage.php' );
40 * Compatibility functions
41 * PHP <4.3.x is not actively supported; 4.1.x and 4.2.x might or might not work.
42 * <4.1.x will not work, as we use a number of features introduced in 4.1.0
43 * such as the new autoglobals.
45 if( !function_exists('iconv') ) {
46 # iconv support is not in the default configuration and so may not be present.
47 # Assume will only ever use utf-8 and iso-8859-1.
48 # This will *not* work in all circumstances.
49 function iconv( $from, $to, $string ) {
50 if(strcasecmp( $from, $to ) == 0) return $string;
51 if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
52 if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
57 if( !function_exists('file_get_contents') ) {
58 # Exists in PHP 4.3.0+
59 function file_get_contents( $filename ) {
60 return implode( '', file( $filename ) );
64 if( !function_exists('is_a') ) {
65 # Exists in PHP 4.2.0+
66 function is_a( $object, $class_name ) {
68 (strcasecmp( get_class( $object ), $class_name ) == 0) ||
69 is_subclass_of( $object, $class_name );
73 # UTF-8 substr function based on a PHP manual comment
74 if ( !function_exists( 'mb_substr' ) ) {
75 function mb_substr($str,$start)
77 preg_match_all("/./us", $str, $ar);
79 if(func_num_args() >= 3) {
80 $end = func_get_arg(2);
81 return join("",array_slice($ar[0],$start,$end));
83 return join("",array_slice($ar[0],$start));
89 * html_entity_decode exists in PHP 4.3.0+ but is FATALLY BROKEN even then,
90 * with no UTF-8 support.
92 * @param string $string String having html entities
94 * @param string $charset Encoding set to use (default 'ISO-8859-1')
96 function do_html_entity_decode( $string, $quote_style=ENT_COMPAT
, $charset='ISO-8859-1' ) {
98 if( !isset( $trans ) ) {
99 $trans = array_flip( get_html_translation_table( HTML_ENTITIES
, $quote_style ) );
100 # Assumes $charset will always be the same through a run, and only understands
101 # utf-8 or default. Note - mixing latin1 named entities and unicode numbered
102 # ones will result in a bad link.
103 if( strcasecmp( 'utf-8', $charset ) == 0 ) {
104 $trans = array_map( 'utf8_encode', $trans );
107 return strtr( $string, $trans );
112 * Where as we got a random seed
113 * @var bool $wgTotalViews
115 $wgRandomSeeded = false;
118 * Seed Mersenne Twister
119 * Only necessary in PHP < 4.2.0
123 function wfSeedRandom() {
124 global $wgRandomSeeded;
126 if ( ! $wgRandomSeeded && version_compare( phpversion(), '4.2.0' ) < 0 ) {
127 $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff;
129 $wgRandomSeeded = true;
134 * Generates a URL from a URL-encoded title and a query string
135 * Title::getLocalURL() is preferred in most cases
137 * @param string $a URL encoded title
138 * @param string $q URL (default '')
140 function wfLocalUrl( $a, $q = '' ) {
141 global $wgServer, $wgScript, $wgArticlePath;
143 $a = str_replace( ' ', '_', $a );
149 $a = $wgScript.'?'.$q;
151 } else if ( '' == $q ) {
152 $a = str_replace( '$1', $a, $wgArticlePath );
153 } else if ($wgScript != '' ) {
154 $a = "{$wgScript}?title={$a}&{$q}";
155 } else { //XXX hackish solution for toplevel wikis
163 * @param string $a URL encoded title
164 * @param string $q URL (default '')
166 function wfLocalUrlE( $a, $q = '' )
168 return htmlspecialchars( wfLocalUrl( $a, $q ) );
169 # die( "Call to obsolete function wfLocalUrlE()" );
173 * We want / and : to be included as literal characters in our title URLs.
174 * %2F in the page titles seems to fatally break for some reason.
179 function wfUrlencode ( $s ) {
180 $s = urlencode( $s );
181 $s = preg_replace( '/%3[Aa]/', ':', $s );
182 $s = preg_replace( '/%2[Ff]/', '/', $s );
188 * Return the UTF-8 sequence for a given Unicode code point.
189 * Currently doesn't work for values outside the Basic Multilingual Plane.
191 * @param string $codepoint UTF-8 code point.
192 * @return string HTML UTF-8 Entitie such as 'Ӓ'.
194 function wfUtf8Sequence( $codepoint ) {
195 if($codepoint < 0x80) return chr($codepoint);
196 if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f |
0xc0) .
197 chr($codepoint & 0x3f |
0x80);
198 if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f |
0xe0) .
199 chr($codepoint >> 6 & 0x3f |
0x80) .
200 chr($codepoint & 0x3f |
0x80);
201 if($codepoint < 0x110000) return chr($codepoint >> 18 & 0x07 |
0xf0) .
202 chr($codepoint >> 12 & 0x3f |
0x80) .
203 chr($codepoint >> 6 & 0x3f |
0x80) .
204 chr($codepoint & 0x3f |
0x80);
206 # There should be no assigned code points outside this range, but...
207 return "&#$codepoint;";
211 * Converts numeric character entities to UTF-8
213 * @param string $string String to convert.
214 * @return string Converted string.
216 function wfMungeToUtf8( $string ) {
217 global $wgInputEncoding; # This is debatable
218 #$string = iconv($wgInputEncoding, "UTF-8", $string);
219 $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
220 $string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
221 # Should also do named entities here
226 * Converts a single UTF-8 character into the corresponding HTML character
227 * entity (for use with preg_replace_callback)
229 * @param array $matches
232 function wfUtf8Entity( $matches ) {
235 $z = ord( $char{0} );
238 while ( $z & 0x80 ) {
246 if ( $length != strlen( $char ) ) {
249 if ( $length == 1 ) {
253 # Mask off the length-determining bits and shift back to the original location
257 # Add in the free bits from subsequent bytes
258 for ( $i=1; $i<$length; $i++
) {
260 $z |
= ord( $char{$i} ) & 0x3f;
268 * Converts all multi-byte characters in a UTF-8 string into the appropriate
271 function wfUtf8ToHTML($string) {
272 return preg_replace_callback( '/[\\xc0-\\xfd][\\x80-\\xbf]*/', 'wfUtf8Entity', $string );
278 function wfDebug( $text, $logonly = false ) {
279 global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
281 # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
282 if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
286 if ( isset( $wgOut ) && $wgDebugComments && !$logonly ) {
287 $wgOut->debug( $text );
289 if ( '' != $wgDebugLogFile && !$wgProfileOnly ) {
290 error_log( $text, 3, $wgDebugLogFile );
295 * Log for database errors
296 * @param string $text Database error message.
298 function wfLogDBError( $text ) {
299 global $wgDBerrorLog;
300 if ( $wgDBerrorLog ) {
301 $text = date('D M j G:i:s T Y') . "\t".$text;
302 error_log( $text, 3, $wgDBerrorLog );
309 function logProfilingData() {
310 global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
311 global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
314 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
315 $start = (float)$sec +
(float)$usec;
316 $elapsed = $now - $start;
317 if ( $wgProfiling ) {
318 $prof = wfGetProfilingOutput( $start, $elapsed );
320 if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
321 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
322 if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
323 $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
324 if( !empty( $_SERVER['HTTP_FROM'] ) )
325 $forward .= ' from ' . $_SERVER['HTTP_FROM'];
327 $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
328 if($wgUser->getId() == 0)
330 $log = sprintf( "%s\t%04.3f\t%s\n",
331 gmdate( 'YmdHis' ), $elapsed,
332 urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
333 if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' ||
$wgDebugRawPage ) ) {
334 error_log( $log . $prof, 3, $wgDebugLogFile );
340 * Check if the wiki read-only lock file is present. This can be used to lock
341 * off editing functions, but doesn't guarantee that the database will not be
345 function wfReadOnly() {
346 global $wgReadOnlyFile;
348 if ( '' == $wgReadOnlyFile ) {
351 return is_file( $wgReadOnlyFile );
355 * Keys strings for replacement
356 * @global array $wgReplacementKeys
358 $wgReplacementKeys = array( '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9' );
361 * Get a message from anywhere
363 function wfMsg( $key ) {
365 if ( $wgRequest->getVal( 'debugmsg' ) ) {
366 if ( $key == 'linktrail' /* a special case where we want to return something specific */ )
367 return "/^()(.*)$/sD";
371 $args = func_get_args();
372 if ( count( $args ) ) {
373 array_shift( $args );
375 return wfMsgReal( $key, $args, true );
379 * Get a message from the language file
381 function wfMsgNoDB( $key ) {
382 $args = func_get_args();
383 if ( count( $args ) ) {
384 array_shift( $args );
386 return wfMsgReal( $key, $args, false );
390 * Really get a message
392 function wfMsgReal( $key, $args, $useDB ) {
393 global $wgReplacementKeys, $wgMessageCache, $wgLang, $wgLanguageCode;
394 global $wgDoZhMessageConversion;
396 wfProfileIn( $fname );
397 if ( $wgMessageCache ) {
398 $message = $wgMessageCache->get( $key, $useDB );
399 } elseif ( $wgLang ) {
400 $message = $wgLang->getMessage( $key );
402 wfDebug( "No language object when getting $key\n" );
403 $message = "<$key>";
406 if(strtolower($wgLanguageCode) == "zh" && $wgDoZhMessageConversion) {
407 $message = $wgLang->convert($message);
410 if( count( $args ) ) {
411 $message = str_replace( $wgReplacementKeys, $args, $message );
413 wfProfileOut( $fname );
420 * Just like exit() but makes a note of it.
421 * Commits open transactions except if the error parameter is set
423 function wfAbruptExit( $error = false ){
424 global $wgLoadBalancer;
425 static $called = false;
431 if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3
432 $bt = debug_backtrace();
433 for($i = 0; $i < count($bt) ; $i++
){
434 $file = $bt[$i]['file'];
435 $line = $bt[$i]['line'];
436 wfDebug("WARNING: Abrupt exit in $file at line $line\n");
439 wfDebug('WARNING: Abrupt exit\n');
442 $wgLoadBalancer->closeAll();
450 function wfErrorExit() {
451 wfAbruptExit( true );
455 * Die with a backtrace
456 * This is meant as a debugging aid to track down where bad data comes from.
457 * Shouldn't be used in production code except maybe in "shouldn't happen" areas.
459 * @param string $msg Message shown when dieing.
461 function wfDebugDieBacktrace( $msg = '' ) {
462 global $wgCommandLineMode;
464 if ( function_exists( 'debug_backtrace' ) ) {
465 if ( $wgCommandLineMode ) {
466 $msg .= "\nBacktrace:\n";
468 $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
470 $backtrace = debug_backtrace();
471 foreach( $backtrace as $call ) {
472 $f = explode( DIRECTORY_SEPARATOR
, $call['file'] );
473 $file = $f[count($f)-1];
474 if ( $wgCommandLineMode ) {
475 $msg .= "$file line {$call['line']} calls ";
477 $msg .= '<li>' . $file . ' line ' . $call['line'] . ' calls ';
479 if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
480 $msg .= $call['function'] . '()';
482 if ( $wgCommandLineMode ) {
493 /* Some generic result counters, pulled out of SearchEngine */
499 function wfShowingResults( $offset, $limit ) {
501 return wfMsg( 'showingresults', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ) );
507 function wfShowingResultsNum( $offset, $limit, $num ) {
509 return wfMsg( 'showingresultsnum', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ), $wgLang->formatNum( $num ) );
515 function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) {
516 global $wgUser, $wgLang;
517 $fmtLimit = $wgLang->formatNum( $limit );
518 $prev = wfMsg( 'prevn', $fmtLimit );
519 $next = wfMsg( 'nextn', $fmtLimit );
520 $link = wfUrlencode( $link );
522 $sk = $wgUser->getSkin();
523 if ( 0 != $offset ) {
524 $po = $offset - $limit;
525 if ( $po < 0 ) { $po = 0; }
526 $q = "limit={$limit}&offset={$po}";
527 if ( '' != $query ) { $q .= '&'.$query; }
528 $plink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$prev}</a>";
529 } else { $plink = $prev; }
531 $no = $offset +
$limit;
532 $q = 'limit='.$limit.'&offset='.$no;
533 if ( '' != $query ) { $q .= '&'.$query; }
538 $nlink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$next}</a>";
540 $nums = wfNumLink( $offset, 20, $link , $query ) . ' | ' .
541 wfNumLink( $offset, 50, $link, $query ) . ' | ' .
542 wfNumLink( $offset, 100, $link, $query ) . ' | ' .
543 wfNumLink( $offset, 250, $link, $query ) . ' | ' .
544 wfNumLink( $offset, 500, $link, $query );
546 return wfMsg( 'viewprevnext', $plink, $nlink, $nums );
552 function wfNumLink( $offset, $limit, $link, $query = '' ) {
553 global $wgUser, $wgLang;
554 if ( '' == $query ) { $q = ''; }
555 else { $q = $query.'&'; }
556 $q .= 'limit='.$limit.'&offset='.$offset;
558 $fmtLimit = $wgLang->formatNum( $limit );
559 $s = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$fmtLimit}</a>";
565 * @todo FIXME: we may want to blacklist some broken browsers
567 * @return bool Whereas client accept gzip compression
569 function wfClientAcceptsGzip() {
572 # FIXME: we may want to blacklist some broken browsers
574 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
575 $_SERVER['HTTP_ACCEPT_ENCODING'],
577 if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false;
578 wfDebug( " accepts gzip\n" );
586 * Yay, more global functions!
588 function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) {
590 return $wgRequest->getLimitOffset( $deflimit, $optionname );
594 * Escapes the given text so that it may be output using addWikiText()
595 * without any linking, formatting, etc. making its way through. This
596 * is achieved by substituting certain characters with HTML entities.
597 * As required by the callers, <nowiki> is not used. It currently does
598 * not filter out characters which have special meaning only at the
599 * start of a line, such as "*".
601 * @param string $text Text to be escaped
603 function wfEscapeWikiText( $text ) {
605 array( '[', '|', "'", 'ISBN ' , '://' , "\n=", '{{' ),
606 array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ),
607 htmlspecialchars($text) );
614 function wfQuotedPrintable( $string, $charset = '' ) {
615 # Probably incomplete; see RFC 2045
616 if( empty( $charset ) ) {
617 global $wgInputEncoding;
618 $charset = $wgInputEncoding;
620 $charset = strtoupper( $charset );
621 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
623 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
624 $replace = $illegal . '\t ?_';
625 if( !preg_match( "/[$illegal]/", $string ) ) return $string;
626 $out = "=?$charset?Q?";
627 $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
637 $st = explode( ' ', microtime() );
638 return (float)$st[0] +
(float)$st[1];
642 * Changes the first character to an HTML entity
644 function wfHtmlEscapeFirst( $text ) {
646 $newText = substr($text, 1);
647 return "&#$ord;$newText";
651 * Sets dest to source and returns the original value of dest
652 * If source is NULL, it just returns the value, it doesn't set the variable
654 function wfSetVar( &$dest, $source ) {
656 if ( !is_null( $source ) ) {
663 * As for wfSetVar except setting a bit
665 function wfSetBit( &$dest, $bit, $state = true ) {
666 $temp = (bool)($dest & $bit );
667 if ( !is_null( $state ) ) {
678 * This function takes two arrays as input, and returns a CGI-style string, e.g.
679 * "days=7&limit=100". Options in the first array override options in the second.
680 * Options set to "" will not be output.
682 function wfArrayToCGI( $array1, $array2 = NULL )
684 if ( !is_null( $array2 ) ) {
685 $array1 = $array1 +
$array2;
689 foreach ( $array1 as $key => $value ) {
690 if ( '' !== $value ) {
694 $cgi .= $key.'='.$value;
701 * This is obsolete, use SquidUpdate::purge()
704 function wfPurgeSquidServers ($urlArr) {
705 SquidUpdate
::purge( $urlArr );
709 * Windows-compatible version of escapeshellarg()
710 * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
711 * function puts single quotes in regardless of OS
713 function wfEscapeShellArg( ) {
714 $args = func_get_args();
717 foreach ( $args as $arg ) {
724 if ( wfIsWindows() ) {
725 $retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
727 $retVal .= escapeshellarg( $arg );
734 * wfMerge attempts to merge differences between three texts.
735 * Returns true for a clean merge and false for failure or a conflict.
737 function wfMerge( $old, $mine, $yours, &$result ){
740 # This check may also protect against code injection in
741 # case of broken installations.
742 if(! file_exists( $wgDiff3 ) ){
746 # Make temporary files
748 $oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
749 $mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
750 $yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
752 fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
753 fwrite( $mytextFile, $mine ); fclose( $mytextFile );
754 fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
756 # Check for a conflict
757 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
758 wfEscapeShellArg( $mytextName ) . ' ' .
759 wfEscapeShellArg( $oldtextName ) . ' ' .
760 wfEscapeShellArg( $yourtextName );
761 $handle = popen( $cmd, 'r' );
763 if( fgets( $handle ) ){
771 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
772 wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
773 $handle = popen( $cmd, 'r' );
776 $data = fread( $handle, 8192 );
777 if ( strlen( $data ) == 0 ) {
783 unlink( $mytextName ); unlink( $oldtextName ); unlink( $yourtextName );
790 function wfVarDump( $var ) {
792 $s = str_replace("\n","<br>\n", var_export( $var, true ) . "\n");
793 if ( headers_sent() ||
!@is_object
( $wgOut ) ) {
796 $wgOut->addHTML( $s );
801 * Provide a simple HTTP error.
803 function wfHttpError( $code, $label, $desc ) {
806 header( "HTTP/1.0 $code $label" );
807 header( "Status: $code $label" );
808 $wgOut->sendCacheControl();
810 # Don't send content if it's a HEAD request.
811 if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
812 header( 'Content-type: text/plain' );
818 * Converts an Accept-* header into an array mapping string values to quality
821 function wfAcceptToPrefs( $accept, $def = '*/*' ) {
822 # No arg means accept anything (per HTTP spec)
824 return array( $def => 1 );
829 $parts = explode( ',', $accept );
831 foreach( $parts as $part ) {
832 # FIXME: doesn't deal with params like 'text/html; level=1'
833 @list
( $value, $qpart ) = explode( ';', $part );
834 if( !isset( $qpart ) ) {
836 } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
837 $prefs[$value] = $match[1];
848 function mimeTypeMatch( $type, $avail ) {
849 if( array_key_exists($type, $avail) ) {
852 $parts = explode( '/', $type );
853 if( array_key_exists( $parts[0] . '/*', $avail ) ) {
854 return $parts[0] . '/*';
855 } elseif( array_key_exists( '*/*', $avail ) ) {
864 * @todo FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
865 * XXX: generalize to negotiate other stuff
867 function wfNegotiateType( $cprefs, $sprefs ) {
870 foreach( array_keys($sprefs) as $type ) {
871 $parts = explode( '/', $type );
872 if( $parts[1] != '*' ) {
873 $ckey = mimeTypeMatch( $type, $cprefs );
875 $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
880 foreach( array_keys( $cprefs ) as $type ) {
881 $parts = explode( '/', $type );
882 if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
883 $skey = mimeTypeMatch( $type, $sprefs );
885 $combine[$type] = $sprefs[$skey] * $cprefs[$type];
893 foreach( array_keys( $combine ) as $type ) {
894 if( $combine[$type] > $bestq ) {
896 $bestq = $combine[$type];
905 * Returns an array where the values in the first array are replaced by the
906 * values in the second array with the corresponding keys
910 function wfArrayLookup( $a, $b ) {
911 return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
916 * Ideally we'd be using actual time fields in the db
919 function wfTimestamp2Unix( $ts ) {
920 return gmmktime( ( (int)substr( $ts, 8, 2) ),
921 (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ),
922 (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ),
923 (int)substr( $ts, 0, 4 ) );
929 function wfUnix2Timestamp( $unixtime ) {
930 return gmdate( 'YmdHis', $unixtime );
936 function wfTimestampNow() {
938 return gmdate( 'YmdHis' );
942 * Sorting hack for MySQL 3, which doesn't use index sorts for DESC
944 function wfInvertTimestamp( $ts ) {
953 * Reference-counted warning suppression
955 function wfSuppressWarnings( $end = false ) {
956 static $suppressCount = 0;
957 static $originalLevel = false;
960 if ( $suppressCount ) {
962 if ( !$suppressCount ) {
963 error_reporting( $originalLevel );
967 if ( !$suppressCount ) {
968 $originalLevel = error_reporting( E_ALL
& ~
( E_WARNING | E_NOTICE
) );
975 * Restore error level to previous value
977 function wfRestoreWarnings() {
978 wfSuppressWarnings( true );
981 # Autodetect, convert and provide timestamps of various types
983 /** Standard unix timestamp (number of seconds since 1 Jan 1970) */
985 /** MediaWiki concatenated string timestamp (yyyymmddhhmmss) */
987 /** Standard database timestamp (yyyy-mm-dd hh:mm:ss) */
993 function wfTimestamp($outputtype=TS_UNIX
,$ts=0) {
994 if (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
996 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
997 (int)$da[2],(int)$da[3],(int)$da[1]);
998 } elseif (preg_match("/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/",$ts,$da)) {
1000 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
1001 (int)$da[2],(int)$da[3],(int)$da[1]);
1002 } elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
1009 switch($outputtype) {
1014 return gmdate( 'YmdHis', $uts );
1017 return gmdate( 'Y-m-d H:i:s', $uts );
1025 * Check where as the operating system is Windows
1028 * @return bool True if it's windows, False otherwise.
1030 function wfIsWindows() {
1031 if (substr(php_uname(), 0, 7) == 'Windows') {