5 * Global functions used everywhere
9 * Some globals and requires needed
12 $wgNumberOfArticles = -1; # Unset
16 require_once( 'DatabaseFunctions.php' );
17 require_once( 'UpdateClasses.php' );
18 require_once( 'LogPage.php' );
21 * Compatibility functions
22 * PHP <4.3.x is not actively supported; 4.1.x and 4.2.x might or might not work.
23 * <4.1.x will not work, as we use a number of features introduced in 4.1.0
24 * such as the new autoglobals.
26 if( !function_exists('iconv') ) {
27 # iconv support is not in the default configuration and so may not be present.
28 # Assume will only ever use utf-8 and iso-8859-1.
29 # This will *not* work in all circumstances.
30 function iconv( $from, $to, $string ) {
31 if(strcasecmp( $from, $to ) == 0) return $string;
32 if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
33 if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
38 if( !function_exists('file_get_contents') ) {
39 # Exists in PHP 4.3.0+
40 function file_get_contents( $filename ) {
41 return implode( '', file( $filename ) );
45 if( !function_exists('is_a') ) {
46 # Exists in PHP 4.2.0+
47 function is_a( $object, $class_name ) {
49 (strcasecmp( get_class( $object ), $class_name ) == 0) ||
50 is_subclass_of( $object, $class_name );
54 # UTF-8 substr function based on a PHP manual comment
55 if ( !function_exists( 'mb_substr' ) ) {
56 function mb_substr($str,$start)
58 preg_match_all("/./us", $str, $ar);
60 if(func_num_args() >= 3) {
61 $end = func_get_arg(2);
62 return join("",array_slice($ar[0],$start,$end));
64 return join("",array_slice($ar[0],$start));
70 * html_entity_decode exists in PHP 4.3.0+ but is FATALLY BROKEN even then,
71 * with no UTF-8 support.
73 function do_html_entity_decode( $string, $quote_style=ENT_COMPAT
, $charset='ISO-8859-1' ) {
75 if( !isset( $trans ) ) {
76 $trans = array_flip( get_html_translation_table( HTML_ENTITIES
, $quote_style ) );
77 # Assumes $charset will always be the same through a run, and only understands
78 # utf-8 or default. Note - mixing latin1 named entities and unicode numbered
79 # ones will result in a bad link.
80 if( strcasecmp( 'utf-8', $charset ) == 0 ) {
81 $trans = array_map( 'utf8_encode', $trans );
84 return strtr( $string, $trans );
87 $wgRandomSeeded = false;
90 * Seed Mersenne Twister
91 * Only necessary in PHP < 4.2.0
93 function wfSeedRandom()
95 global $wgRandomSeeded;
97 if ( ! $wgRandomSeeded && version_compare( phpversion(), '4.2.0' ) < 0 ) {
98 $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff;
100 $wgRandomSeeded = true;
105 * Generates a URL from a URL-encoded title and a query string
106 * Title::getLocalURL() is preferred in most cases
108 function wfLocalUrl( $a, $q = '' )
110 global $wgServer, $wgScript, $wgArticlePath;
112 $a = str_replace( ' ', '_', $a );
118 $a = $wgScript.'?'.$q;
120 } else if ( '' == $q ) {
121 $a = str_replace( '$1', $a, $wgArticlePath );
122 } else if ($wgScript != '' ) {
123 $a = "{$wgScript}?title={$a}&{$q}";
124 } else { //XXX hackish solution for toplevel wikis
133 function wfLocalUrlE( $a, $q = '' )
135 return htmlspecialchars( wfLocalUrl( $a, $q ) );
136 # die( "Call to obsolete function wfLocalUrlE()" );
140 * We want / and : to be included as literal characters in our title URLs.
141 * %2F in the page titles seems to fatally break for some reason.
143 function wfUrlencode ( $s )
145 $s = urlencode( $s );
146 $s = preg_replace( '/%3[Aa]/', ':', $s );
147 $s = preg_replace( '/%2[Ff]/', '/', $s );
153 * Return the UTF-8 sequence for a given Unicode code point.
154 * Currently doesn't work for values outside the Basic Multilingual Plane.
156 function wfUtf8Sequence( $codepoint ) {
157 if($codepoint < 0x80) return chr($codepoint);
158 if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f |
0xc0) .
159 chr($codepoint & 0x3f |
0x80);
160 if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f |
0xe0) .
161 chr($codepoint >> 6 & 0x3f |
0x80) .
162 chr($codepoint & 0x3f |
0x80);
163 if($codepoint < 0x110000) return chr($codepoint >> 18 & 0x07 |
0xf0) .
164 chr($codepoint >> 12 & 0x3f |
0x80) .
165 chr($codepoint >> 6 & 0x3f |
0x80) .
166 chr($codepoint & 0x3f |
0x80);
168 # There should be no assigned code points outside this range, but...
169 return "&#$codepoint;";
173 * Converts numeric character entities to UTF-8
175 function wfMungeToUtf8( $string ) {
176 global $wgInputEncoding; # This is debatable
177 #$string = iconv($wgInputEncoding, "UTF-8", $string);
178 $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
179 $string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
180 # Should also do named entities here
185 * Converts a single UTF-8 character into the corresponding HTML character
186 * entity (for use with preg_replace_callback)
188 function wfUtf8Entity( $matches ) {
191 $z = ord( $char{0} );
194 while ( $z & 0x80 ) {
202 if ( $length != strlen( $char ) ) {
205 if ( $length == 1 ) {
209 # Mask off the length-determining bits and shift back to the original location
213 # Add in the free bits from subsequent bytes
214 for ( $i=1; $i<$length; $i++
) {
216 $z |
= ord( $char{$i} ) & 0x3f;
224 * Converts all multi-byte characters in a UTF-8 string into the appropriate
227 function wfUtf8ToHTML($string) {
228 return preg_replace_callback( '/[\\xc0-\\xfd][\\x80-\\xbf]*/', 'wfUtf8Entity', $string );
234 function wfDebug( $text, $logonly = false )
236 global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
238 # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
239 if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
243 if ( isset( $wgOut ) && $wgDebugComments && !$logonly ) {
244 $wgOut->debug( $text );
246 if ( '' != $wgDebugLogFile && !$wgProfileOnly ) {
247 error_log( $text, 3, $wgDebugLogFile );
252 * Log for database errors
254 function wfLogDBError( $text ) {
255 global $wgDBerrorLog;
256 if ( $wgDBerrorLog ) {
257 $text = date('D M j G:i:s T Y') . "\t".$text;
258 error_log( $text, 3, $wgDBerrorLog );
265 function logProfilingData()
267 global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
268 global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
271 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
272 $start = (float)$sec +
(float)$usec;
273 $elapsed = $now - $start;
274 if ( $wgProfiling ) {
275 $prof = wfGetProfilingOutput( $start, $elapsed );
277 if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
278 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
279 if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
280 $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
281 if( !empty( $_SERVER['HTTP_FROM'] ) )
282 $forward .= ' from ' . $_SERVER['HTTP_FROM'];
284 $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
285 if($wgUser->getId() == 0)
287 $log = sprintf( "%s\t%04.3f\t%s\n",
288 gmdate( 'YmdHis' ), $elapsed,
289 urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
290 if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' ||
$wgDebugRawPage ) ) {
291 error_log( $log . $prof, 3, $wgDebugLogFile );
297 * Check if the wiki read-only lock file is present. This can be used to lock
298 * off editing functions, but doesn't guarantee that the database will not be
301 function wfReadOnly() {
302 global $wgReadOnlyFile;
304 if ( '' == $wgReadOnlyFile ) {
307 return is_file( $wgReadOnlyFile );
310 $wgReplacementKeys = array( '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9' );
313 * Get a message from anywhere
315 function wfMsg( $key ) {
317 if ( $wgRequest->getVal( 'debugmsg' ) ) {
318 if ( $key == 'linktrail' /* a special case where we want to return something specific */ )
319 return "/^()(.*)$/sD";
323 $args = func_get_args();
324 if ( count( $args ) ) {
325 array_shift( $args );
327 return wfMsgReal( $key, $args, true );
331 * Get a message from the language file
333 function wfMsgNoDB( $key ) {
334 $args = func_get_args();
335 if ( count( $args ) ) {
336 array_shift( $args );
338 return wfMsgReal( $key, $args, false );
342 * Really get a message
344 function wfMsgReal( $key, $args, $useDB ) {
345 global $wgReplacementKeys, $wgMessageCache, $wgLang;
348 wfProfileIn( $fname );
349 if ( $wgMessageCache ) {
350 $message = $wgMessageCache->get( $key, $useDB );
351 } elseif ( $wgLang ) {
352 $message = $wgLang->getMessage( $key );
354 wfDebug( "No language object when getting $key\n" );
355 $message = "<$key>";
359 if( count( $args ) ) {
360 $message = str_replace( $wgReplacementKeys, $args, $message );
362 wfProfileOut( $fname );
367 * Just like exit() but makes a note of it.
368 * Commits open transactions except if the error parameter is set
370 function wfAbruptExit( $error = false ){
371 global $wgLoadBalancer;
372 static $called = false;
378 if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3
379 $bt = debug_backtrace();
380 for($i = 0; $i < count($bt) ; $i++
){
381 $file = $bt[$i]['file'];
382 $line = $bt[$i]['line'];
383 wfDebug("WARNING: Abrupt exit in $file at line $line\n");
386 wfDebug('WARNING: Abrupt exit\n');
389 $wgLoadBalancer->closeAll();
397 function wfErrorExit() {
398 wfAbruptExit( true );
402 * This is meant as a debugging aid to track down where bad data comes from.
403 * Shouldn't be used in production code except maybe in "shouldn't happen" areas.
405 function wfDebugDieBacktrace( $msg = '' ) {
406 global $wgCommandLineMode;
408 if ( function_exists( 'debug_backtrace' ) ) {
409 if ( $wgCommandLineMode ) {
410 $msg .= "\nBacktrace:\n";
412 $msg .= "\n<p>Backtrace:</p>\n<ul>\n";
414 $backtrace = debug_backtrace();
415 foreach( $backtrace as $call ) {
416 $f = explode( DIRECTORY_SEPARATOR
, $call['file'] );
417 $file = $f[count($f)-1];
418 if ( $wgCommandLineMode ) {
419 $msg .= "$file line {$call['line']} calls ";
421 $msg .= '<li>' . $file . ' line ' . $call['line'] . ' calls ';
423 if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
424 $msg .= $call['function'] . '()';
426 if ( $wgCommandLineMode ) {
437 /* Some generic result counters, pulled out of SearchEngine */
439 function wfShowingResults( $offset, $limit )
442 return wfMsg( 'showingresults', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ) );
445 function wfShowingResultsNum( $offset, $limit, $num )
448 return wfMsg( 'showingresultsnum', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+
1 ), $wgLang->formatNum( $num ) );
451 function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false )
453 global $wgUser, $wgLang;
454 $fmtLimit = $wgLang->formatNum( $limit );
455 $prev = wfMsg( 'prevn', $fmtLimit );
456 $next = wfMsg( 'nextn', $fmtLimit );
457 $link = wfUrlencode( $link );
459 $sk = $wgUser->getSkin();
460 if ( 0 != $offset ) {
461 $po = $offset - $limit;
462 if ( $po < 0 ) { $po = 0; }
463 $q = "limit={$limit}&offset={$po}";
464 if ( '' != $query ) { $q .= '&'.$query; }
465 $plink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$prev}</a>";
466 } else { $plink = $prev; }
468 $no = $offset +
$limit;
469 $q = 'limit='.$limit.'&offset='.$no;
470 if ( '' != $query ) { $q .= '&'.$query; }
475 $nlink = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$next}</a>";
477 $nums = wfNumLink( $offset, 20, $link , $query ) . ' | ' .
478 wfNumLink( $offset, 50, $link, $query ) . ' | ' .
479 wfNumLink( $offset, 100, $link, $query ) . ' | ' .
480 wfNumLink( $offset, 250, $link, $query ) . ' | ' .
481 wfNumLink( $offset, 500, $link, $query );
483 return wfMsg( 'viewprevnext', $plink, $nlink, $nums );
486 function wfNumLink( $offset, $limit, $link, $query = '' )
488 global $wgUser, $wgLang;
489 if ( '' == $query ) { $q = ''; }
490 else { $q = $query.'&'; }
491 $q .= 'limit='.$limit.'&offset='.$offset;
493 $fmtLimit = $wgLang->formatNum( $limit );
494 $s = '<a href="' . wfLocalUrlE( $link, $q ) . "\">{$fmtLimit}</a>";
498 function wfClientAcceptsGzip() {
501 # FIXME: we may want to blacklist some broken browsers
503 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
504 $_SERVER['HTTP_ACCEPT_ENCODING'],
506 if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false;
507 wfDebug( " accepts gzip\n" );
515 * Yay, more global functions!
517 function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) {
519 return $wgRequest->getLimitOffset( $deflimit, $optionname );
523 * Escapes the given text so that it may be output using addWikiText()
524 * without any linking, formatting, etc. making its way through. This
525 * is achieved by substituting certain characters with HTML entities.
526 * As required by the callers, <nowiki> is not used. It currently does
527 * not filter out characters which have special meaning only at the
528 * start of a line, such as "*".
530 function wfEscapeWikiText( $text )
533 array( '[', '|', "'", 'ISBN ' , '://' , "\n=", '{{' ),
534 array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ),
535 htmlspecialchars($text) );
539 function wfQuotedPrintable( $string, $charset = '' )
541 # Probably incomplete; see RFC 2045
542 if( empty( $charset ) ) {
543 global $wgInputEncoding;
544 $charset = $wgInputEncoding;
546 $charset = strtoupper( $charset );
547 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
549 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
550 $replace = $illegal . '\t ?_';
551 if( !preg_match( "/[$illegal]/", $string ) ) return $string;
552 $out = "=?$charset?Q?";
553 $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
559 $st = explode( ' ', microtime() );
560 return (float)$st[0] +
(float)$st[1];
564 * Changes the first character to an HTML entity
566 function wfHtmlEscapeFirst( $text ) {
568 $newText = substr($text, 1);
569 return "&#$ord;$newText";
573 * Sets dest to source and returns the original value of dest
574 * If source is NULL, it just returns the value, it doesn't set the variable
576 function wfSetVar( &$dest, $source )
579 if ( !is_null( $source ) ) {
586 * As for wfSetVar except setting a bit
588 function wfSetBit( &$dest, $bit, $state = true ) {
589 $temp = (bool)($dest & $bit );
590 if ( !is_null( $state ) ) {
601 * This function takes two arrays as input, and returns a CGI-style string, e.g.
602 * "days=7&limit=100". Options in the first array override options in the second.
603 * Options set to "" will not be output.
605 function wfArrayToCGI( $array1, $array2 = NULL )
607 if ( !is_null( $array2 ) ) {
608 $array1 = $array1 +
$array2;
612 foreach ( $array1 as $key => $value ) {
613 if ( '' !== $value ) {
617 $cgi .= $key.'='.$value;
624 * This is obsolete, use SquidUpdate::purge()
627 function wfPurgeSquidServers ($urlArr) {
628 SquidUpdate
::purge( $urlArr );
632 * Windows-compatible version of escapeshellarg()
633 * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
634 * function puts single quotes in regardless of OS
636 function wfEscapeShellArg( )
638 $args = func_get_args();
641 foreach ( $args as $arg ) {
648 if ( wfIsWindows() ) {
649 $retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
651 $retVal .= escapeshellarg( $arg );
658 * wfMerge attempts to merge differences between three texts.
659 * Returns true for a clean merge and false for failure or a conflict.
661 function wfMerge( $old, $mine, $yours, &$result ){
664 # This check may also protect against code injection in
665 # case of broken installations.
666 if(! file_exists( $wgDiff3 ) ){
670 # Make temporary files
672 $oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
673 $mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
674 $yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
676 fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
677 fwrite( $mytextFile, $mine ); fclose( $mytextFile );
678 fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
680 # Check for a conflict
681 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a --overlap-only ' .
682 wfEscapeShellArg( $mytextName ) . ' ' .
683 wfEscapeShellArg( $oldtextName ) . ' ' .
684 wfEscapeShellArg( $yourtextName );
685 $handle = popen( $cmd, 'r' );
687 if( fgets( $handle ) ){
695 $cmd = wfEscapeShellArg( $wgDiff3 ) . ' -a -e --merge ' .
696 wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
697 $handle = popen( $cmd, 'r' );
700 $data = fread( $handle, 8192 );
701 if ( strlen( $data ) == 0 ) {
707 unlink( $mytextName ); unlink( $oldtextName ); unlink( $yourtextName );
714 function wfVarDump( $var )
717 $s = str_replace("\n","<br>\n", var_export( $var, true ) . "\n");
718 if ( headers_sent() ||
!@is_object
( $wgOut ) ) {
721 $wgOut->addHTML( $s );
726 * Provide a simple HTTP error.
728 function wfHttpError( $code, $label, $desc ) {
731 header( "HTTP/1.0 $code $label" );
732 header( "Status: $code $label" );
733 $wgOut->sendCacheControl();
735 # Don't send content if it's a HEAD request.
736 if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
737 header( 'Content-type: text/plain' );
743 * Converts an Accept-* header into an array mapping string values to quality
746 function wfAcceptToPrefs( $accept, $def = '*/*' ) {
747 # No arg means accept anything (per HTTP spec)
749 return array( $def => 1 );
754 $parts = explode( ',', $accept );
756 foreach( $parts as $part ) {
757 # FIXME: doesn't deal with params like 'text/html; level=1'
758 @list
( $value, $qpart ) = explode( ';', $part );
759 if( !isset( $qpart ) ) {
761 } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
762 $prefs[$value] = $match[1];
773 function mimeTypeMatch( $type, $avail ) {
774 if( array_key_exists($type, $avail) ) {
777 $parts = explode( '/', $type );
778 if( array_key_exists( $parts[0] . '/*', $avail ) ) {
779 return $parts[0] . '/*';
780 } elseif( array_key_exists( '*/*', $avail ) ) {
789 * @todo FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
790 * XXX: generalize to negotiate other stuff
792 function wfNegotiateType( $cprefs, $sprefs ) {
795 foreach( array_keys($sprefs) as $type ) {
796 $parts = explode( '/', $type );
797 if( $parts[1] != '*' ) {
798 $ckey = mimeTypeMatch( $type, $cprefs );
800 $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
805 foreach( array_keys( $cprefs ) as $type ) {
806 $parts = explode( '/', $type );
807 if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
808 $skey = mimeTypeMatch( $type, $sprefs );
810 $combine[$type] = $sprefs[$skey] * $cprefs[$type];
818 foreach( array_keys( $combine ) as $type ) {
819 if( $combine[$type] > $bestq ) {
821 $bestq = $combine[$type];
830 * Returns an array where the values in the first array are replaced by the
831 * values in the second array with the corresponding keys
833 function wfArrayLookup( $a, $b )
835 return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
840 * Ideally we'd be using actual time fields in the db
843 function wfTimestamp2Unix( $ts ) {
844 return gmmktime( ( (int)substr( $ts, 8, 2) ),
845 (int)substr( $ts, 10, 2 ), (int)substr( $ts, 12, 2 ),
846 (int)substr( $ts, 4, 2 ), (int)substr( $ts, 6, 2 ),
847 (int)substr( $ts, 0, 4 ) );
850 function wfUnix2Timestamp( $unixtime ) {
851 return gmdate( 'YmdHis', $unixtime );
854 function wfTimestampNow() {
856 return gmdate( 'YmdHis' );
860 * Sorting hack for MySQL 3, which doesn't use index sorts for DESC
862 function wfInvertTimestamp( $ts ) {
871 * Reference-counted warning suppression
873 function wfSuppressWarnings( $end = false ) {
874 static $suppressCount = 0;
875 static $originalLevel = false;
878 if ( $suppressCount ) {
880 if ( !$suppressCount ) {
881 error_reporting( $originalLevel );
885 if ( !$suppressCount ) {
886 $originalLevel = error_reporting( E_ALL
& ~
( E_WARNING | E_NOTICE
) );
893 * Restore error level to previous value
895 function wfRestoreWarnings() {
896 wfSuppressWarnings( true );
899 # Autodetect, convert and provide timestamps of various types
900 define('TS_UNIX',0); # Standard unix timestamp (number of seconds since 1 Jan 1970)
901 define('TS_MW',1); # Mediawiki concatenated string timestamp (yyyymmddhhmmss)
902 define('TS_DB',2); # Standard database timestamp (yyyy-mm-dd hh:mm:ss)
907 function wfTimestamp($outputtype=TS_UNIX
,$ts=0) {
908 if (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
910 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
911 (int)$da[2],(int)$da[3],(int)$da[1]);
912 } elseif (preg_match("/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/",$ts,$da)) {
914 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
915 (int)$da[2],(int)$da[3],(int)$da[1]);
916 } elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
923 switch($outputtype) {
928 return gmdate( 'YmdHis', $uts );
931 return gmdate( 'Y-m-d H:i:s', $uts );
941 function wfIsWindows() {
942 if (substr(php_uname(), 0, 7) == 'Windows') {