DB2: Implemented prepared statements for INSERT and UPDATE to allow more than 32k...
[lhc/web/wiklou.git] / includes / GlobalFunctions.php
index ee80461..a3b9a42 100644 (file)
@@ -227,9 +227,10 @@ function wfArrayDiff2_cmp( $a, $b ) {
 /**
  * Seed Mersenne Twister
  * No-op for compatibility; only necessary in PHP < 4.2.0
+ * @deprecated. Remove in 1.18
  */
 function wfSeedRandom() {
-       /* No-op */
+       wfDeprecated(__FUNCTION__);
 }
 
 /**
@@ -1509,7 +1510,11 @@ function wfMerge( $old, $mine, $yours, &$result ) {
 
        # This check may also protect against code injection in
        # case of broken installations.
-       if( !$wgDiff3 || !file_exists( $wgDiff3 ) ) {
+       wfSuppressWarnings();
+       $haveDiff3 = $wgDiff3 && file_exists( $wgDiff3 );
+       wfRestoreWarnings();
+
+       if( !$haveDiff3 ) {
                wfDebug( "diff3 not found\n" );
                return false;
        }
@@ -1579,10 +1584,13 @@ function wfDiff( $before, $after, $params = '-u' ) {
        }
 
        global $wgDiff;
+       wfSuppressWarnings();
+       $haveDiff = $wgDiff && file_exists( $wgDiff );
+       wfRestoreWarnings();
 
        # This check may also protect against code injection in
        # case of broken installations.
-       if( !file_exists( $wgDiff ) ) {
+       if( !$haveDiff ) {
                wfDebug( "diff executable not found\n" );
                $diffs = new Diff( explode( "\n", $before ), explode( "\n", $after ) );
                $format = new UnifiedDiffFormatter();
@@ -1951,7 +1959,7 @@ define( 'TS_DB2', 8 );
 function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
        $uts = 0;
        $da = array();
-       if ( $ts == 0 ) {
+       if ( $ts === 0 ) {
                $uts = time();
        } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)$/D', $ts, $da ) ) {
                # TS_DB
@@ -1972,6 +1980,11 @@ function wfTimestamp( $outputtype = TS_UNIX, $ts = 0 ) {
                # TS_POSTGRES
        } elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d* GMT$/', $ts, $da ) ) {
                # TS_POSTGRES
+       } elseif (preg_match('/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.\d\d\d$/',$ts,$da)) {
+               # TS_DB2
+       } elseif ( preg_match( '/^[A-Z][a-z]{2}, \d\d [A-Z][a-z]{2} \d{4} \d\d:\d\d:\d\d/', $ts ) ) {
+               # TS_RFC2822
+               $uts = strtotime( $ts );
        } else {
                # Bogus value; fall back to the epoch...
                wfDebug("wfTimestamp() fed bogus time value: $outputtype; $ts\n");
@@ -2159,10 +2172,10 @@ function &wfGetMimeMagic() {
 }
 
 /**
- * Tries to get the system directory for temporary files. For PHP >= 5.2.1,
- * we'll use sys_get_temp_dir(). The TMPDIR, TMP, and TEMP environment
- * variables are then checked in sequence, and if none are set /tmp is
- * returned as the generic Unix default.
+ * Tries to get the system directory for temporary files. The TMPDIR, TMP, and
+ * TEMP environment variables are then checked in sequence, and if none are set
+ * try sys_get_temp_dir() for PHP >= 5.2.1. All else fails, return /tmp for Unix
+ * or C:\Windows\Temp for Windows and hope for the best.
  * It is common to call it with tempnam().
  *
  * NOTE: When possible, use instead the tmpfile() function to create
@@ -2171,17 +2184,17 @@ function &wfGetMimeMagic() {
  * @return String
  */
 function wfTempDir() {
-       if( function_exists( 'sys_get_temp_dir' ) ) {
-               return sys_get_temp_dir();
-       }
        foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
                $tmp = getenv( $var );
                if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
                        return $tmp;
                }
        }
-       # Hope this is Unix of some kind!
-       return '/tmp';
+       if( function_exists( 'sys_get_temp_dir' ) ) {
+               return sys_get_temp_dir();
+       }
+       # Usual defaults
+       return wfIsWindows() ? 'C:\Windows\Temp' : '/tmp';
 }
 
 /**
@@ -2454,7 +2467,7 @@ function wfShellExec( $cmd, &$retval = null ) {
                if ( $time > 0 && $mem > 0 ) {
                        $script = "$IP/bin/ulimit4.sh";
                        if ( is_executable( $script ) ) {
-                               $cmd = escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd );
+                               $cmd = '/bin/bash ' . escapeshellarg( $script ) . " $time $mem $filesize " . escapeshellarg( $cmd );
                        }
                }
        } elseif ( php_uname( 's' ) == 'Windows NT' &&
@@ -3454,3 +3467,23 @@ function wfArrayMap( $function, $input ) {
        }
        return $ret;
 }
+
+/**
+ * Returns the PackageRepository object for interaction with the package repository.
+ * 
+ * TODO: Make the repository type also configurable. 
+ * 
+ * @since 1.17
+ * 
+ * @return PackageRepository
+ */
+function wfGetRepository() {
+       global $wgRepositoryApiLocation;
+       static $repository = false;
+       
+       if ( $repository === false ) {
+               $repository = new DistributionRepository( $wgRepositoryApiLocation );
+       }
+       
+       return $repository;
+}