From abcffab3c0d81eb8d0fa699a81d7c64f9cadb900 Mon Sep 17 00:00:00 2001 From: Jens Frank Date: Wed, 2 Nov 2005 23:14:33 +0000 Subject: [PATCH] Change storage architecture in images/math/. Old: images/math/434be915b5fe2e0e63cad907f254dfd5.png New: images/math/4/3/4/434be915b5fe2e0e63cad907f254dfd5.png --- RELEASE-NOTES | 2 ++ includes/Math.php | 48 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 21c5dbf5de..624642f1a8 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -198,6 +198,8 @@ fully support the editing toolbar, but was found to be too confusing. * Fix Parser::unstrip on PHP 5.1.0RC4 * (bug 3852) "Redirected from" link no longer obscured on double-redirects * (bug 3845) Update attribute.php for 1.5 schema +* changed directory hierarchy in images/math/. System upgrades from old to + new hierarchy on the fly. === Caveats === diff --git a/includes/Math.php b/includes/Math.php index d24f30d45d..49701d76a0 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -31,7 +31,7 @@ class MathRenderer { } function render() { - global $wgMathDirectory, $wgTmpDirectory, $wgInputEncoding; + global $wgTmpDirectory, $wgInputEncoding; global $wgTexvc; $fname = 'MathRenderer::render'; @@ -42,11 +42,13 @@ class MathRenderer { if( !$this->_recall() ) { # Ensure that the temp and output directories are available before continuing... - if( !file_exists( $wgMathDirectory ) ) { - if( !@mkdir( $wgMathDirectory ) ) { + $hashpath = $this->_getHashPath(); + + if( !file_exists( $hashpath ) ) { + if( !@wfMkdirParents( $hashpath, 0755 ) ) { return $this->_error( 'math_bad_output' ); } - } elseif( !is_dir( $wgMathDirectory ) || !is_writable( $wgMathDirectory ) ) { + } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) { return $this->_error( 'math_bad_output' ); } if( !file_exists( $wgTmpDirectory ) ) { @@ -62,7 +64,7 @@ class MathRenderer { } $cmd = $wgTexvc . ' ' . escapeshellarg( $wgTmpDirectory ).' '. - escapeshellarg( $wgMathDirectory ).' '. + escapeshellarg( $hashpath ).' '. escapeshellarg( $this->tex ).' '. escapeshellarg( $wgInputEncoding ); @@ -125,7 +127,7 @@ class MathRenderer { return $this->_error( 'math_unknown_error' ); } - if( !file_exists( "$wgMathDirectory/{$this->hash}.png" ) ) { + if( !file_exists( "$hashpath/{$this->hash}.png" ) ) { return $this->_error( 'math_image_error' ); } @@ -181,9 +183,29 @@ class MathRenderer { $this->html = $rpage->math_html; $this->mathml = $rpage->math_mathml; - if( file_exists( "$wgMathDirectory/{$this->hash}.png" ) ) { + if( file_exists( $this->_getHashPath() . "/{$this->hash}.png" ) ) { return true; } + + if( file_exists( $wgMathDirectory . "/{$this->hash}.png" ) ) { + $hashpath = $this->_getHashPath(); + + if( !file_exists( $hashpath ) ) { + if( !@wfMkdirParents( $hashpath, 0755 ) ) { + return false; + } + } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) { + return false; + } + if ( function_exists( "link" ) ) { + return link ( $wgMathDirectory . "/{$this->hash}.png", + $hashpath . "/{$this->hash}.png" ); + } else { + return rename ( $wgMathDirectory . "/{$this->hash}.png", + $hashpath . "/{$this->hash}.png" ); + } + } + } # Missing from the database and/or the render cache @@ -208,11 +230,21 @@ class MathRenderer { function _linkToMathImage() { global $wgMathPath; - $url = htmlspecialchars( "$wgMathPath/{$this->hash}.png" ); + $url = htmlspecialchars( "$wgMathPath/" . substr($this->hash, 0, 1) + .'/'. substr($this->hash, 1, 1) .'/'. substr($this->hash, 2, 1) + . "/{$this->hash}.png" ); $alt = trim(str_replace("\n", ' ', htmlspecialchars( $this->tex ))); return "\"$alt\""; } + function _getHashPath() { + global $wgMathDirectory; + return $wgMathDirectory .'/'. substr($this->hash, 0, 1) + .'/'. substr($this->hash, 1, 1) + .'/'. substr($this->hash, 2, 1); + } + + } function renderMath( $tex ) { -- 2.20.1