From: Mark A. Hershberger Date: Sat, 26 May 2012 03:19:55 +0000 (-0400) Subject: Bug 24985 use $wgTmpDirectory when available X-Git-Tag: 1.31.0-rc.0~23334 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/modifier.php?a=commitdiff_plain;h=99fdc6e838d4c7f6a7135a06b58d0bb232ca611c;hp=bbffc62c58972a34ee617ce135e37ec936272341;p=lhc%2Fweb%2Fwiklou.git 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 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index fabc38cbe6..dba0737703 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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 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. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 508add4be8..c2606ce826 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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; diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 4cfd946ab6..ba9bf74556 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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; } diff --git a/includes/Setup.php b/includes/Setup.php index 335d37b431..18a880e560 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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 ); } diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 57729584c7..e624ec2d5a 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -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 ) { diff --git a/includes/filerepo/backend/TempFSFile.php b/includes/filerepo/backend/TempFSFile.php index ae22a1cf0f..ddc640a6e9 100644 --- a/includes/filerepo/backend/TempFSFile.php +++ b/includes/filerepo/backend/TempFSFile.php @@ -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 */ diff --git a/includes/objectcache/DBABagOStuff.php b/includes/objectcache/DBABagOStuff.php index d03771e637..63ad4de53b 100644 --- a/includes/objectcache/DBABagOStuff.php +++ b/includes/objectcache/DBABagOStuff.php @@ -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(); diff --git a/maintenance/storage/checkStorage.php b/maintenance/storage/checkStorage.php index 5887a7554a..29904db21f 100644 --- a/maintenance/storage/checkStorage.php +++ b/maintenance/storage/checkStorage.php @@ -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; } } -