/**
* Compatibility functions
*
- * We more or less support PHP 5.0.x and up.
+ * We support PHP 5.1.x and up.
* Re-implementations of newer functions or functions in non-standard
* PHP extensions may be included here.
*/
/**
* 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__);
}
/**
return wfGetLangObj( !$wgBetterDirectionality );
}
+/**
+ * This is the new function for getting translated interface messages.
+ * See the Message class for documentation how to use them.
+ * The intention is that this function replaces all old wfMsg* functions.
+ * @param $key \string Message key.
+ * Varargs: normal message parameters.
+ * @return \type{Message}
+ * @since 1.17
+ */
+function wfMessage( $key /*...*/) {
+ $params = func_get_args();
+ array_shift( $params );
+ return new Message( $key, $params );
+}
+
/**
* Get a message from anywhere, for the current user language.
*
}
}
-/**
- * This is obsolete, use SquidUpdate::purge()
- * @deprecated
- */
-function wfPurgeSquidServers( $urlArr ) {
- SquidUpdate::purge( $urlArr );
-}
-
/**
* Windows-compatible version of escapeshellarg()
* Windows doesn't recognise single-quotes in the shell, but the escapeshellarg()
# 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;
}
}
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();
*/
define( 'TS_DB2', 8 );
+/**
+ * ISO 8601 basic format with no timezone: 19860209T200000Z
+ *
+ * This is used by ResourceLoader
+ */
+define( 'TS_ISO_8601_BASIC', 9 );
+
/**
* @param $outputtype Mixed: A timestamp in one of the supported formats, the
* function will autodetect which format is supplied and act
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
str_replace( '+00:00', 'UTC', $ts ) ) );
} elseif ( preg_match( '/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
# TS_ISO_8601
+ } elseif ( preg_match( '/^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})(?:\.*\d*)?Z$/', $ts, $da ) ) {
+ #TS_ISO_8601_BASIC
} elseif ( preg_match( '/^(\d{4})\-(\d\d)\-(\d\d) (\d\d):(\d\d):(\d\d)\.*\d*[\+\- ](\d\d)$/', $ts, $da ) ) {
# 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");
return gmdate( 'Y-m-d H:i:s', $uts );
case TS_ISO_8601:
return gmdate( 'Y-m-d\TH:i:s\Z', $uts );
+ case TS_ISO_8601_BASIC:
+ return gmdate( 'Ymd\THis\Z', $uts );
// This shouldn't ever be used, but is included for completeness
case TS_EXIF:
return gmdate( 'Y:m:d H:i:s', $uts );
}
/**
- * 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
* @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';
}
/**
$disabled = false;
if( wfIniGetBool( 'safe_mode' ) ) {
wfDebug( "wfShellExec can't run in safe_mode, PHP's exec functions are too broken.\n" );
- $disabled = true;
+ $disabled = 'safemode';
}
$functions = explode( ',', ini_get( 'disable_functions' ) );
$functions = array_map( 'trim', $functions );
$functions = array_map( 'strtolower', $functions );
if ( in_array( 'passthru', $functions ) ) {
wfDebug( "passthru is in disabled_functions\n" );
- $disabled = true;
+ $disabled = 'passthru';
}
}
if ( $disabled ) {
$retval = 1;
- return 'Unable to run external programs in safe mode.';
+ return $disabled == 'safemode' ?
+ 'Unable to run external programs in safe mode.' :
+ 'Unable to run external programs, passthru() is disabled.';
}
wfInitShellLocale();
/**
* Initialise php session
*/
-function wfSetupSession() {
+function wfSetupSession( $sessionId = false ) {
global $wgSessionsInMemcached, $wgCookiePath, $wgCookieDomain,
$wgCookieSecure, $wgCookieHttpOnly, $wgSessionHandler;
if( $wgSessionsInMemcached ) {
session_set_cookie_params( 0, $wgCookiePath, $wgCookieDomain, $wgCookieSecure );
}
session_cache_limiter( 'private, must-revalidate' );
+ if ( $sessionId ) {
+ session_id( $sessionId );
+ }
wfSuppressWarnings();
session_start();
wfRestoreWarnings();
/**
* Find a file.
* Shortcut for RepoGroup::singleton()->findFile()
- * @param $title Either a string or Title object
+ * @param $title String or Title object
* @param $options Associative array of options:
* time: requested time for an archived image, or false for the
* current version. An image object will be returned which was
* characters before hashing.
*/
function wfGenerateToken( $salt = '' ) {
- $salt = serialize( $salt );
-
- return md5( mt_rand( 0, 0x7fffffff ) . $salt );
+ $salt = serialize( $salt );
+ return md5( mt_rand( 0, 0x7fffffff ) . $salt );
}
/**
* @return PackageRepository
*/
function wfGetRepository() {
- global $wgRepository, $wgRepositoryApiLocation;
+ global $wgRepositoryApiLocation;
+ static $repository = false;
- if ( !isset( $wgRepository ) ) {
- $wgRepository = new DistributionRepository( $wgRepositoryApiLocation );
+ if ( $repository === false ) {
+ $repository = new DistributionRepository( $wgRepositoryApiLocation );
}
- return $wgRepository;
+ return $repository;
}