45a71d0e5970ec01d01782344dbef7fce62628fb
5 * Global functions used everywhere
9 * Some globals and requires needed
13 * Total number of articles
14 * @global integer $wgNumberOfArticles
16 $wgNumberOfArticles = -1; # Unset
18 * Total number of views
19 * @global integer $wgTotalViews
23 * Total number of edits
24 * @global integer $wgTotalEdits
28 require_once( 'DatabaseFunctions.php' );
29 require_once( 'UpdateClasses.php' );
30 require_once( 'LogPage.php' );
33 * Compatibility functions
34 * PHP <4.3.x is not actively supported; 4.1.x and 4.2.x might or might not work.
35 * <4.1.x will not work, as we use a number of features introduced in 4.1.0
36 * such as the new autoglobals.
38 if( !function_exists('iconv') ) {
39 # iconv support is not in the default configuration and so may not be present.
40 # Assume will only ever use utf-8 and iso-8859-1.
41 # This will *not* work in all circumstances.
42 function iconv( $from, $to, $string ) {
43 if(strcasecmp( $from, $to ) == 0) return $string;
44 if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
45 if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
50 if( !function_exists('file_get_contents') ) {
51 # Exists in PHP 4.3.0+
52 function file_get_contents( $filename ) {
53 return implode( '', file( $filename ) );
57 if( !function_exists('is_a') ) {
58 # Exists in PHP 4.2.0+
59 function is_a( $object, $class_name ) {
61 (strcasecmp( get_class( $object ), $class_name ) == 0) ||
62 is_subclass_of( $object, $class_name );
66 # UTF-8 substr function based on a PHP manual comment
67 if ( !function_exists( 'mb_substr' ) ) {
68 function mb_substr($str,$start)
70 preg_match_all("/./us", $str, $ar);
72 if(func_num_args() >= 3) {
73 $end = func_get_arg(2);
74 return join("",array_slice($ar[0],$start,$end));
76 return join("",array_slice($ar[0],$start));
82 * html_entity_decode exists in PHP 4.3.0+ but is FATALLY BROKEN even then,
83 * with no UTF-8 support.
85 * @param string $string String having html entities
87 * @param string $charset Encoding set to use (default 'ISO-8859-1')
89 function do_html_entity_decode( $string, $quote_style=ENT_COMPAT
, $charset='ISO-8859-1' ) {
91 if( !isset( $trans ) ) {
92 $trans = array_flip( get_html_translation_table( HTML_ENTITIES
, $quote_style ) );
93 # Assumes $charset will always be the same through a run, and only understands
94 # utf-8 or default. Note - mixing latin1 named entities and unicode numbered
95 # ones will result in a bad link.
96 if( strcasecmp( 'utf-8', $charset ) == 0 ) {
97 $trans = array_map( 'utf8_encode', $trans );
100 return strtr( $string, $trans );
105 * Where as we got a random seed
106 * @var bool $wgTotalViews
108 $wgRandomSeeded = false;
111 * Seed Mersenne Twister
112 * Only necessary in PHP < 4.2.0
116 function wfSeedRandom() {
117 global $wgRandomSeeded;
119 if ( ! $wgRandomSeeded && version_compare( phpversion(), '4.2.0' ) < 0 ) {
120 $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff;
122 $wgRandomSeeded = true;
127 * Generates a URL from a URL-encoded title and a query string
128 * Title::getLocalURL() is preferred in most cases
130 * @param string $a URL encoded title
131 * @param string $q URL (default '')
133 function wfLocalUrl( $a, $q = '' ) {
134 global $wgServer, $wgScript, $wgArticlePath;
136 $a = str_replace( ' ', '_', $a );
142 $a = $wgScript.'?'.$q;
144 } else if ( '' == $q ) {
145 $a = str_replace( '$1', $a, $wgArticlePath );
146 } else if ($wgScript != '' ) {
147 $a = "{$wgScript}?title={$a}&{$q}";
148 } else { //XXX hackish solution for toplevel wikis
156 * @param string $a URL encoded title
157 * @param string $q URL (default '')
159 function wfLocalUrlE( $a, $q = '' )
161 return htmlspecialchars( wfLocalUrl( $a, $q ) );
162 # die( "Call to obsolete function wfLocalUrlE()" );
166 * We want / and : to be included as literal characters in our title URLs.
167 * %2F in the page titles seems to fatally break for some reason.
172 function wfUrlencode ( $s ) {
173 $s = urlencode( $s );
174 $s = preg_replace( '/%3[Aa]/', ':', $s );
175 $s = preg_replace( '/%2[Ff]/', '/', $s );
181 * Return the UTF-8 sequence for a given Unicode code point.
182 * Currently doesn't work for values outside the Basic Multilingual Plane.
184 * @param string $codepoint UTF-8 code point.
185 * @return string HTML UTF-8 Entitie such as 'Ӓ'.
187 function wfUtf8Sequence( $codepoint ) {
188 if($codepoint < 0x80) return chr($codepoint);
189 if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f |
0xc0) .
190 chr($codepoint & 0x3f |
0x80);
191 if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f |
0xe0) .
192 chr($codepoint >> 6 & 0x3f |
0x80) .
193 chr($codepoint & 0x3f |
0x80);
194 if($codepoint < 0x110000) return chr($codepoint >> 18 & 0x07 |
0xf0) .
195 chr($codepoint >> 12 & 0x3f |
0x80) .
196 chr($codepoint >> 6 & 0x3f |
0x80) .
197 chr($codepoint & 0x3f |
0x80);
199 # There should be no assigned code points outside this range, but...
200 return "&#$codepoint;";
204 * Converts numeric character entities to UTF-8
206 * @param string $string String to convert.
207 * @return string Converted string.
209 function wfMungeToUtf8( $string ) {
210 global $wgInputEncoding; # This is debatable
211 #$string = iconv($wgInputEncoding, "UTF-8", $string);
212 $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
213 $string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
214 # Should also do named entities here
219 * Converts a single UTF-8 character into the corresponding HTML character
220 * entity (for use with preg_replace_callback)
222 * @param array $matches
225 function wfUtf8Entity( $matches ) {
228 $z = ord( $char{0} );
231 while ( $z & 0x80 ) {
239 if ( $length != strlen( $char ) ) {
242 if ( $length == 1 ) {
246 # Mask off the length-determining bits and shift back to the original location
250 # Add in the free bits from subsequent bytes
251 for ( $i=1; $i<$length; $i++
) {
253 $z |
= ord( $char{$i} ) & 0x3f;
261 * Converts all multi-byte characters in a UTF-8 string into the appropriate
264 function wfUtf8ToHTML($string) {
265 return preg_replace_callback( '/[\\xc0-\\xfd][\\x80-\\xbf]*/', 'wfUtf8Entity', $string );
271 function wfDebug( $text, $logonly = false ) {
272 global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
274 # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
275 if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
279 if ( isset( $wgOut ) && $wgDebugComments && !$logonly ) {
280 $wgOut->debug( $text );
282 if ( '' != $wgDebugLogFile && !$wgProfileOnly ) {
283 error_log( $text, 3, $wgDebugLogFile );
288 * Log for database errors
289 * @param string $text Database error message.
291 function wfLogDBError( $text ) {
292 global $wgDBerrorLog;
293 if ( $wgDBerrorLog ) {
294 $text = date('D M j G:i:s T Y') . "\t".$text;
295 error_log( $text, 3, $wgDBerrorLog );
302 function logProfilingData() {
303 global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
304 global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
307 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
308 $start = (float)$sec +
(float)$usec;
309 $elapsed = $now - $start;
310 if ( $wgProfiling ) {
311 $prof = wfGetProfilingOutput( $start, $elapsed );
313 if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
314 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
315 if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
316 $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
317 if( !empty( $_SERVER['HTTP_FROM'] ) )
318 $forward .= ' from ' . $_SERVER['HTTP_FROM'];
320 $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
321 if($wgUser->getId() == 0)
323 $log = sprintf( "%s\t%04.3f\t%s\n",
324 gmdate( 'YmdHis' ), $elapsed,
325 urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
326 if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' ||
$wgDebugRawPage ) ) {
327 error_log( $log . $prof, 3, $wgDebugLogFile );
333 * Check if the wiki read-only lock file is present. This can be used to lock
334 * off editing functions, but doesn't guarantee that the database will not be
338 function wfReadOnly() {
339 global $wgReadOnlyFile;
341 if ( '' == $wgReadOnlyFile ) {
344 return is_file( $wgReadOnlyFile );
348 * Keys strings for replacement
349 * @global array $wgReplacementKeys
351 $wgReplacementKeys = array( '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9' );
354 * Get a message from anywhere
356 function wfMsg( $key ) {
358 if ( $wgRequest->getVal( 'debugmsg' ) ) {
359 if ( $key == 'linktrail' /* a special case where we want to return something specific */ )
360 return "/^()(.*)$/sD";
364 $args = func_get_args();
365 if ( count( $args ) ) {
366 array_shift( $args );
368 return wfMsgReal( $key, $args, true );
372 * Get a message from the language file
374 function wfMsgNoDB( $key ) {
375 $args = func_get_args();
376 if ( count( $args ) ) {
377 array_shift( $args );
379 return wfMsgReal( $key, $args, false );
383 * Really get a message
385 function wfMsgReal( $key, $args, $useDB ) {
386 global $wgReplacementKeys, $wgMessageCache, $wgLang;
389 wfProfileIn( $fname );
390 if ( $wgMessageCache ) {
391 $message = $wgMessageCache->get( $key, $useDB );
392 } elseif ( $wgLang ) {
393 $message = $wgLang->getMessage( $key );
395 wfDebug( "No language object when getting $key\n" );
396 $message = "<$key>";
400 if( count( $args ) ) {
401 $message = str_replace( $wgReplacementKeys, $args, $message );
403 wfProfileOut( $fname );
408 * Just like exit() but makes a note of it.
409 * Commits open transactions except if the error parameter is set
411 function wfAbruptExit( $error = false ){
412 global $wgLoadBalancer;
413 static $called = false;
419 if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3
420 $bt = debug_backtrace();
421 for($i = 0; $i < count($bt) ; $i++
){
422 $file = $bt[$i]['file'];
423 $line = $bt[$i]['line'];
424 wfDebug("WARNING: Abrupt exit in $file at line $line\n");
427 wfDebug('WARNING: Abrupt exit\n');
430 $wgLoadBalancer->closeAll();
438 function wfErrorExit() {
439 wfAbruptExit( true );
443 * Die with a backtrace
444 * This is meant as a debugging aid to track down where bad data comes from.
445 * Shouldn't be used in production code except maybe in "shouldn't happen" areas.
447 * @param string $msg Message shown when dieing.
449 function wfDebugDieBacktrace( $msg = '' ) {
450 global $wgCommandLineMode;
452 if ( function_exists( 'debug_backtrace' ) ) {
453 if ( $wgCommandLineMode ) {
454 $msg .= "\nBacktrace:\n";
456 $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
458 $backtrace = debug_backtrace();
459 foreach( $backtrace as $call ) {
460 $f = explode( DIRECTORY_SEPARATOR
, $call['file'] );
461 $file = $f[count($f)-1];
462 if ( $wgCommandLineMode ) {
463 $msg .= "$file line {$call['line']} calls ";
465 $msg .= '<li>' . $file . ' line ' . $call['line'] . ' calls ';
467 if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
468 $msg .= $call['function'] . '()';
470 if ( $wgCommandLineMode ) {
481 /* Some generic result counters, pulled out of SearchEngine */
487 function wfShowingResults( $offset, $limit ) {
489 return wfMsg( 'showingresults', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ) );
495 function wfShowingResultsNum( $offset, $limit, $num ) {
497 return wfMsg( 'showingresultsnum', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ), $wgLang->formatNum( $num ) );
503 function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) {
504 global $wgUser, $wgLang;
505 $fmtLimit = $wgLang->formatNum( $limit );
506 $prev = wfMsg( 'prevn', $fmtLimit );
507 $next = wfMsg( 'nextn', $fmtLimit );
508 $link = wfUrlencode( $link );
510 $sk = $wgUser->getSkin();
511 if ( 0 != $offset ) {
512 $po = $offset - $limit;
513 if ( $po < 0 ) { $po = 0; }
514 $q = "limit={$limit}&offset={$po}";
515 if ( '' != $query ) { $q .= '&'.$query; }
516 $plink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$prev}</a>";
517 } else { $plink = $prev; }
519 $no = $offset +
$limit;
520 $q = 'limit='.$limit.'&offset='.$no;
521 if ( '' != $query ) { $q .= '&'.$query; }
526 $nlink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$next}</a>";
528 $nums = wfNumLink( $offset, 20, $link , $query ) . ' | ' .
529 wfNumLink( $offset, 50, $link, $query ) . ' | ' .
530 wfNumLink( $offset, 100, $link, $query ) . ' | ' .
531 wfNumLink( $offset, 250, $link, $query ) . ' | ' .
532 wfNumLink( $offset, 500, $link, $query );
534 return wfMsg( 'viewprevnext', $plink, $nlink, $nums );
540 function wfNumLink( $offset, $limit, $link, $query = '' ) {
541 global $wgUser, $wgLang;
542 if ( '' == $query ) { $q = ''; }
543 else { $q = $query.'&'; }
544 $q .= 'limit='.$limit.'&offset='.$offset;
546 $fmtLimit = $wgLang->formatNum( $limit );
547 $s = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$fmtLimit}</a>";
553 * @todo FIXME: we may want to blacklist some broken browsers
555 * @return bool Whereas client accept gzip compression
557 function wfClientAcceptsGzip() {
560 # FIXME: we may want to blacklist some broken browsers
562 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
563 $_SERVER['HTTP_ACCEPT_ENCODING'],
565 if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false;
566 wfDebug( " accepts gzip\n" );
574 * Yay, more global functions!
576 function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) {
578 return $wgRequest->getLimitOffset( $deflimit, $optionname );
582 * Escapes the given text so that it may be output using addWikiText()
583 * without any linking, formatting, etc. making its way through. This
584 * is achieved by substituting certain characters with HTML entities.
585 * As required by the callers, <nowiki> is not used. It currently does
586 * not filter out characters which have special meaning only at the
587 * start of a line, such as "*".
589 * @param string $text Text to be escaped
591 function wfEscapeWikiText( $text ) {
593 array( '[', '|', "'", 'ISBN ' , '://' , "\n=", '{{' ),
594 array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ),
595 htmlspecialchars($text) );
602 function wfQuotedPrintable( $string, $charset = '' ) {
603 # Probably incomplete; see RFC 2045
604 if( empty( $charset ) ) {
605 global $wgInputEncoding;
606 $charset = $wgInputEncoding;
608 $charset = strtoupper( $charset );
609 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
611 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
612 $replace = $illegal . '\t ?_';
613 if( !preg_match( "/[$illegal]/", $string ) ) return $string;
614 $out = "=?$charset?Q?";
615 $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
625 $st = explode( ' ', microtime() );
626 return (float)$st[0] +
(float)$st[1];
630 * Changes the first character to an HTML entity
632 function wfHtmlEscapeFirst( $text ) {
634 $newText = substr($text, 1);
635 return "&#$ord;$newText";
639 * Sets dest to source and returns the original value of dest
640 * If source is NULL, it just returns the value, it doesn't set the variable
642 function wfSetVar( &$dest, $source ) {
644 if ( !is_null( $source ) ) {
651 * As for wfSetVar except setting a bit
653 function wfSetBit( &$dest, $bit, $state = true ) {
654 $temp = (bool)($dest & $bit );
655 if ( !is_null( $state ) ) {
666 * This function takes two arrays as input, and returns a CGI-style string, e.g.
667 * "days=7&limit=100". Options in the first array override options in the second.
668 * Options set to "" will not be output.
670 function wfArrayToCGI( $array1, $array2 = NULL )
672 if ( !is_null( $array2 ) ) {
673 $array1 = $array1 +
$array2;
677 foreach ( $array1 as $key => $value ) {
678 if ( '' !== $value ) {
682 $cgi .= $key.'='.$value;
689 * This is obsolete, use SquidUpdate::purge()
692 function wfPurgeSquidServers ($urlArr) {
693 SquidUpdate
::purge( $urlArr );
697 * Windows-compatible version of escapeshellarg()
698 * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
699 * function puts single quotes in regardless of OS
701 function wfEscapeShellArg( ) {
702 $args = func_get_args();
705 foreach ( $args as $arg ) {
712 if ( wfIsWindows() ) {
713 $retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
715 $retVal .= escapeshellarg( $arg );
722 * wfMerge attempts to merge differences between three texts.
723 * Returns true for a clean merge and false for failure or a conflict.
725 function wfMerge( $old, $mine, $yours, &$result ){
728 # This check may also protect against code injection in
729 # case of broken installations.
730 if(! file_exists( $wgDiff3 ) ){
734 # Make temporary files
736 $oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
737 $mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
738 $yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
740 fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
741 fwrite( $mytextFile, $mine ); fclose( $mytextFile );
742 fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
744 # Check for a conflict
745 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
746 wfEscapeShellArg( $mytextName ) . ' ' .
747 wfEscapeShellArg( $oldtextName ) . ' ' .
748 wfEscapeShellArg( $yourtextName );
749 $handle = popen( $cmd, 'r' );
751 if( fgets( $handle ) ){
759 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
760 wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
761 $handle = popen( $cmd, 'r' );
764 $data = fread( $handle, 8192 );
765 if ( strlen( $data ) == 0 ) {
771 unlink( $mytextName ); unlink( $oldtextName ); unlink( $yourtextName );
778 function wfVarDump( $var ) {
780 $s = str_replace("\n","<br>\n", var_export( $var, true ) . "\n");
781 if ( headers_sent() ||
!@is_object
( $wgOut ) ) {
784 $wgOut->addHTML( $s );
789 * Provide a simple HTTP error.
791 function wfHttpError( $code, $label, $desc ) {
794 header( "HTTP/1.0 $code $label" );
795 header( "Status: $code $label" );
796 $wgOut->sendCacheControl();
798 # Don't send content if it's a HEAD request.
799 if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
800 header( 'Content-type: text/plain' );
806 * Converts an Accept-* header into an array mapping string values to quality
809 function wfAcceptToPrefs( $accept, $def = '*/*' ) {
810 # No arg means accept anything (per HTTP spec)
812 return array( $def => 1 );
817 $parts = explode( ',', $accept );
819 foreach( $parts as $part ) {
820 # FIXME: doesn't deal with params like 'text/html; level=1'
821 @list
( $value, $qpart ) = explode( ';', $part );
822 if( !isset( $qpart ) ) {
824 } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
825 $prefs[$value] = $match[1];
836 function mimeTypeMatch( $type, $avail ) {
837 if( array_key_exists($type, $avail) ) {
840 $parts = explode( '/', $type );
841 if( array_key_exists( $parts[0] . '/*', $avail ) ) {
842 return $parts[0] . '/*';
843 } elseif( array_key_exists( '*/*', $avail ) ) {
852 * @todo FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
853 * XXX: generalize to negotiate other stuff
855 function wfNegotiateType( $cprefs, $sprefs ) {
858 foreach( array_keys($sprefs) as $type ) {
859 $parts = explode( '/', $type );
860 if( $parts[1] != '*' ) {
861 $ckey = mimeTypeMatch( $type, $cprefs );
863 $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
868 foreach( array_keys( $cprefs ) as $type ) {
869 $parts = explode( '/', $type );
870 if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
871 $skey = mimeTypeMatch( $type, $sprefs );
873 $combine[$type] = $sprefs[$skey] * $cprefs[$type];
881 foreach( array_keys( $combine ) as $type ) {
882 if( $combine[$type] > $bestq ) {
884 $bestq = $combine[$type];
893 * Returns an array where the values in the first array are replaced by the
894 * values in the second array with the corresponding keys
898 function wfArrayLookup( $a, $b ) {
899 return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
904 * Ideally we'd be using actual time fields in the db
907 function wfTimestamp2Unix( $ts ) {
908 return gmmktime( ( (int)substr( $ts, 8, 2) ),
909 (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ),
910 (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ),
911 (int)substr( $ts, 0, 4 ) );
917 function wfUnix2Timestamp( $unixtime ) {
918 return gmdate( 'YmdHis', $unixtime );
924 function wfTimestampNow() {
926 return gmdate( 'YmdHis' );
930 * Sorting hack for MySQL 3, which doesn't use index sorts for DESC
932 function wfInvertTimestamp( $ts ) {
941 * Reference-counted warning suppression
943 function wfSuppressWarnings( $end = false ) {
944 static $suppressCount = 0;
945 static $originalLevel = false;
948 if ( $suppressCount ) {
950 if ( !$suppressCount ) {
951 error_reporting( $originalLevel );
955 if ( !$suppressCount ) {
956 $originalLevel = error_reporting( E_ALL
& ~
( E_WARNING | E_NOTICE
) );
963 * Restore error level to previous value
965 function wfRestoreWarnings() {
966 wfSuppressWarnings( true );
969 # Autodetect, convert and provide timestamps of various types
971 /** Standard unix timestamp (number of seconds since 1 Jan 1970) */
973 /** Mediawiki concatenated string timestamp (yyyymmddhhmmss) */
975 /** Standard database timestamp (yyyy-mm-dd hh:mm:ss) */
981 function wfTimestamp($outputtype=TS_UNIX
,$ts=0) {
982 if (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
984 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
985 (int)$da[2],(int)$da[3],(int)$da[1]);
986 } elseif (preg_match("/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/",$ts,$da)) {
988 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
989 (int)$da[2],(int)$da[3],(int)$da[1]);
990 } elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
997 switch($outputtype) {
1002 return gmdate( 'YmdHis', $uts );
1005 return gmdate( 'Y-m-d H:i:s', $uts );
1013 * Check where as the operating system is Windows
1016 * @return bool True if it's windows, False otherwise.
1018 function wfIsWindows() {
1019 if (substr(php_uname(), 0, 7) == 'Windows') {