From: Brion Vibber Date: Fri, 4 Nov 2005 02:33:50 +0000 (+0000) Subject: * (bug 3877) Render math images into temp directory, then move to hashed X-Git-Tag: 1.6.0~1223 X-Git-Url: https://git.heureux-cyclage.org/?a=commitdiff_plain;h=9d15c14be407121f79c2837633254c7e456df7df;p=lhc%2Fweb%2Fwiklou.git * (bug 3877) Render math images into temp directory, then move to hashed subdir so you can render new math images and have them work --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2b9ae8f92d..cb74739df6 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -202,7 +202,8 @@ fully support the editing toolbar, but was found to be too confusing. new hierarchy on the fly. * (bug 3487) Fix category edit preview with preview-on-bottom * (bug 918) Search index incorrectly joined words at == headings == - +* (bug 3877) Render math images into temp directory, then move to hashed + subdir so you can render new math images and have them work === Caveats === diff --git a/includes/Math.php b/includes/Math.php index 49701d76a0..ef6c603f6d 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -42,15 +42,6 @@ class MathRenderer { if( !$this->_recall() ) { # Ensure that the temp and output directories are available before continuing... - $hashpath = $this->_getHashPath(); - - if( !file_exists( $hashpath ) ) { - if( !@wfMkdirParents( $hashpath, 0755 ) ) { - return $this->_error( 'math_bad_output' ); - } - } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) { - return $this->_error( 'math_bad_output' ); - } if( !file_exists( $wgTmpDirectory ) ) { if( !@mkdir( $wgTmpDirectory ) ) { return $this->_error( 'math_bad_tmpdir' ); @@ -64,7 +55,7 @@ class MathRenderer { } $cmd = $wgTexvc . ' ' . escapeshellarg( $wgTmpDirectory ).' '. - escapeshellarg( $hashpath ).' '. + escapeshellarg( $wgTmpDirectory ).' '. escapeshellarg( $this->tex ).' '. escapeshellarg( $wgInputEncoding ); @@ -127,10 +118,23 @@ class MathRenderer { return $this->_error( 'math_unknown_error' ); } - if( !file_exists( "$hashpath/{$this->hash}.png" ) ) { + if( !file_exists( "$wgTmpDirectory/{$this->hash}.png" ) ) { return $this->_error( 'math_image_error' ); } + $hashpath = $this->_getHashPath(); + if( !file_exists( $hashpath ) ) { + if( !@wfMkdirParents( $hashpath, 0755 ) ) { + return $this->_error( 'math_bad_output' ); + } + } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) { + return $this->_error( 'math_bad_output' ); + } + + if( !rename( "$wgTmpDirectory/{$this->hash}.png", "$hashpath/{$this->hash}.png" ) ) { + return $this->_error( 'math_output_error' ); + } + # Now save it back to the DB: if ( !wfReadOnly() ) { $outmd5_sql = pack('H32', $this->hash); @@ -239,9 +243,11 @@ class MathRenderer { function _getHashPath() { global $wgMathDirectory; - return $wgMathDirectory .'/'. substr($this->hash, 0, 1) + $path = $wgMathDirectory .'/'. substr($this->hash, 0, 1) .'/'. substr($this->hash, 1, 1) .'/'. substr($this->hash, 2, 1); + wfDebug( "TeX: getHashPath, hash is: $this->hash, path is: $path\n" ); + return $path; }