* Added a new paramater to wfDebugLog()
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
1 <?php
2
3 /**
4 * Global functions used everywhere
5 * @package MediaWiki
6 */
7
8 /**
9 * Some globals and requires needed
10 */
11
12 /**
13 * Total number of articles
14 * @global integer $wgNumberOfArticles
15 */
16 $wgNumberOfArticles = -1; # Unset
17 /**
18 * Total number of views
19 * @global integer $wgTotalViews
20 */
21 $wgTotalViews = -1;
22 /**
23 * Total number of edits
24 * @global integer $wgTotalEdits
25 */
26 $wgTotalEdits = -1;
27
28
29 require_once( 'DatabaseFunctions.php' );
30 require_once( 'UpdateClasses.php' );
31 require_once( 'LogPage.php' );
32 require_once( 'normal/UtfNormalUtil.php' );
33
34 /**
35 * Compatibility functions
36 * PHP <4.3.x is not actively supported; 4.1.x and 4.2.x might or might not work.
37 * <4.1.x will not work, as we use a number of features introduced in 4.1.0
38 * such as the new autoglobals.
39 */
40 if( !function_exists('iconv') ) {
41 # iconv support is not in the default configuration and so may not be present.
42 # Assume will only ever use utf-8 and iso-8859-1.
43 # This will *not* work in all circumstances.
44 function iconv( $from, $to, $string ) {
45 if(strcasecmp( $from, $to ) == 0) return $string;
46 if(strcasecmp( $from, 'utf-8' ) == 0) return utf8_decode( $string );
47 if(strcasecmp( $to, 'utf-8' ) == 0) return utf8_encode( $string );
48 return $string;
49 }
50 }
51
52 if( !function_exists('file_get_contents') ) {
53 # Exists in PHP 4.3.0+
54 function file_get_contents( $filename ) {
55 return implode( '', file( $filename ) );
56 }
57 }
58
59 if( !function_exists('is_a') ) {
60 # Exists in PHP 4.2.0+
61 function is_a( $object, $class_name ) {
62 return
63 (strcasecmp( get_class( $object ), $class_name ) == 0) ||
64 is_subclass_of( $object, $class_name );
65 }
66 }
67
68 # UTF-8 substr function based on a PHP manual comment
69 if ( !function_exists( 'mb_substr' ) ) {
70 function mb_substr( $str, $start ) {
71 preg_match_all( '/./us', $str, $ar );
72
73 if( func_num_args() >= 3 ) {
74 $end = func_get_arg( 2 );
75 return join( '', array_slice( $ar[0], $start, $end ) );
76 } else {
77 return join( '', array_slice( $ar[0], $start ) );
78 }
79 }
80 }
81
82 if( !function_exists( 'floatval' ) ) {
83 /**
84 * First defined in PHP 4.2.0
85 * @param mixed $var;
86 * @return float
87 */
88 function floatval( $var ) {
89 return (float)$var;
90 }
91 }
92
93 /**
94 * Where as we got a random seed
95 * @var bool $wgTotalViews
96 */
97 $wgRandomSeeded = false;
98
99 /**
100 * Seed Mersenne Twister
101 * Only necessary in PHP < 4.2.0
102 *
103 * @return bool
104 */
105 function wfSeedRandom() {
106 global $wgRandomSeeded;
107
108 if ( ! $wgRandomSeeded && version_compare( phpversion(), '4.2.0' ) < 0 ) {
109 $seed = hexdec(substr(md5(microtime()),-8)) & 0x7fffffff;
110 mt_srand( $seed );
111 $wgRandomSeeded = true;
112 }
113 }
114
115 /**
116 * Get a random decimal value between 0 and 1, in a way
117 * not likely to give duplicate values for any realistic
118 * number of articles.
119 *
120 * @return string
121 */
122 function wfRandom() {
123 # The maximum random value is "only" 2^31-1, so get two random
124 # values to reduce the chance of dupes
125 $max = mt_getrandmax();
126 $rand = number_format( (mt_rand() * $max + mt_rand())
127 / $max / $max, 12, '.', '' );
128 return $rand;
129 }
130
131 /**
132 * We want / and : to be included as literal characters in our title URLs.
133 * %2F in the page titles seems to fatally break for some reason.
134 *
135 * @param string $s
136 * @return string
137 */
138 function wfUrlencode ( $s ) {
139 $s = urlencode( $s );
140 $s = preg_replace( '/%3[Aa]/', ':', $s );
141 $s = preg_replace( '/%2[Ff]/', '/', $s );
142
143 return $s;
144 }
145
146 /**
147 * Sends a line to the debug log if enabled or, optionally, to a comment in output.
148 * In normal operation this is a NOP.
149 *
150 * Controlling globals:
151 * $wgDebugLogFile - points to the log file
152 * $wgProfileOnly - if set, normal debug messages will not be recorded.
153 * $wgDebugRawPage - if false, 'action=raw' hits will not result in debug output.
154 * $wgDebugComments - if on, some debug items may appear in comments in the HTML output.
155 *
156 * @param string $text
157 * @param bool $logonly Set true to avoid appearing in HTML when $wgDebugComments is set
158 */
159 function wfDebug( $text, $logonly = false ) {
160 global $wgOut, $wgDebugLogFile, $wgDebugComments, $wgProfileOnly, $wgDebugRawPage;
161
162 # Check for raw action using $_GET not $wgRequest, since the latter might not be initialised yet
163 if ( isset( $_GET['action'] ) && $_GET['action'] == 'raw' && !$wgDebugRawPage ) {
164 return;
165 }
166
167 if ( isset( $wgOut ) && $wgDebugComments && !$logonly ) {
168 $wgOut->debug( $text );
169 }
170 if ( '' != $wgDebugLogFile && !$wgProfileOnly ) {
171 # Strip unprintables; they can switch terminal modes when binary data
172 # gets dumped, which is pretty annoying.
173 $text = preg_replace( '![\x00-\x08\x0b\x0c\x0e-\x1f]!', ' ', $text );
174 @error_log( $text, 3, $wgDebugLogFile );
175 }
176 }
177
178 /**
179 * Send a line to a supplementary debug log file, if configured, or main debug log if not.
180 * $wgDebugLogGroups[$logGroup] should be set to a filename to send to a separate log.
181 *
182 * @param string $logGroup
183 * @param string $text
184 * @param bool $public Whether to log the event in the public log if no private
185 * log file is specified, (default true)
186 */
187 function wfDebugLog( $logGroup, $text, $public = true ) {
188 global $wgDebugLogGroups, $wgDBname;
189 if( $text{strlen( $text ) - 1} != "\n" ) $text .= "\n";
190 if( isset( $wgDebugLogGroups[$logGroup] ) ) {
191 @error_log( "$wgDBname: $text", 3, $wgDebugLogGroups[$logGroup] );
192 } else if ( $public === true ) {
193 wfDebug( $text, true );
194 }
195 }
196
197 /**
198 * Log for database errors
199 * @param string $text Database error message.
200 */
201 function wfLogDBError( $text ) {
202 global $wgDBerrorLog;
203 if ( $wgDBerrorLog ) {
204 $text = date('D M j G:i:s T Y') . "\t".$text;
205 error_log( $text, 3, $wgDBerrorLog );
206 }
207 }
208
209 /**
210 * @todo document
211 */
212 function logProfilingData() {
213 global $wgRequestTime, $wgDebugLogFile, $wgDebugRawPage, $wgRequest;
214 global $wgProfiling, $wgProfileStack, $wgProfileLimit, $wgUser;
215 $now = wfTime();
216
217 list( $usec, $sec ) = explode( ' ', $wgRequestTime );
218 $start = (float)$sec + (float)$usec;
219 $elapsed = $now - $start;
220 if ( $wgProfiling ) {
221 $prof = wfGetProfilingOutput( $start, $elapsed );
222 $forward = '';
223 if( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
224 $forward = ' forwarded for ' . $_SERVER['HTTP_X_FORWARDED_FOR'];
225 if( !empty( $_SERVER['HTTP_CLIENT_IP'] ) )
226 $forward .= ' client IP ' . $_SERVER['HTTP_CLIENT_IP'];
227 if( !empty( $_SERVER['HTTP_FROM'] ) )
228 $forward .= ' from ' . $_SERVER['HTTP_FROM'];
229 if( $forward )
230 $forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
231 if( $wgUser->isAnon() )
232 $forward .= ' anon';
233 $log = sprintf( "%s\t%04.3f\t%s\n",
234 gmdate( 'YmdHis' ), $elapsed,
235 urldecode( $_SERVER['REQUEST_URI'] . $forward ) );
236 if ( '' != $wgDebugLogFile && ( $wgRequest->getVal('action') != 'raw' || $wgDebugRawPage ) ) {
237 error_log( $log . $prof, 3, $wgDebugLogFile );
238 }
239 }
240 }
241
242 /**
243 * Check if the wiki read-only lock file is present. This can be used to lock
244 * off editing functions, but doesn't guarantee that the database will not be
245 * modified.
246 * @return bool
247 */
248 function wfReadOnly() {
249 global $wgReadOnlyFile, $wgReadOnly;
250
251 if ( $wgReadOnly ) {
252 return true;
253 }
254 if ( '' == $wgReadOnlyFile ) {
255 return false;
256 }
257
258 // Set $wgReadOnly and unset $wgReadOnlyFile, for faster access next time
259 if ( is_file( $wgReadOnlyFile ) ) {
260 $wgReadOnly = file_get_contents( $wgReadOnlyFile );
261 } else {
262 $wgReadOnly = false;
263 }
264 $wgReadOnlyFile = '';
265 return $wgReadOnly;
266 }
267
268
269 /**
270 * Get a message from anywhere, for the current user language.
271 *
272 * Use wfMsgForContent() instead if the message should NOT
273 * change depending on the user preferences.
274 *
275 * Note that the message may contain HTML, and is therefore
276 * not safe for insertion anywhere. Some functions such as
277 * addWikiText will do the escaping for you. Use wfMsgHtml()
278 * if you need an escaped message.
279 *
280 * @param string lookup key for the message, usually
281 * defined in languages/Language.php
282 */
283 function wfMsg( $key ) {
284 $args = func_get_args();
285 array_shift( $args );
286 return wfMsgReal( $key, $args, true );
287 }
288
289 /**
290 * Get a message from anywhere, for the current global language
291 * set with $wgLanguageCode.
292 *
293 * Use this if the message should NOT change dependent on the
294 * language set in the user's preferences. This is the case for
295 * most text written into logs, as well as link targets (such as
296 * the name of the copyright policy page). Link titles, on the
297 * other hand, should be shown in the UI language.
298 *
299 * Note that MediaWiki allows users to change the user interface
300 * language in their preferences, but a single installation
301 * typically only contains content in one language.
302 *
303 * Be wary of this distinction: If you use wfMsg() where you should
304 * use wfMsgForContent(), a user of the software may have to
305 * customize over 70 messages in order to, e.g., fix a link in every
306 * possible language.
307 *
308 * @param string lookup key for the message, usually
309 * defined in languages/Language.php
310 */
311 function wfMsgForContent( $key ) {
312 global $wgForceUIMsgAsContentMsg;
313 $args = func_get_args();
314 array_shift( $args );
315 $forcontent = true;
316 if( is_array( $wgForceUIMsgAsContentMsg ) &&
317 in_array( $key, $wgForceUIMsgAsContentMsg ) )
318 $forcontent = false;
319 return wfMsgReal( $key, $args, true, $forcontent );
320 }
321
322 /**
323 * Get a message from the language file, for the UI elements
324 */
325 function wfMsgNoDB( $key ) {
326 $args = func_get_args();
327 array_shift( $args );
328 return wfMsgReal( $key, $args, false );
329 }
330
331 /**
332 * Get a message from the language file, for the content
333 */
334 function wfMsgNoDBForContent( $key ) {
335 global $wgForceUIMsgAsContentMsg;
336 $args = func_get_args();
337 array_shift( $args );
338 $forcontent = true;
339 if( is_array( $wgForceUIMsgAsContentMsg ) &&
340 in_array( $key, $wgForceUIMsgAsContentMsg ) )
341 $forcontent = false;
342 return wfMsgReal( $key, $args, false, $forcontent );
343 }
344
345
346 /**
347 * Really get a message
348 */
349 function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
350 $fname = 'wfMsgReal';
351 wfProfileIn( $fname );
352
353 $message = wfMsgGetKey( $key, $useDB, $forContent );
354 $message = wfMsgReplaceArgs( $message, $args );
355 wfProfileOut( $fname );
356 return $message;
357 }
358
359 /**
360 * Fetch a message string value, but don't replace any keys yet.
361 * @param string $key
362 * @param bool $useDB
363 * @param bool $forContent
364 * @return string
365 * @access private
366 */
367 function wfMsgGetKey( $key, $useDB, $forContent = false ) {
368 global $wgParser, $wgMsgParserOptions;
369 global $wgContLang, $wgLanguageCode;
370 global $wgMessageCache, $wgLang;
371
372 if( is_object( $wgMessageCache ) ) {
373 $message = $wgMessageCache->get( $key, $useDB, $forContent );
374 } else {
375 if( $forContent ) {
376 $lang = &$wgContLang;
377 } else {
378 $lang = &$wgLang;
379 }
380
381 wfSuppressWarnings();
382
383 if( is_object( $lang ) ) {
384 $message = $lang->getMessage( $key );
385 } else {
386 $message = false;
387 }
388 wfRestoreWarnings();
389 if($message === false)
390 $message = Language::getMessage($key);
391 if(strstr($message, '{{' ) !== false) {
392 $message = $wgParser->transformMsg($message, $wgMsgParserOptions);
393 }
394 }
395 return $message;
396 }
397
398 /**
399 * Replace message parameter keys on the given formatted output.
400 *
401 * @param string $message
402 * @param array $args
403 * @return string
404 * @access private
405 */
406 function wfMsgReplaceArgs( $message, $args ) {
407 static $replacementKeys = array( '$1', '$2', '$3', '$4', '$5', '$6', '$7', '$8', '$9' );
408
409 # Fix windows line-endings
410 # Some messages are split with explode("\n", $msg)
411 $message = str_replace( "\r", '', $message );
412
413 # Replace arguments
414 if( count( $args ) ) {
415 $message = str_replace( $replacementKeys, $args, $message );
416 }
417 return $message;
418 }
419
420 /**
421 * Return an HTML-escaped version of a message.
422 * Parameter replacements, if any, are done *after* the HTML-escaping,
423 * so parameters may contain HTML (eg links or form controls). Be sure
424 * to pre-escape them if you really do want plaintext, or just wrap
425 * the whole thing in htmlspecialchars().
426 *
427 * @param string $key
428 * @param string ... parameters
429 * @return string
430 */
431 function wfMsgHtml( $key ) {
432 $args = func_get_args();
433 array_shift( $args );
434 return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key, true ) ), $args );
435 }
436
437 /**
438 * Return an HTML version of message
439 * Parameter replacements, if any, are done *after* parsing the wiki-text message,
440 * so parameters may contain HTML (eg links or form controls). Be sure
441 * to pre-escape them if you really do want plaintext, or just wrap
442 * the whole thing in htmlspecialchars().
443 *
444 * @param string $key
445 * @param string ... parameters
446 * @return string
447 */
448 function wfMsgWikiHtml( $key ) {
449 global $wgOut;
450 $args = func_get_args();
451 array_shift( $args );
452 return wfMsgReplaceArgs( $wgOut->parse( wfMsgGetKey( $key, true ), /* can't be set to false */ true ), $args );
453 }
454
455 /**
456 * Just like exit() but makes a note of it.
457 * Commits open transactions except if the error parameter is set
458 */
459 function wfAbruptExit( $error = false ){
460 global $wgLoadBalancer;
461 static $called = false;
462 if ( $called ){
463 exit();
464 }
465 $called = true;
466
467 if( function_exists( 'debug_backtrace' ) ){ // PHP >= 4.3
468 $bt = debug_backtrace();
469 for($i = 0; $i < count($bt) ; $i++){
470 $file = $bt[$i]['file'];
471 $line = $bt[$i]['line'];
472 wfDebug("WARNING: Abrupt exit in $file at line $line\n");
473 }
474 } else {
475 wfDebug('WARNING: Abrupt exit\n');
476 }
477 if ( !$error ) {
478 $wgLoadBalancer->closeAll();
479 }
480 exit();
481 }
482
483 /**
484 * @todo document
485 */
486 function wfErrorExit() {
487 wfAbruptExit( true );
488 }
489
490 /**
491 * Die with a backtrace
492 * This is meant as a debugging aid to track down where bad data comes from.
493 * Shouldn't be used in production code except maybe in "shouldn't happen" areas.
494 *
495 * @param string $msg Message shown when dieing.
496 */
497 function wfDebugDieBacktrace( $msg = '' ) {
498 global $wgCommandLineMode;
499
500 $backtrace = wfBacktrace();
501 if ( $backtrace !== false ) {
502 if ( $wgCommandLineMode ) {
503 $msg .= "\nBacktrace:\n$backtrace";
504 } else {
505 $msg .= "\n<p>Backtrace:</p>\n$backtrace";
506 }
507 }
508 echo $msg;
509 die( -1 );
510 }
511
512 function wfBacktrace() {
513 global $wgCommandLineMode;
514 if ( !function_exists( 'debug_backtrace' ) ) {
515 return false;
516 }
517
518 if ( $wgCommandLineMode ) {
519 $msg = '';
520 } else {
521 $msg = "<ul>\n";
522 }
523 $backtrace = debug_backtrace();
524 foreach( $backtrace as $call ) {
525 if( isset( $call['file'] ) ) {
526 $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
527 $file = $f[count($f)-1];
528 } else {
529 $file = '-';
530 }
531 if( isset( $call['line'] ) ) {
532 $line = $call['line'];
533 } else {
534 $line = '-';
535 }
536 if ( $wgCommandLineMode ) {
537 $msg .= "$file line $line calls ";
538 } else {
539 $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
540 }
541 if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
542 $msg .= $call['function'] . '()';
543
544 if ( $wgCommandLineMode ) {
545 $msg .= "\n";
546 } else {
547 $msg .= "</li>\n";
548 }
549 }
550 if ( $wgCommandLineMode ) {
551 $msg .= "\n";
552 } else {
553 $msg .= "</ul>\n";
554 }
555
556 return $msg;
557 }
558
559
560 /* Some generic result counters, pulled out of SearchEngine */
561
562
563 /**
564 * @todo document
565 */
566 function wfShowingResults( $offset, $limit ) {
567 global $wgLang;
568 return wfMsg( 'showingresults', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ) );
569 }
570
571 /**
572 * @todo document
573 */
574 function wfShowingResultsNum( $offset, $limit, $num ) {
575 global $wgLang;
576 return wfMsg( 'showingresultsnum', $wgLang->formatNum( $limit ), $wgLang->formatNum( $offset+1 ), $wgLang->formatNum( $num ) );
577 }
578
579 /**
580 * @todo document
581 */
582 function wfViewPrevNext( $offset, $limit, $link, $query = '', $atend = false ) {
583 global $wgUser, $wgLang;
584 $fmtLimit = $wgLang->formatNum( $limit );
585 $prev = wfMsg( 'prevn', $fmtLimit );
586 $next = wfMsg( 'nextn', $fmtLimit );
587
588 if( is_object( $link ) ) {
589 $title =& $link;
590 } else {
591 $title = Title::newFromText( $link );
592 if( is_null( $title ) ) {
593 return false;
594 }
595 }
596
597 $sk = $wgUser->getSkin();
598 if ( 0 != $offset ) {
599 $po = $offset - $limit;
600 if ( $po < 0 ) { $po = 0; }
601 $q = "limit={$limit}&offset={$po}";
602 if ( '' != $query ) { $q .= '&'.$query; }
603 $plink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$prev}</a>";
604 } else { $plink = $prev; }
605
606 $no = $offset + $limit;
607 $q = 'limit='.$limit.'&offset='.$no;
608 if ( '' != $query ) { $q .= '&'.$query; }
609
610 if ( $atend ) {
611 $nlink = $next;
612 } else {
613 $nlink = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$next}</a>";
614 }
615 $nums = wfNumLink( $offset, 20, $title, $query ) . ' | ' .
616 wfNumLink( $offset, 50, $title, $query ) . ' | ' .
617 wfNumLink( $offset, 100, $title, $query ) . ' | ' .
618 wfNumLink( $offset, 250, $title, $query ) . ' | ' .
619 wfNumLink( $offset, 500, $title, $query );
620
621 return wfMsg( 'viewprevnext', $plink, $nlink, $nums );
622 }
623
624 /**
625 * @todo document
626 */
627 function wfNumLink( $offset, $limit, &$title, $query = '' ) {
628 global $wgUser, $wgLang;
629 if ( '' == $query ) { $q = ''; }
630 else { $q = $query.'&'; }
631 $q .= 'limit='.$limit.'&offset='.$offset;
632
633 $fmtLimit = $wgLang->formatNum( $limit );
634 $s = '<a href="' . $title->escapeLocalUrl( $q ) . "\">{$fmtLimit}</a>";
635 return $s;
636 }
637
638 /**
639 * @todo document
640 * @todo FIXME: we may want to blacklist some broken browsers
641 *
642 * @return bool Whereas client accept gzip compression
643 */
644 function wfClientAcceptsGzip() {
645 global $wgUseGzip;
646 if( $wgUseGzip ) {
647 # FIXME: we may want to blacklist some broken browsers
648 if( preg_match(
649 '/\bgzip(?:;(q)=([0-9]+(?:\.[0-9]+)))?\b/',
650 $_SERVER['HTTP_ACCEPT_ENCODING'],
651 $m ) ) {
652 if( isset( $m[2] ) && ( $m[1] == 'q' ) && ( $m[2] == 0 ) ) return false;
653 wfDebug( " accepts gzip\n" );
654 return true;
655 }
656 }
657 return false;
658 }
659
660 /**
661 * Yay, more global functions!
662 */
663 function wfCheckLimits( $deflimit = 50, $optionname = 'rclimit' ) {
664 global $wgRequest;
665 return $wgRequest->getLimitOffset( $deflimit, $optionname );
666 }
667
668 /**
669 * Escapes the given text so that it may be output using addWikiText()
670 * without any linking, formatting, etc. making its way through. This
671 * is achieved by substituting certain characters with HTML entities.
672 * As required by the callers, <nowiki> is not used. It currently does
673 * not filter out characters which have special meaning only at the
674 * start of a line, such as "*".
675 *
676 * @param string $text Text to be escaped
677 */
678 function wfEscapeWikiText( $text ) {
679 $text = str_replace(
680 array( '[', '|', '\'', 'ISBN ' , '://' , "\n=", '{{' ),
681 array( '&#91;', '&#124;', '&#39;', 'ISBN&#32;', '&#58;//' , "\n&#61;", '&#123;&#123;' ),
682 htmlspecialchars($text) );
683 return $text;
684 }
685
686 /**
687 * @todo document
688 */
689 function wfQuotedPrintable( $string, $charset = '' ) {
690 # Probably incomplete; see RFC 2045
691 if( empty( $charset ) ) {
692 global $wgInputEncoding;
693 $charset = $wgInputEncoding;
694 }
695 $charset = strtoupper( $charset );
696 $charset = str_replace( 'ISO-8859', 'ISO8859', $charset ); // ?
697
698 $illegal = '\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\xff=';
699 $replace = $illegal . '\t ?_';
700 if( !preg_match( "/[$illegal]/", $string ) ) return $string;
701 $out = "=?$charset?Q?";
702 $out .= preg_replace( "/([$replace])/e", 'sprintf("=%02X",ord("$1"))', $string );
703 $out .= '?=';
704 return $out;
705 }
706
707 /**
708 * Returns an escaped string suitable for inclusion in a string literal
709 * for JavaScript source code.
710 * Illegal control characters are assumed not to be present.
711 *
712 * @param string $string
713 * @return string
714 */
715 function wfEscapeJsString( $string ) {
716 // See ECMA 262 section 7.8.4 for string literal format
717 $pairs = array(
718 "\\" => "\\\\",
719 "\"" => "\\\"",
720 '\'' => '\\\'',
721 "\n" => "\\n",
722 "\r" => "\\r",
723
724 # To avoid closing the element or CDATA section
725 "<" => "\\x3c",
726 ">" => "\\x3e",
727 );
728 return strtr( $string, $pairs );
729 }
730
731 /**
732 * @todo document
733 * @return float
734 */
735 function wfTime() {
736 $st = explode( ' ', microtime() );
737 return (float)$st[0] + (float)$st[1];
738 }
739
740 /**
741 * Changes the first character to an HTML entity
742 */
743 function wfHtmlEscapeFirst( $text ) {
744 $ord = ord($text);
745 $newText = substr($text, 1);
746 return "&#$ord;$newText";
747 }
748
749 /**
750 * Sets dest to source and returns the original value of dest
751 * If source is NULL, it just returns the value, it doesn't set the variable
752 */
753 function wfSetVar( &$dest, $source ) {
754 $temp = $dest;
755 if ( !is_null( $source ) ) {
756 $dest = $source;
757 }
758 return $temp;
759 }
760
761 /**
762 * As for wfSetVar except setting a bit
763 */
764 function wfSetBit( &$dest, $bit, $state = true ) {
765 $temp = (bool)($dest & $bit );
766 if ( !is_null( $state ) ) {
767 if ( $state ) {
768 $dest |= $bit;
769 } else {
770 $dest &= ~$bit;
771 }
772 }
773 return $temp;
774 }
775
776 /**
777 * This function takes two arrays as input, and returns a CGI-style string, e.g.
778 * "days=7&limit=100". Options in the first array override options in the second.
779 * Options set to "" will not be output.
780 */
781 function wfArrayToCGI( $array1, $array2 = NULL )
782 {
783 if ( !is_null( $array2 ) ) {
784 $array1 = $array1 + $array2;
785 }
786
787 $cgi = '';
788 foreach ( $array1 as $key => $value ) {
789 if ( '' !== $value ) {
790 if ( '' != $cgi ) {
791 $cgi .= '&';
792 }
793 $cgi .= urlencode( $key ) . '=' . urlencode( $value );
794 }
795 }
796 return $cgi;
797 }
798
799 /**
800 * This is obsolete, use SquidUpdate::purge()
801 * @deprecated
802 */
803 function wfPurgeSquidServers ($urlArr) {
804 SquidUpdate::purge( $urlArr );
805 }
806
807 /**
808 * Windows-compatible version of escapeshellarg()
809 * Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
810 * function puts single quotes in regardless of OS
811 */
812 function wfEscapeShellArg( ) {
813 $args = func_get_args();
814 $first = true;
815 $retVal = '';
816 foreach ( $args as $arg ) {
817 if ( !$first ) {
818 $retVal .= ' ';
819 } else {
820 $first = false;
821 }
822
823 if ( wfIsWindows() ) {
824 $retVal .= '"' . str_replace( '"','\"', $arg ) . '"';
825 } else {
826 $retVal .= escapeshellarg( $arg );
827 }
828 }
829 return $retVal;
830 }
831
832 /**
833 * wfMerge attempts to merge differences between three texts.
834 * Returns true for a clean merge and false for failure or a conflict.
835 */
836 function wfMerge( $old, $mine, $yours, &$result ){
837 global $wgDiff3;
838
839 # This check may also protect against code injection in
840 # case of broken installations.
841 if(! file_exists( $wgDiff3 ) ){
842 wfDebug( "diff3 not found\n" );
843 return false;
844 }
845
846 # Make temporary files
847 $td = wfTempDir();
848 $oldtextFile = fopen( $oldtextName = tempnam( $td, 'merge-old-' ), 'w' );
849 $mytextFile = fopen( $mytextName = tempnam( $td, 'merge-mine-' ), 'w' );
850 $yourtextFile = fopen( $yourtextName = tempnam( $td, 'merge-your-' ), 'w' );
851
852 fwrite( $oldtextFile, $old ); fclose( $oldtextFile );
853 fwrite( $mytextFile, $mine ); fclose( $mytextFile );
854 fwrite( $yourtextFile, $yours ); fclose( $yourtextFile );
855
856 # Check for a conflict
857 $cmd = $wgDiff3 . ' -a --overlap-only ' .
858 wfEscapeShellArg( $mytextName ) . ' ' .
859 wfEscapeShellArg( $oldtextName ) . ' ' .
860 wfEscapeShellArg( $yourtextName );
861 $handle = popen( $cmd, 'r' );
862
863 if( fgets( $handle, 1024 ) ){
864 $conflict = true;
865 } else {
866 $conflict = false;
867 }
868 pclose( $handle );
869
870 # Merge differences
871 $cmd = $wgDiff3 . ' -a -e --merge ' .
872 wfEscapeShellArg( $mytextName, $oldtextName, $yourtextName );
873 $handle = popen( $cmd, 'r' );
874 $result = '';
875 do {
876 $data = fread( $handle, 8192 );
877 if ( strlen( $data ) == 0 ) {
878 break;
879 }
880 $result .= $data;
881 } while ( true );
882 pclose( $handle );
883 unlink( $mytextName ); unlink( $oldtextName ); unlink( $yourtextName );
884
885 if ( $result === '' && $old !== '' && $conflict == false ) {
886 wfDebug( "Unexpected null result from diff3.\nCommand: $cmd\nOutput: " . `$cmd 2>&1` . "\n" );
887 $conflict = true;
888 }
889 return ! $conflict;
890 }
891
892 /**
893 * @todo document
894 */
895 function wfVarDump( $var ) {
896 global $wgOut;
897 $s = str_replace("\n","<br />\n", var_export( $var, true ) . "\n");
898 if ( headers_sent() || !@is_object( $wgOut ) ) {
899 print $s;
900 } else {
901 $wgOut->addHTML( $s );
902 }
903 }
904
905 /**
906 * Provide a simple HTTP error.
907 */
908 function wfHttpError( $code, $label, $desc ) {
909 global $wgOut;
910 $wgOut->disable();
911 header( "HTTP/1.0 $code $label" );
912 header( "Status: $code $label" );
913 $wgOut->sendCacheControl();
914
915 header( 'Content-type: text/html' );
916 print "<html><head><title>" .
917 htmlspecialchars( $label ) .
918 "</title></head><body><h1>" .
919 htmlspecialchars( $label ) .
920 "</h1><p>" .
921 htmlspecialchars( $desc ) .
922 "</p></body></html>\n";
923 }
924
925 /**
926 * Converts an Accept-* header into an array mapping string values to quality
927 * factors
928 */
929 function wfAcceptToPrefs( $accept, $def = '*/*' ) {
930 # No arg means accept anything (per HTTP spec)
931 if( !$accept ) {
932 return array( $def => 1 );
933 }
934
935 $prefs = array();
936
937 $parts = explode( ',', $accept );
938
939 foreach( $parts as $part ) {
940 # FIXME: doesn't deal with params like 'text/html; level=1'
941 @list( $value, $qpart ) = explode( ';', $part );
942 if( !isset( $qpart ) ) {
943 $prefs[$value] = 1;
944 } elseif( preg_match( '/q\s*=\s*(\d*\.\d+)/', $qpart, $match ) ) {
945 $prefs[$value] = $match[1];
946 }
947 }
948
949 return $prefs;
950 }
951
952 /**
953 * Checks if a given MIME type matches any of the keys in the given
954 * array. Basic wildcards are accepted in the array keys.
955 *
956 * Returns the matching MIME type (or wildcard) if a match, otherwise
957 * NULL if no match.
958 *
959 * @param string $type
960 * @param array $avail
961 * @return string
962 * @access private
963 */
964 function mimeTypeMatch( $type, $avail ) {
965 if( array_key_exists($type, $avail) ) {
966 return $type;
967 } else {
968 $parts = explode( '/', $type );
969 if( array_key_exists( $parts[0] . '/*', $avail ) ) {
970 return $parts[0] . '/*';
971 } elseif( array_key_exists( '*/*', $avail ) ) {
972 return '*/*';
973 } else {
974 return NULL;
975 }
976 }
977 }
978
979 /**
980 * Returns the 'best' match between a client's requested internet media types
981 * and the server's list of available types. Each list should be an associative
982 * array of type to preference (preference is a float between 0.0 and 1.0).
983 * Wildcards in the types are acceptable.
984 *
985 * @param array $cprefs Client's acceptable type list
986 * @param array $sprefs Server's offered types
987 * @return string
988 *
989 * @todo FIXME: doesn't handle params like 'text/plain; charset=UTF-8'
990 * XXX: generalize to negotiate other stuff
991 */
992 function wfNegotiateType( $cprefs, $sprefs ) {
993 $combine = array();
994
995 foreach( array_keys($sprefs) as $type ) {
996 $parts = explode( '/', $type );
997 if( $parts[1] != '*' ) {
998 $ckey = mimeTypeMatch( $type, $cprefs );
999 if( $ckey ) {
1000 $combine[$type] = $sprefs[$type] * $cprefs[$ckey];
1001 }
1002 }
1003 }
1004
1005 foreach( array_keys( $cprefs ) as $type ) {
1006 $parts = explode( '/', $type );
1007 if( $parts[1] != '*' && !array_key_exists( $type, $sprefs ) ) {
1008 $skey = mimeTypeMatch( $type, $sprefs );
1009 if( $skey ) {
1010 $combine[$type] = $sprefs[$skey] * $cprefs[$type];
1011 }
1012 }
1013 }
1014
1015 $bestq = 0;
1016 $besttype = NULL;
1017
1018 foreach( array_keys( $combine ) as $type ) {
1019 if( $combine[$type] > $bestq ) {
1020 $besttype = $type;
1021 $bestq = $combine[$type];
1022 }
1023 }
1024
1025 return $besttype;
1026 }
1027
1028 /**
1029 * Array lookup
1030 * Returns an array where the values in the first array are replaced by the
1031 * values in the second array with the corresponding keys
1032 *
1033 * @return array
1034 */
1035 function wfArrayLookup( $a, $b ) {
1036 return array_flip( array_intersect( array_flip( $a ), array_keys( $b ) ) );
1037 }
1038
1039 /**
1040 * Convenience function; returns MediaWiki timestamp for the present time.
1041 * @return string
1042 */
1043 function wfTimestampNow() {
1044 # return NOW
1045 return wfTimestamp( TS_MW, time() );
1046 }
1047
1048 /**
1049 * Reference-counted warning suppression
1050 */
1051 function wfSuppressWarnings( $end = false ) {
1052 static $suppressCount = 0;
1053 static $originalLevel = false;
1054
1055 if ( $end ) {
1056 if ( $suppressCount ) {
1057 --$suppressCount;
1058 if ( !$suppressCount ) {
1059 error_reporting( $originalLevel );
1060 }
1061 }
1062 } else {
1063 if ( !$suppressCount ) {
1064 $originalLevel = error_reporting( E_ALL & ~( E_WARNING | E_NOTICE ) );
1065 }
1066 ++$suppressCount;
1067 }
1068 }
1069
1070 /**
1071 * Restore error level to previous value
1072 */
1073 function wfRestoreWarnings() {
1074 wfSuppressWarnings( true );
1075 }
1076
1077 # Autodetect, convert and provide timestamps of various types
1078
1079 /**
1080 * Unix time - the number of seconds since 1970-01-01 00:00:00 UTC
1081 */
1082 define('TS_UNIX', 0);
1083
1084 /**
1085 * MediaWiki concatenated string timestamp (YYYYMMDDHHMMSS)
1086 */
1087 define('TS_MW', 1);
1088
1089 /**
1090 * MySQL DATETIME (YYYY-MM-DD HH:MM:SS)
1091 */
1092 define('TS_DB', 2);
1093
1094 /**
1095 * RFC 2822 format, for E-mail and HTTP headers
1096 */
1097 define('TS_RFC2822', 3);
1098
1099 /**
1100 * An Exif timestamp (YYYY:MM:DD HH:MM:SS)
1101 *
1102 * @link http://exif.org/Exif2-2.PDF The Exif 2.2 spec, see page 28 for the
1103 * DateTime tag and page 36 for the DateTimeOriginal and
1104 * DateTimeDigitized tags.
1105 */
1106 define('TS_EXIF', 4);
1107
1108 /**
1109 * Oracle format time.
1110 */
1111 define('TS_ORACLE', 5);
1112
1113 /**
1114 * @param mixed $outputtype A timestamp in one of the supported formats, the
1115 * function will autodetect which format is supplied
1116 and act accordingly.
1117 * @return string Time in the format specified in $outputtype
1118 */
1119 function wfTimestamp($outputtype=TS_UNIX,$ts=0) {
1120 $uts = 0;
1121 if ($ts==0) {
1122 $uts=time();
1123 } elseif (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
1124 # TS_DB
1125 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
1126 (int)$da[2],(int)$da[3],(int)$da[1]);
1127 } elseif (preg_match("/^(\d{4}):(\d\d):(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
1128 # TS_EXIF
1129 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
1130 (int)$da[2],(int)$da[3],(int)$da[1]);
1131 } elseif (preg_match("/^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/",$ts,$da)) {
1132 # TS_MW
1133 $uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
1134 (int)$da[2],(int)$da[3],(int)$da[1]);
1135 } elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
1136 # TS_UNIX
1137 $uts=$ts;
1138 } elseif (preg_match('/^(\d{1,2})-(...)-(\d\d(\d\d)?) (\d\d)\.(\d\d)\.(\d\d)/', $ts, $da)) {
1139 # TS_ORACLE
1140 $uts = strtotime(preg_replace('/(\d\d)\.(\d\d)\.(\d\d)(\.(\d+))?/', "$1:$2:$3",
1141 str_replace("+00:00", "UTC", $ts)));
1142 } else {
1143 # Bogus value; fall back to the epoch...
1144 wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
1145 $uts = 0;
1146 }
1147
1148
1149 switch($outputtype) {
1150 case TS_UNIX:
1151 return $uts;
1152 case TS_MW:
1153 return gmdate( 'YmdHis', $uts );
1154 case TS_DB:
1155 return gmdate( 'Y-m-d H:i:s', $uts );
1156 // This shouldn't ever be used, but is included for completeness
1157 case TS_EXIF:
1158 return gmdate( 'Y:m:d H:i:s', $uts );
1159 case TS_RFC2822:
1160 return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
1161 case TS_ORACLE:
1162 return gmdate( 'd-M-y h.i.s A', $uts) . ' +00:00';
1163 default:
1164 wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.');
1165 }
1166 }
1167
1168 /**
1169 * Return a formatted timestamp, or null if input is null.
1170 * For dealing with nullable timestamp columns in the database.
1171 * @param int $outputtype
1172 * @param string $ts
1173 * @return string
1174 */
1175 function wfTimestampOrNull( $outputtype = TS_UNIX, $ts = null ) {
1176 if( is_null( $ts ) ) {
1177 return null;
1178 } else {
1179 return wfTimestamp( $outputtype, $ts );
1180 }
1181 }
1182
1183 /**
1184 * Check where as the operating system is Windows
1185 *
1186 * @return bool True if it's windows, False otherwise.
1187 */
1188 function wfIsWindows() {
1189 if (substr(php_uname(), 0, 7) == 'Windows') {
1190 return true;
1191 } else {
1192 return false;
1193 }
1194 }
1195
1196 /**
1197 * Swap two variables
1198 */
1199 function swap( &$x, &$y ) {
1200 $z = $x;
1201 $x = $y;
1202 $y = $z;
1203 }
1204
1205 function wfGetSiteNotice() {
1206 global $wgSiteNotice, $wgTitle, $wgOut;
1207 $fname = 'wfGetSiteNotice';
1208 wfProfileIn( $fname );
1209
1210 $notice = wfMsg( 'sitenotice' );
1211 if( $notice == '&lt;sitenotice&gt;' || $notice == '-' ) {
1212 $notice = '';
1213 }
1214 if( $notice == '' ) {
1215 # We may also need to override a message with eg downtime info
1216 # FIXME: make this work!
1217 $notice = $wgSiteNotice;
1218 }
1219 if($notice != '-' && $notice != '') {
1220 $specialparser = new Parser();
1221 $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false );
1222 $notice = $parserOutput->getText();
1223 }
1224 wfProfileOut( $fname );
1225 return $notice;
1226 }
1227
1228 /**
1229 * Format an XML element with given attributes and, optionally, text content.
1230 * Element and attribute names are assumed to be ready for literal inclusion.
1231 * Strings are assumed to not contain XML-illegal characters; special
1232 * characters (<, >, &) are escaped but illegals are not touched.
1233 *
1234 * @param string $element
1235 * @param array $attribs Name=>value pairs. Values will be escaped.
1236 * @param string $contents NULL to make an open tag only; '' for a contentless closed tag (default)
1237 * @return string
1238 */
1239 function wfElement( $element, $attribs = null, $contents = '') {
1240 $out = '<' . $element;
1241 if( !is_null( $attribs ) ) {
1242 foreach( $attribs as $name => $val ) {
1243 $out .= ' ' . $name . '="' . htmlspecialchars( $val ) . '"';
1244 }
1245 }
1246 if( is_null( $contents ) ) {
1247 $out .= '>';
1248 } else {
1249 if( $contents == '' ) {
1250 $out .= ' />';
1251 } else {
1252 $out .= '>';
1253 $out .= htmlspecialchars( $contents );
1254 $out .= "</$element>";
1255 }
1256 }
1257 return $out;
1258 }
1259
1260 /**
1261 * Format an XML element as with wfElement(), but run text through the
1262 * UtfNormal::cleanUp() validator first to ensure that no invalid UTF-8
1263 * is passed.
1264 *
1265 * @param string $element
1266 * @param array $attribs Name=>value pairs. Values will be escaped.
1267 * @param string $contents NULL to make an open tag only; '' for a contentless closed tag (default)
1268 * @return string
1269 */
1270 function wfElementClean( $element, $attribs = array(), $contents = '') {
1271 if( $attribs ) {
1272 $attribs = array_map( array( 'UtfNormal', 'cleanUp' ), $attribs );
1273 }
1274 if( $contents ) {
1275 $contents = UtfNormal::cleanUp( $contents );
1276 }
1277 return wfElement( $element, $attribs, $contents );
1278 }
1279
1280 // Shortcuts
1281 function wfOpenElement( $element ) { return "<$element>"; }
1282 function wfCloseElement( $element ) { return "</$element>"; }
1283
1284 /**
1285 * Create a namespace selector
1286 *
1287 * @param mixed $selected The namespace which should be selected, default ''
1288 * @param string $allnamespaces Value of a special item denoting all namespaces. Null to not include (default)
1289 * @return Html string containing the namespace selector
1290 */
1291 function &HTMLnamespaceselector($selected = '', $allnamespaces = null) {
1292 global $wgContLang;
1293 $s = "<select name='namespace' class='namespaceselector'>\n\t";
1294 $arr = $wgContLang->getFormattedNamespaces();
1295 if( !is_null($allnamespaces) ) {
1296 $arr = array($allnamespaces => wfMsgHtml('namespacesall')) + $arr;
1297 }
1298 foreach ($arr as $index => $name) {
1299 if ($index < NS_MAIN) continue;
1300
1301 $name = $index !== 0 ? $name : wfMsgHtml('blanknamespace');
1302
1303 if ($index === $selected) {
1304 $s .= wfElement("option",
1305 array("value" => $index, "selected" => "selected"),
1306 $name);
1307 } else {
1308 $s .= wfElement("option", array("value" => $index), $name);
1309 }
1310 }
1311 $s .= "\n</select>\n";
1312 return $s;
1313 }
1314
1315 /** Global singleton instance of MimeMagic. This is initialized on demand,
1316 * please always use the wfGetMimeMagic() function to get the instance.
1317 *
1318 * @private
1319 */
1320 $wgMimeMagic= NULL;
1321
1322 /** Factory functions for the global MimeMagic object.
1323 * This function always returns the same singleton instance of MimeMagic.
1324 * That objects will be instantiated on the first call to this function.
1325 * If needed, the MimeMagic.php file is automatically included by this function.
1326 * @return MimeMagic the global MimeMagic objects.
1327 */
1328 function &wfGetMimeMagic() {
1329 global $wgMimeMagic;
1330
1331 if (!is_null($wgMimeMagic)) {
1332 return $wgMimeMagic;
1333 }
1334
1335 if (!class_exists("MimeMagic")) {
1336 #include on demand
1337 require_once("MimeMagic.php");
1338 }
1339
1340 $wgMimeMagic= new MimeMagic();
1341
1342 return $wgMimeMagic;
1343 }
1344
1345
1346 /**
1347 * Tries to get the system directory for temporary files.
1348 * The TMPDIR, TMP, and TEMP environment variables are checked in sequence,
1349 * and if none are set /tmp is returned as the generic Unix default.
1350 *
1351 * NOTE: When possible, use the tempfile() function to create temporary
1352 * files to avoid race conditions on file creation, etc.
1353 *
1354 * @return string
1355 */
1356 function wfTempDir() {
1357 foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
1358 $tmp = getenv( $var );
1359 if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
1360 return $tmp;
1361 }
1362 }
1363 # Hope this is Unix of some kind!
1364 return '/tmp';
1365 }
1366
1367 /**
1368 * Make directory, and make all parent directories if they don't exist
1369 */
1370 function wfMkdirParents( $fullDir, $mode ) {
1371 $parts = explode( '/', $fullDir );
1372 $path = '';
1373 $success = false;
1374 foreach ( $parts as $dir ) {
1375 $path .= $dir . '/';
1376 if ( !is_dir( $path ) ) {
1377 if ( !mkdir( $path, $mode ) ) {
1378 return false;
1379 }
1380 }
1381 }
1382 return true;
1383 }
1384
1385 /**
1386 * Increment a statistics counter
1387 */
1388 function wfIncrStats( $key ) {
1389 global $wgDBname, $wgMemc;
1390 $key = "$wgDBname:stats:$key";
1391 if ( is_null( $wgMemc->incr( $key ) ) ) {
1392 $wgMemc->add( $key, 1 );
1393 }
1394 }
1395
1396 /**
1397 * @param mixed $nr The number to format
1398 * @param int $acc The number of digits after the decimal point, default 2
1399 * @param bool $round Whether or not to round the value, default true
1400 * @return float
1401 */
1402 function wfPercent( $nr, $acc = 2, $round = true ) {
1403 $ret = sprintf( "%.${acc}f", $nr );
1404 return $round ? round( $ret, $acc ) . '%' : "$ret%";
1405 }
1406
1407 /**
1408 * Encrypt a username/password.
1409 *
1410 * @param string $userid ID of the user
1411 * @param string $password Password of the user
1412 * @return string Hashed password
1413 */
1414 function wfEncryptPassword( $userid, $password ) {
1415 global $wgPasswordSalt;
1416 $p = md5( $password);
1417
1418 if($wgPasswordSalt)
1419 return md5( "{$userid}-{$p}" );
1420 else
1421 return $p;
1422 }
1423
1424 /**
1425 * Appends to second array if $value differs from that in $default
1426 */
1427 function wfAppendToArrayIfNotDefault( $key, $value, $default, &$changed ) {
1428 if ( is_null( $changed ) ) {
1429 wfDebugDieBacktrace('GlobalFunctions::wfAppendToArrayIfNotDefault got null');
1430 }
1431 if ( $default[$key] !== $value ) {
1432 $changed[$key] = $value;
1433 }
1434 }
1435
1436 /**
1437 * Since wfMsg() and co suck, they don't return false if the message key they
1438 * looked up didn't exist but a XHTML string, this function checks for the
1439 * nonexistance of messages by looking at wfMsg() output
1440 *
1441 * @param $msg The message key looked up
1442 * @param $wfMsgOut The output of wfMsg*()
1443 * @return bool
1444 */
1445 function wfEmptyMsg( $msg, $wfMsgOut ) {
1446 return $wfMsgOut === "&lt;$msg&gt;";
1447 }
1448 ?>