* (bug 3877) Render math images into temp directory, then move to hashed
authorBrion Vibber <brion@users.mediawiki.org>
Fri, 4 Nov 2005 02:33:50 +0000 (02:33 +0000)
committerBrion Vibber <brion@users.mediawiki.org>
Fri, 4 Nov 2005 02:33:50 +0000 (02:33 +0000)
  subdir so you can render new math images and have them work

RELEASE-NOTES
includes/Math.php

index 2b9ae8f..cb74739 100644 (file)
@@ -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 ===
 
index 49701d7..ef6c603 100644 (file)
@@ -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;
        }