Physikerwelt has submitted this change and it was merged.

Change subject: Demo: getSecure TeX see MathSearch
......................................................................


Demo: getSecure TeX see MathSearch

* Keep the tex output of texvc and treat png and tex file in the same way
* Fix: emtpty tex string on load from database
* new Method: MathTexvc::getSecuredTex
* partially fix: Broken tests

The failing tests are probably related to
Bug: 45194

Change-Id: Iaaf5c7ae018eeb0d014bbc2e06c7ffa7f40e14dc
---
M MathRenderer.php
M MathTexvc.php
M math/render.ml
M tests/MathLaTeXMLTest.php
M tests/MathTexvcTest.php
5 files changed, 52 insertions(+), 19 deletions(-)

Approvals:
  Physikerwelt: Verified; Looks good to me, approved



diff --git a/MathRenderer.php b/MathRenderer.php
index 9a818a7..8d198bb 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -197,6 +197,7 @@
                                if ( $this->tex != "" ) {
                                        wfDebugLog ( "Math", 'WARNING database 
text is '.
                                                var_export($dbtex,true).' 
whereas input text was' . $this->tex );
+                                       $dbtex = $this->tex;
                                }
                        }
                        $this->tex = $dbtex;
diff --git a/MathTexvc.php b/MathTexvc.php
index 493e83a..6d755a0 100644
--- a/MathTexvc.php
+++ b/MathTexvc.php
@@ -17,21 +17,22 @@
  * @author Brion Vibber
  * @author Moritz Schubotz
  */
-define( 'MW_TEXVC_SUCCESS', -1 );
 class MathTexvc extends MathRenderer {
        const CONSERVATIVE = 2;
        const MODERATE = 1;
        const LIBERAL = 0;
+       const MW_TEXVC_SUCCESS = -1;
 
        /**
         * Renders TeX using texvc
         *
         * @return string rendered TeK
         */
-       function render() {
+       public function render() {
                if ( !$this->readCache() ) { // cache miss
+                       wfDebug('Math', 'cache miss. texvc renderer called');
                        $result = $this->callTexvc();
-                       if ( $result != MW_TEXVC_SUCCESS ) {
+                       if ( $result != self::MW_TEXVC_SUCCESS ) {
                                return $result;
                        }
                }
@@ -43,7 +44,7 @@
         *
         * @return string Storage directory
         */
-       function getHashPath() {
+       public function getHashPath() {
                $path = $this->getBackend()->getRootStoragePath() .
                        '/math-render/' . $this->getHashSubPath();
                wfDebugLog("Math", "TeX: getHashPath, hash is: 
{$this->getHash()}, path is: $path\n" );
@@ -55,7 +56,7 @@
         *
         * @return string Relative directory
         */
-       function getHashSubPath() {
+       public function getHashSubPath() {
                return substr( $this->getHash(), 0, 1 )
                        . '/' . substr( $this->getHash(), 1, 1 )
                        . '/' . substr( $this->getHash(), 2, 1 );
@@ -66,10 +67,21 @@
         *
         * @return string image URL
         */
-       function getMathImageUrl() {
+       public function getMathImageUrl() {
                global $wgMathPath;
                $dir = $this->getHashSubPath();
                return "$wgMathPath/$dir/{$this->getHash()}.png";
+       }
+
+       /**
+        * Gets URL for math image
+        *
+        * @return string image URL
+        */
+       public function getMathTeXFileUrl() {
+               global $wgMathPath;
+               $dir = $this->getHashSubPath();
+               return "$wgMathPath/$dir/{$this->getHash()}.tex";
        }
 
        /**
@@ -125,7 +137,7 @@
         *
         * @return int|string MW_TEXVC_SUCCESS or error string
         */
-       function callTexvc() {
+       public function callTexvc() {
                global $wgTexvc, $wgTexvcBackgroundColor, $wgUseSquid, 
$wgMathCheckFiles;
                $tmpDir = wfTempDir();
                if ( !is_executable( $wgTexvc ) ) {
@@ -159,7 +171,8 @@
 
                $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.png" 
);
                $tempFsFile->autocollect(); // destroy file when $tempFsFile 
leaves scope
-
+               $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.tex" 
);
+               $tempFsFile->autocollect(); // destroy file when $tempFsFile 
leaves scope
                $retval = substr( $contents, 0, 1 );
                $errmsg = '';
                if ( ( $retval == 'C' ) || ( $retval == 'M' ) || ( $retval == 
'L' ) ) {
@@ -228,7 +241,12 @@
                ) {
                        return $this->getError( 'math_output_error' );
                }
-               return MW_TEXVC_SUCCESS;
+//             Store the TeX source as well
+               wfDebugLog('Math','Move texfile from 
'."$tmpDir/{$this->getHash()}.tex".' to '."$hashpath/{$this->getHash()}.tex");
+               $backend->quickStore( array(
+                               'src' => "$tmpDir/{$this->getHash()}.tex", 
'dst' => "$hashpath/{$this->getHash()}.tex"
+               ));
+               return self::MW_TEXVC_SUCCESS;
        }
 
        /**
@@ -236,7 +254,7 @@
         *
         * @return FileBackend appropriate file backend
         */
-       function getBackend() {
+       public function getBackend() {
                global $wgMathFileBackend, $wgMathDirectory;
                if ( $wgMathFileBackend ) {
                        return FileBackendGroup::singleton()->get( 
$wgMathFileBackend );
@@ -259,7 +277,7 @@
         *
         * @return string HTML string
         */
-       function doHTMLRender() {
+       public function doHTMLRender() {
                if ( $this->getMode() == MW_MATH_MATHML && $this->getMathml() 
!= '' ) {
                        return Xml::tags( 'math',
                                $this->getAttributes( 'math',
@@ -306,7 +324,7 @@
         *
         * @return boolean true if retrieved, false otherwise
         */
-       function readCache() {
+       public function readCache() {
                global $wgMathCheckFiles;
                if ( $this->readFromDatabase() ) {
                        if ( !$wgMathCheckFiles ) {
@@ -328,4 +346,16 @@
                }
        }
 
+       /**
+        * 
+        * @return string texvc secured tex code
+        */
+       public function getSecureTex(){
+               $backend = $this->getBackend();
+               $src= $this->getHashPath() .'/'.$this->getHash().'.tex';
+               $fullTeXDocumentContent = 
$backend->getFileContents(array('src'=>$src));
+               $parts = explode('$$', $fullTeXDocumentContent);
+               $newtex = $parts[1];
+               return $newtex;
+       }
 }
\ No newline at end of file
diff --git a/math/render.ml b/math/render.ml
index 362b566..67cb389 100644
--- a/math/render.ml
+++ b/math/render.ml
@@ -14,7 +14,7 @@
 exception ExternalCommandFailure of string
 
 let render tmppath finalpath outtex md5 backcolor =
-    let tmpprefix0 = (*(string_of_int (Unix.getpid ()))^"_"^*)md5 in
+    let tmpprefix0 = (string_of_int (Unix.getpid ()))^"_"^md5 in
     let tmpprefix = (tmppath^"/"^tmpprefix0) in
     let unlink_all () =
       begin
@@ -22,7 +22,7 @@
         Sys.remove (tmpprefix ^ ".dvi");
         Sys.remove (tmpprefix ^ ".aux");
         Sys.remove (tmpprefix ^ ".log");
-        (*Sys.remove (tmpprefix ^ ".tex");*)
+        Sys.rename (tmpprefix ^ ".tex") (tmppath^"/"^md5^".tex");
         if Sys.file_exists (tmpprefix ^ ".ps")
         then Sys.remove (tmpprefix ^ ".ps");
       end in
diff --git a/tests/MathLaTeXMLTest.php b/tests/MathLaTeXMLTest.php
index 303fbf3..760e8b5 100644
--- a/tests/MathLaTeXMLTest.php
+++ b/tests/MathLaTeXMLTest.php
@@ -96,10 +96,12 @@
        public function testInsecureResult(){
                $bad_mml='<math href="javascript:alert(1)">CLICKME</math>';
                $bad_mml2='<math> <!-- up to FF 13 --> <maction 
actiontype="statusline#http://google.com"; 
xlink:href="javascript:alert(2)">CLICKME</maction>  <!-- FF 14+ --> <maction 
actiontype="statusline" 
xlink:href="javascript:alert(3)">CLICKME<mtext>http://http://google.com</mtext></maction>
 </math>';
-               $final_mml=MathLaTeXML::embedMathML($bad_mml2);
-               echo(var_dump(MathLaTeXML::isValidMathML($bad_mml))."\n");
-               echo(var_dump(MathLaTeXML::isValidMathML($bad_mml2))."\n");
-               echo($final_mml);
+               //$final_mml=MathLaTeXML::embedMathML($bad_mml);
+               
//$plain_tex=MathRenderer::renderMath($bad_mml,array(),MW_MATH_SOURCE);
+               //echo(var_dump(MathLaTeXML::isValidMathML($bad_mml))."\n");
+               $this->assertFalse(MathLaTeXML::isValidMathML($bad_mml2));
+               //echo($final_mml);
+               //echo($plain_tex);
                
        }
        /**
diff --git a/tests/MathTexvcTest.php b/tests/MathTexvcTest.php
index cb66951..c2c6229 100644
--- a/tests/MathTexvcTest.php
+++ b/tests/MathTexvcTest.php
@@ -74,7 +74,7 @@
                // ... on cache miss, MathTexvc will shell out to texvc:
                $texvc->expects( $this->once() )
                        ->method( 'callTexvc' )
-                       ->will( $this->returnValue( MW_TEXVC_SUCCESS ) );
+                       ->will( $this->returnValue( MathTexvc::MW_TEXVC_SUCCESS 
) );
 
                // ... if texvc succeeds, MathTexvc will generate HTML:
                $texvc->expects( $this->once() )

-- 
To view, visit https://gerrit.wikimedia.org/r/67412
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iaaf5c7ae018eeb0d014bbc2e06c7ffa7f40e14dc
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: LaTeXML
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to