* Fixed unclosed <p> tag
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 9dd3d1e..c0c9e0a 100644 (file)
@@ -79,6 +79,17 @@ if ( !function_exists( 'mb_substr' ) ) {
        }
 }
 
+if( !function_exists( 'floatval' ) ) {
+       /**
+        * First defined in PHP 4.2.0
+        * @param mixed $var;
+        * @return float
+        */
+       function floatval( $var ) {
+               return (float)$var;
+       }
+}
+
 /**
  * Where as we got a random seed
  * @var bool $wgTotalViews
@@ -224,7 +235,15 @@ function wfReadOnly() {
        if ( '' == $wgReadOnlyFile ) {
                return false;
        }
-       return is_file( $wgReadOnlyFile );
+       
+       // Set $wgReadOnly and unset $wgReadOnlyFile, for faster access next time
+       if ( is_file( $wgReadOnlyFile ) ) {
+               $wgReadOnly = true;
+       } else {
+               $wgReadOnly = false;
+       }
+       $wgReadOnlyFile = '';
+       return $wgReadOnly;
 }
 
 
@@ -365,9 +384,7 @@ function wfMsgReplaceArgs( $message, $args ) {
 function wfMsgHtml( $key ) {
        $args = func_get_args();
        array_shift( $args );
-       return wfMsgReplaceArgs(
-               htmlspecialchars( wfMsgGetKey( $key, $args, true ) ),
-               $args );
+       return wfMsgReplaceArgs( htmlspecialchars( wfMsgGetKey( $key, true ) ), $args );
 }
 
 /**
@@ -423,7 +440,8 @@ function wfDebugDieBacktrace( $msg = '' ) {
                        $msg .= "\n<p>Backtrace:</p>\n$backtrace";
                }
         }
-        die( $msg );
+        echo $msg;
+        die( -1 );
 }
 
 function wfBacktrace() {
@@ -634,7 +652,7 @@ function wfEscapeJsString( $string ) {
        $pairs = array(
                "\\" => "\\\\",
                "\"" => "\\\"",
-               "\'" => "\\\'",
+               '\'' => '\\\'',
                "\n" => "\\n",
                "\r" => "\\r",
                
@@ -1108,19 +1126,18 @@ function wfGetSiteNotice() {
        wfProfileIn( $fname );
 
        $notice = wfMsg( 'sitenotice' );
-       if($notice == '&lt;sitenotice&gt;') $notice = '';
-       # Allow individual wikis to turn it off
-       if ( $notice == '-' ) {
+       if( $notice == '&lt;sitenotice&gt;' || $notice == '-' ) {
                $notice = '';
-       } else {
-               if ($notice == '') {
-                       $notice = $wgSiteNotice;
-               }
-               if($notice != '-' && $notice != '') {
-                       $specialparser = new Parser();
-                       $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false );
-                       $notice = $parserOutput->getText();
-               }
+       }
+       if( $notice == '' ) {
+               # We may also need to override a message with eg downtime info
+               # FIXME: make this work!
+               $notice = $wgSiteNotice;
+       }
+       if($notice != '-' && $notice != '') {
+               $specialparser = new Parser();
+               $parserOutput = $specialparser->parse( $notice, $wgTitle, $wgOut->mParserOptions, false );
+               $notice = $parserOutput->getText();
        }
        wfProfileOut( $fname );
        return $notice;
@@ -1248,7 +1265,9 @@ function wfMkdirParents( $fullDir, $mode ) {
        return true;
 }
 
-
+/**
+ * Increment a statistics counter
+ */
 function wfIncrStats( $key ) {
        global $wgDBname, $wgMemc;
        $key = "$wgDBname:stats:$key";
@@ -1257,4 +1276,14 @@ function wfIncrStats( $key ) {
        }
 }
 
+/**
+ * @param mixed $nr The number to format
+ * @param int $acc The number of digits after the decimal point, default 2
+ * @param bool $round Whether or not to round the value, default true
+ * @return float
+ */
+function percent( $nr, $acc = 2, $round = true ) {
+       $ret = sprintf( "%.${acc}f", $nr );
+       return $round ? round( $ret, $acc ) . '%' : "$ret%";
+}
 ?>