(bug 26130) Revert changes to WebStart.php in r72349, which turn out to have been...
[lhc/web/wiklou.git] / includes / Math.php
index 8cf9b8d..0e136d5 100644 (file)
@@ -37,7 +37,8 @@ class MathRenderer {
 
                if( $this->mode == MW_MATH_SOURCE ) {
                        # No need to render or parse anything more!
-                       return ('$ '.htmlspecialchars( $this->tex ).' $');
+                       # New lines are replaced with spaces, which avoids confusing our parser (bugs 23190, 22818)
+                       return ('<span class="tex">$ ' . str_replace( "\n", " ", htmlspecialchars( $this->tex ) ) . ' $</span>');
                }
                if( $this->tex == '' ) {
                        return; # bug 8372
@@ -55,7 +56,7 @@ class MathRenderer {
                                }
                        }
 
-                       if( function_exists( 'is_executable' ) && !is_executable( $wgTexvc ) ) {
+                       if( !is_executable( $wgTexvc ) ) {
                                return $this->_error( 'math_notexvc' );
                        }
                        $cmd = $wgTexvc . ' ' .
@@ -71,7 +72,7 @@ class MathRenderer {
                        }
 
                        wfDebug( "TeX: $cmd\n" );
-                       $contents = `$cmd`;
+                       $contents = wfShellExec( $cmd );
                        wfDebug( "TeX output:\n $contents\n---\n" );
 
                        if (strlen($contents) == 0) {
@@ -153,7 +154,10 @@ class MathRenderer {
 
                        $hashpath = $this->_getHashPath();
                        if( !file_exists( $hashpath ) ) {
-                               if( !@wfMkdirParents( $hashpath, 0755 ) ) {
+                               wfSuppressWarnings();
+                               $ret = wfMkdirParents( $hashpath, 0755 );
+                               wfRestoreWarnings();
+                               if( !$ret ) {
                                        return $this->_error( 'math_bad_output' );
                                }
                        } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) {
@@ -231,7 +235,9 @@ class MathRenderer {
                        if( file_exists( $filename ) ) {
                                if( filesize( $filename ) == 0 ) {
                                        // Some horrible error corrupted stuff :(
-                                       @unlink( $filename );
+                                       wfSuppressWarnings();
+                                       unlink( $filename );
+                                       wfRestoreWarnings();
                                } else {
                                        return true;
                                }
@@ -241,7 +247,10 @@ class MathRenderer {
                                $hashpath = $this->_getHashPath();
 
                                if( !file_exists( $hashpath ) ) {
-                                       if( !@wfMkdirParents( $hashpath, 0755 ) ) {
+                                       wfSuppressWarnings();
+                                       $ret = wfMkdirParents( $hashpath, 0755 );
+                                       wfRestoreWarnings();
+                                       if( !$ret ) {
                                                return false;
                                        }
                                } elseif( !is_dir( $hashpath ) || !is_writable( $hashpath ) ) {
@@ -323,10 +332,10 @@ class MathRenderer {
                                        .'/'. substr($this->hash, 2, 1);
        }
 
-       public static function renderMath( $tex, $params=array() ) {
-               global $wgUser;
+       public static function renderMath( $tex, $params=array(), ParserOptions $parserOptions = null ) {
                $math = new MathRenderer( $tex, $params );
-               $math->setOutputMode( $wgUser->getOption('math'));
+               if ( $parserOptions )
+                       $math->setOutputMode( $parserOptions->getMath() );
                return $math->render();
        }
 }