function wfMungeToUtf8( $string ) {
global $wgInputEncoding; # This is debatable
#$string = iconv($wgInputEncoding, "UTF-8", $string);
- $string = preg_replace ( '/&#([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
+ $string = preg_replace ( '/�*([0-9]+);/e', 'wfUtf8Sequence($1)', $string );
$string = preg_replace ( '/&#x([0-9a-f]+);/ie', 'wfUtf8Sequence(0x$1)', $string );
# Should also do named entities here
return $string;
$forward .= ' from ' . $_SERVER['HTTP_FROM'];
if( $forward )
$forward = "\t(proxied via {$_SERVER['REMOTE_ADDR']}{$forward})";
- if($wgUser->getId() == 0)
+ if( $wgUser->isAnon() )
$forward .= ' anon';
$log = sprintf( "%s\t%04.3f\t%s\n",
gmdate( 'YmdHis' ), $elapsed,
if( is_object( $wgMessageCache ) ) {
$message = $wgMessageCache->get( $key, $useDB, $forContent );
- }
- else {
+ } else {
if( $forContent ) {
$lang = &$wgContLang;
} else {
}
wfSuppressWarnings();
- $message = $lang->getMessage( $key );
+
+ if( is_object( $lang ) ) {
+ $message = $lang->getMessage( $key );
+ } else {
+ $message = '';
+ }
wfRestoreWarnings();
if(!$message)
$message = Language::getMessage($key);
}
$backtrace = debug_backtrace();
foreach( $backtrace as $call ) {
- $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
- $file = $f[count($f)-1];
+ if( isset( $call['file'] ) ) {
+ $f = explode( DIRECTORY_SEPARATOR, $call['file'] );
+ $file = $f[count($f)-1];
+ } else {
+ $file = '-';
+ }
+ if( isset( $call['line'] ) ) {
+ $line = $call['line'];
+ } else {
+ $line = '-';
+ }
if ( $wgCommandLineMode ) {
- $msg .= "$file line {$call['line']} calls ";
+ $msg .= "$file line $line calls ";
} else {
- $msg .= '<li>' . $file . ' line ' . $call['line'] . ' calls ';
+ $msg .= '<li>' . $file . ' line ' . $line . ' calls ';
}
if( !empty( $call['class'] ) ) $msg .= $call['class'] . '::';
$msg .= $call['function'] . '()';
*/
function wfEscapeWikiText( $text ) {
$text = str_replace(
- array( '[', '|', "'", 'ISBN ' , '://' , "\n=", '{{' ),
+ array( '[', '|', '\'', 'ISBN ' , '://' , "\n=", '{{' ),
array( '[', '|', ''', 'ISBN ', '://' , "\n=", '{{' ),
htmlspecialchars($text) );
return $text;
wfEscapeShellArg( $yourtextName );
$handle = popen( $cmd, 'r' );
- if( fgets( $handle ) ){
+ if( fgets( $handle, 1024 ) ){
$conflict = true;
} else {
$conflict = false;
*/
function wfVarDump( $var ) {
global $wgOut;
- $s = str_replace("\n","<br>\n", var_export( $var, true ) . "\n");
+ $s = str_replace("\n","<br />\n", var_export( $var, true ) . "\n");
if ( headers_sent() || !@is_object( $wgOut ) ) {
print $s;
} else {
header( "Status: $code $label" );
$wgOut->sendCacheControl();
- # Don't send content if it's a HEAD request.
- if( $_SERVER['REQUEST_METHOD'] == 'HEAD' ) {
- header( 'Content-type: text/plain' );
- print "$desc\n";
- }
+ header( 'Content-type: text/plain' );
+ print $desc."\n";
}
/**
return wfTimestamp( TS_MW, time() );
}
-/**
- * Sorting hack for MySQL 3, which doesn't use index sorts for DESC
- */
-function wfInvertTimestamp( $ts ) {
- return strtr(
- $ts,
- '0123456789',
- '9876543210'
- );
-}
-
/**
* Reference-counted warning suppression
*/
* @todo document
*/
function wfTimestamp($outputtype=TS_UNIX,$ts=0) {
- if (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
+ if ($ts==0) {
+ $uts=time();
+ } elseif (preg_match("/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/",$ts,$da)) {
# TS_DB
$uts=gmmktime((int)$da[4],(int)$da[5],(int)$da[6],
(int)$da[2],(int)$da[3],(int)$da[1]);
} elseif (preg_match("/^(\d{1,13})$/",$ts,$datearray)) {
# TS_UNIX
$uts=$ts;
+ } else {
+ # Bogus value; fall back to the epoch...
+ wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
+ $uts = 0;
}
- if ($ts==0)
- $uts=time();
+
switch($outputtype) {
- case TS_UNIX:
- return $uts;
- case TS_MW:
- return gmdate( 'YmdHis', $uts );
- case TS_DB:
- return gmdate( 'Y-m-d H:i:s', $uts );
- case TS_RFC2822:
- return gmdate( "D, j M Y H:i:s", $uts ) . ' GMT';
- default:
- return;
+ case TS_UNIX:
+ return $uts;
+ case TS_MW:
+ return gmdate( 'YmdHis', $uts );
+ case TS_DB:
+ return gmdate( 'Y-m-d H:i:s', $uts );
+ case TS_RFC2822:
+ return gmdate( 'D, d M Y H:i:s', $uts ) . ' GMT';
+ default:
+ wfDebugDieBacktrace( 'wfTimestamp() called with illegal output type.');
}
}
/**
* Check where as the operating system is Windows
*
- * @todo document
* @return bool True if it's windows, False otherwise.
*/
function wfIsWindows() {
}
}
+/**
+ * Swap two variables
+ */
+function swap( &$x, &$y ) {
+ $z = $x;
+ $x = $y;
+ $y = $z;
+}
+
+function wfGetSiteNotice() {
+ global $wgSiteNotice, $wgTitle, $wgOut;
+ $fname = 'wfGetSiteNotice';
+ wfProfileIn( $fname );
+
+ $notice = wfMsg( 'sitenotice' );
+ if($notice == '<sitenotice>') $notice = '';
+ # Allow individual wikis to turn it off
+ if ( $notice == '-' ) {
+ $notice = '';
+ } else {
+ if ($notice == '') {
+ $notice = $wgSiteNotice;
+ }
+ if($notice != '-' && $notice != '') {
+ $specialparser = new Parser();
+ $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false );
+ $notice = $parserOutput->getText();
+ }
+ }
+ wfProfileOut( $fname );
+ return $notice;
+}
+
+/**
+ * Format an XML element with given attributes and, optionally, text content.
+ * Element and attribute names are assumed to be ready for literal inclusion.
+ * Strings are assumed to not contain XML-illegal characters; special
+ * characters (<, >, &) are escaped but illegals are not touched.
+ *
+ * @param string $element
+ * @param array $attribs Name=>value pairs. Values will be escaped.
+ * @param bool $contents NULL to make an open tag only; '' for a contentless closed tag (default)
+ * @return string
+ */
+function wfElement( $element, $attribs = array(), $contents = '') {
+ $out = '<' . $element;
+ foreach( $attribs as $name => $val ) {
+ $out .= ' ' . $name . '="' . htmlspecialchars( $val ) . '"';
+ }
+ if( is_null( $contents ) ) {
+ $out .= '>';
+ } else {
+ if( $contents == '' ) {
+ $out .= ' />';
+ } else {
+ $out .= '>';
+ $out .= htmlspecialchars( $contents );
+ $out .= "</$element>";
+ }
+ }
+ return $out;
+}
+
?>