Bug 24985 use $wgTmpDirectory when available
We had two way to get a temporary directory: - $wgTempDirectory: more or less stable accross sessions - wfTempDir(): set through environnement variable and could potentially vary from a session to another one thanks to tempnam() This patch makes wfTempDir() to always use the global $wgTempDirectory first when it is available. Thus explicitly overriding tempnam() or any environnement variable such as TMP or TEMP. Hence, people who don't have access to a system wide directory specificed by their environnement (such as /tmp) can specify an alternative straight from the MediaWiki configuration. The patch remove references to $wgTmpDirectory and replace them with calls to wfTempDir(). Make wfTempDir() use $wgTmpDirectory first. The default setting of $wgTmpDirectory was removed in favor of having it initialized through Setup.php by calling wfTempDir. Note: this may also address Bug 36475 - Generating thumbnails does not work when there is no access to /tmp Change-Id: Ifdc79e9c5d95f978025b237a5eeb95fd75092f46
This commit is contained in:
parent
bbffc62c58
commit
99fdc6e838
8 changed files with 41 additions and 23 deletions
|
|
@ -115,6 +115,8 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
|
|||
* (bug 25946) The message on the top of Special:RecentChanges is now displayed
|
||||
in user language instead of content language
|
||||
* (bug 35264) Wrong type used for <ns> in export.xsd
|
||||
* (bug 24985) Use $wgTmpDirectory as the default temp directory so that people
|
||||
who don't have access to /tmp can specify an alternative.
|
||||
|
||||
=== API changes in 1.20 ===
|
||||
* (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
|
||||
|
|
|
|||
|
|
@ -240,7 +240,16 @@ $wgAppleTouchIcon = false;
|
|||
* The local filesystem path to a temporary directory. This is not required to
|
||||
* be web accessible.
|
||||
*
|
||||
* Will default to "{$wgUploadDirectory}/tmp" in Setup.php
|
||||
* When this setting is set to false, its value will be set through a call
|
||||
* to wfTempDir(). See that methods implementation for the actul detection
|
||||
* logic.
|
||||
*
|
||||
* Developers should use the global function wfTempDir() instead of this
|
||||
* variable.
|
||||
*
|
||||
* @see wfTempDir()
|
||||
* @note Default modified to false in v1.20
|
||||
*
|
||||
*/
|
||||
$wgTmpDirectory = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -2610,11 +2610,10 @@ function swap( &$x, &$y ) {
|
|||
}
|
||||
|
||||
/**
|
||||
* 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().
|
||||
* Tries to get the system directory for temporary files. First
|
||||
* $wgTmpDirectory is checked, and then the TMPDIR, TMP, and TEMP
|
||||
* environment variables are then checked in sequence, and if none are
|
||||
* set try sys_get_temp_dir().
|
||||
*
|
||||
* NOTE: When possible, use instead the tmpfile() function to create
|
||||
* temporary files to avoid race conditions on file creation, etc.
|
||||
|
|
@ -2622,8 +2621,15 @@ function swap( &$x, &$y ) {
|
|||
* @return String
|
||||
*/
|
||||
function wfTempDir() {
|
||||
foreach( array( 'TMPDIR', 'TMP', 'TEMP' ) as $var ) {
|
||||
$tmp = getenv( $var );
|
||||
global $wgTmpDirectory;
|
||||
|
||||
if ( $wgTmpDirectory !== false ) {
|
||||
return $wgTmpDirectory;
|
||||
}
|
||||
|
||||
$tmpDir = array_map( "getenv", array( 'TMPDIR', 'TMP', 'TEMP' ) );
|
||||
|
||||
foreach( $tmpDir as $tmp ) {
|
||||
if( $tmp && file_exists( $tmp ) && is_dir( $tmp ) && is_writable( $tmp ) ) {
|
||||
return $tmp;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,9 +77,6 @@ if ( $wgLogo === false ) $wgLogo = "$wgStylePath/common/images/wiki.png";
|
|||
|
||||
if ( $wgUploadPath === false ) $wgUploadPath = "$wgScriptPath/images";
|
||||
if ( $wgUploadDirectory === false ) $wgUploadDirectory = "$IP/images";
|
||||
|
||||
if ( $wgTmpDirectory === false ) $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
|
||||
|
||||
if ( $wgReadOnlyFile === false ) $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
|
||||
if ( $wgFileCacheDirectory === false ) $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
|
||||
if ( $wgDeletedDirectory === false ) $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
|
||||
|
|
@ -400,7 +397,12 @@ if ( !defined( 'MW_COMPILED' ) ) {
|
|||
wfProfileOut( $fname . '-includes' );
|
||||
}
|
||||
|
||||
# Now that GlobalFunctions is loaded, set the default for $wgCanonicalServer
|
||||
# Now that GlobalFunctions is loaded, set defaults that depend
|
||||
# on it.
|
||||
if ( $wgTmpDirectory === false ) {
|
||||
$wgTmpDirectory = wfTempDir();
|
||||
}
|
||||
|
||||
if ( $wgCanonicalServer === false ) {
|
||||
$wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -720,9 +720,9 @@ class DifferenceEngine extends ContextSource {
|
|||
}
|
||||
if ( $wgExternalDiffEngine != 'wikidiff3' && $wgExternalDiffEngine !== false ) {
|
||||
# Diff via the shell
|
||||
global $wgTmpDirectory;
|
||||
$tempName1 = tempnam( $wgTmpDirectory, 'diff_' );
|
||||
$tempName2 = tempnam( $wgTmpDirectory, 'diff_' );
|
||||
$tmpDir = wfTempDir();
|
||||
$tempName1 = tempnam( $tmpDir, 'diff_' );
|
||||
$tempName2 = tempnam( $tmpDir, 'diff_' );
|
||||
|
||||
$tempFile1 = fopen( $tempName1, "w" );
|
||||
if ( !$tempFile1 ) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
||||
/**
|
||||
* This class is used to hold the location and do limited manipulation
|
||||
* of files stored temporarily (usually this will be $wgTmpDirectory)
|
||||
* of files stored temporarily (this will be whatever wfTempDir() returns)
|
||||
*
|
||||
* @ingroup FileBackend
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
* for systems that don't have it.
|
||||
*
|
||||
* On construction you can pass array( 'dir' => '/some/path' ); as a parameter
|
||||
* to override the default DBA files directory (wgTmpDirectory).
|
||||
* to override the default DBA files directory (wfTempDir()).
|
||||
*
|
||||
* @ingroup Cache
|
||||
*/
|
||||
|
|
@ -39,8 +39,7 @@ class DBABagOStuff extends BagOStuff {
|
|||
global $wgDBAhandler;
|
||||
|
||||
if ( !isset( $params['dir'] ) ) {
|
||||
global $wgTmpDirectory;
|
||||
$params['dir'] = $wgTmpDirectory;
|
||||
$params['dir'] = wfTempDir();
|
||||
}
|
||||
|
||||
$this->mFile = $params['dir']."/mw-cache-" . wfWikiID();
|
||||
|
|
|
|||
|
|
@ -388,7 +388,8 @@ class CheckStorage {
|
|||
}
|
||||
|
||||
function restoreText( $revIds, $xml ) {
|
||||
global $wgTmpDirectory, $wgDBname;
|
||||
global $wgDBname;
|
||||
$tmpDir = wfTempDir();
|
||||
|
||||
if ( !count( $revIds ) ) {
|
||||
return;
|
||||
|
|
@ -396,8 +397,8 @@ class CheckStorage {
|
|||
|
||||
print "Restoring text from XML backup...\n";
|
||||
|
||||
$revFileName = "$wgTmpDirectory/broken-revlist-$wgDBname";
|
||||
$filteredXmlFileName = "$wgTmpDirectory/filtered-$wgDBname.xml";
|
||||
$revFileName = "$tmpDir/broken-revlist-$wgDBname";
|
||||
$filteredXmlFileName = "$tmpDir/filtered-$wgDBname.xml";
|
||||
|
||||
// Write revision list
|
||||
if ( !file_put_contents( $revFileName, implode( "\n", $revIds ) ) ) {
|
||||
|
|
@ -481,4 +482,3 @@ class CheckStorage {
|
|||
$this->errors['fixed'][$id] = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue