From 59c2243cc3928503afe29a890506fb6b6782ae2f Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Wed, 26 Nov 2008 02:28:15 +0000 Subject: [PATCH] Follow-up to r43964 (bug 16440) * Purge newly rendered math images from squids, so any old bad versions get purged out * Don't save entries that were 0-byte files --- includes/Math.php | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/includes/Math.php b/includes/Math.php index 090400e18b..0bc24bc9c0 100644 --- a/includes/Math.php +++ b/includes/Math.php @@ -145,6 +145,10 @@ class MathRenderer { return $this->_error( 'math_image_error' ); } + if( filesize( "$wgTmpDirectory/{$this->hash}.png" ) == 0 ) { + return $this->_error( 'math_image_error' ); + } + $hashpath = $this->_getHashPath(); if( !file_exists( $hashpath ) ) { if( !@wfMkdirParents( $hashpath, 0755 ) ) { @@ -175,7 +179,14 @@ class MathRenderer { ), $fname ); } - + + // If we're replacing an older version of the image, make sure it's current. + global $wgUseSquid; + if ( $wgUseSquid ) { + $urls = array( $this->_mathImageUrl() ); + $u = new SquidUpdate( $urls ); + $u->doUpdate(); + } } return $this->_doRender(); @@ -274,10 +285,7 @@ class MathRenderer { } function _linkToMathImage() { - global $wgMathPath; - $url = "$wgMathPath/" . substr($this->hash, 0, 1) - .'/'. substr($this->hash, 1, 1) .'/'. substr($this->hash, 2, 1) - . "/{$this->hash}.png"; + $url = $this->_mathImageUrl(); return Xml::element( 'img', $this->_attribs( @@ -289,14 +297,24 @@ class MathRenderer { 'src' => $url ) ) ); } + function _mathImageUrl() { + global $wgMathPath; + $dir = $this->_getHashSubPath(); + return "$wgMathPath/$dir/$this->hash"; + } + function _getHashPath() { global $wgMathDirectory; - $path = $wgMathDirectory .'/'. substr($this->hash, 0, 1) - .'/'. substr($this->hash, 1, 1) - .'/'. substr($this->hash, 2, 1); + $path = $wgMathDirectory .'/' . $this->_getHashSubPath(); wfDebug( "TeX: getHashPath, hash is: $this->hash, path is: $path\n" ); return $path; } + + function _getHashSubPath() { + return substr($this->hash, 0, 1) + .'/'. substr($this->hash, 1, 1) + .'/'. substr($this->hash, 2, 1); + } public static function renderMath( $tex, $params=array() ) { global $wgUser; -- 2.20.1