* (bug 153) Adjust thumbnail size calculations to match consistently;
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index 3d0ac19..57bd132 100644 (file)
@@ -201,7 +201,8 @@ function wfDebugLog( $logGroup, $text, $public = true ) {
 function wfLogDBError( $text ) {
        global $wgDBerrorLog;
        if ( $wgDBerrorLog ) {
-               $text = date('D M j G:i:s T Y') . "\t".$text;
+               $host = trim(`hostname`);
+               $text = date('D M j G:i:s T Y') . "\t$host\t".$text;
                error_log( $text, 3, $wgDBerrorLog );
        }
 }
@@ -286,6 +287,15 @@ function wfMsg( $key ) {
        return wfMsgReal( $key, $args, true );
 }
 
+/**
+ * Same as above except doesn't transform the message
+ */
+function wfMsgNoTrans( $key ) {
+       $args = func_get_args();
+       array_shift( $args );
+       return wfMsgReal( $key, $args, true, false );
+}
+
 /**
  * Get a message from anywhere, for the current global language
  * set with $wgLanguageCode.
@@ -319,6 +329,20 @@ function wfMsgForContent( $key ) {
        return wfMsgReal( $key, $args, true, $forcontent );
 }
 
+/**
+ * Same as above except doesn't transform the message
+ */
+function wfMsgForContentNoTrans( $key ) {
+       global $wgForceUIMsgAsContentMsg;
+       $args = func_get_args();
+       array_shift( $args );
+       $forcontent = true;
+       if( is_array( $wgForceUIMsgAsContentMsg ) &&
+               in_array( $key, $wgForceUIMsgAsContentMsg ) )
+               $forcontent = false;
+       return wfMsgReal( $key, $args, true, $forcontent, false );
+}
+
 /**
  * Get a message from the language file, for the UI elements
  */
@@ -346,11 +370,11 @@ function wfMsgNoDBForContent( $key ) {
 /**
  * Really get a message
  */
-function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
+function wfMsgReal( $key, $args, $useDB, $forContent=false, $transform = true ) {
        $fname = 'wfMsgReal';
        wfProfileIn( $fname );
 
-       $message = wfMsgGetKey( $key, $useDB, $forContent );
+       $message = wfMsgGetKey( $key, $useDB, $forContent, $transform );
        $message = wfMsgReplaceArgs( $message, $args );
        wfProfileOut( $fname );
        return $message;
@@ -364,12 +388,17 @@ function wfMsgReal( $key, $args, $useDB, $forContent=false ) {
  * @return string
  * @access private
  */
-function wfMsgGetKey( $key, $useDB, $forContent = false ) {
+function wfMsgGetKey( $key, $useDB, $forContent = false, $transform = true ) {
        global $wgParser, $wgMsgParserOptions;
        global $wgContLang, $wgLanguageCode;
        global $wgMessageCache, $wgLang;
 
+       if ( is_object( $wgMessageCache ) )
+               $transstat = $wgMessageCache->getTransform();
+       
        if( is_object( $wgMessageCache ) ) {
+               if ( ! $transform )
+                       $wgMessageCache->disableTransform();
                $message = $wgMessageCache->get( $key, $useDB, $forContent );
        } else {
                if( $forContent ) {
@@ -388,10 +417,14 @@ function wfMsgGetKey( $key, $useDB, $forContent = false ) {
                wfRestoreWarnings();
                if($message === false)
                        $message = Language::getMessage($key);
-               if(strstr($message, '{{' ) !== false) {
+               if ( $transform && strstr( $message, '{{' ) !== false ) {
                        $message = $wgParser->transformMsg($message, $wgMsgParserOptions);
                }
        }
+
+       if ( is_object( $wgMessageCache ) && ! $transform )
+               $wgMessageCache->setTransform( $transstat );
+       
        return $message;
 }
 
@@ -408,13 +441,17 @@ function wfMsgReplaceArgs( $message, $args ) {
        # Some messages are split with explode("\n", $msg)
        $message = str_replace( "\r", '', $message );
 
-       # Replace arguments
-       if( count( $args ) ) {
-               foreach( $args as $n => $param ) {
+       // Replace arguments
+       if ( count( $args ) )
+               if ( is_array( $args[0] ) )
+                       foreach ( $args[0] as $key => $val )
+                               $message = str_replace( '$' . $key, $val, $message );
+       else {
+               foreach( $args as $n => $param )
                        $replacementKeys['$' . ($n + 1)] = $param;
-               }
                $message = strtr( $message, $replacementKeys );
        }
+       
        return $message;
 }
 
@@ -1579,10 +1616,20 @@ function wfIsWellFormedXmlFragment( $text ) {
 function wfShellExec( $cmd )
 {
        global $IP;
+       
        if ( php_uname( 's' ) == 'Linux' ) {
                $time = ini_get( 'max_execution_time' );
-               $memKB = intval( ini_get( 'memory_limit' ) / 1024 );
-               $cmd = escapeshellarg( "$IP/ulimit.sh" ) . " $time $memKB $cmd";
+               $mem = ini_get( 'memory_limit' );
+               if( preg_match( '/^([0-9]+)[Mm]$/', trim( $mem ), $m ) ) {
+                       $mem = intval( $m[1] * (1024*1024) );
+               }
+               if ( $time > 0 && $mem > 0 ) {
+                       $script = "$IP/bin/ulimit.sh";
+                       if ( is_executable( $script ) ) {
+                               $memKB = intval( $mem / 1024 );
+                               $cmd = escapeshellarg( $script ) . " $time $memKB $cmd";
+                       }
+               }
        }
        return shell_exec( $cmd );
 }