Physikerwelt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/60882
Change subject: introduce setter and getter
......................................................................
introduce setter and getter
introduce getter and setter for the MathRenderer
in preperation for determining if a value was changed and has
to be cached
Change-Id: Ica15f77d96453d30edd3a117c7185c694ad3691e
---
M MathMathJax.php
M MathRenderer.php
M MathSource.php
M MathTexvc.php
M tests/MathDatabaseTest.php
5 files changed, 153 insertions(+), 60 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math
refs/changes/82/60882/1
diff --git a/MathMathJax.php b/MathMathJax.php
index e0daa5d..2b21318 100644
--- a/MathMathJax.php
+++ b/MathMathJax.php
@@ -30,7 +30,7 @@
'dir' => 'ltr'
)
),
- '$ ' . str_replace( "\n", " ", $this->tex ) . ' $'
+ '$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
);
}
}
diff --git a/MathRenderer.php b/MathRenderer.php
index a504ee3..e346cd6 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -9,11 +9,11 @@
*/
/**
- * Abstract base class with static methods for rendering the <math> tags using
different technologies.
- * This static methods create a new istance of the extending classes and
render the math tags based on the
- * mode setting of the user.
- * Furthermore this class handles the caching of the rendered output and
provides debug information,
- * if run in mathdebug mode.
+ * Abstract base class with static methods for rendering the <math> tags using
different technologies.
+ * This static methods create a new istance of the extending classes and
render the math tags based on the
+ * mode setting of the user.
+ * Furthermore this class handles the caching of the rendered output and
provides debug information,
+ * if run in mathdebug mode.
*
* @author Tomasz Wegrzanowski
* @author Brion Vibber
@@ -26,15 +26,16 @@
*/
var $mode = MW_MATH_PNG;
var $tex = '';
- /**
- * is calculated by texvc.
- * @var string
- */
+ /**
+ * is calculated by texvc.
+ * @var string
+ */
var $hash = '';
var $html = '';
var $mathml = '';
var $conservativeness = 0;
var $params = '';
+ var $changed = false;
protected $recall;
/**
@@ -85,21 +86,21 @@
default:
$renderer = new MathTexvc( $tex, $params );
}
- wfDebugLog ( "Math", 'start rendering $' . $renderer->tex . '$'
);
+ wfDebugLog ( "Math", 'start rendering $' . $renderer->tex . '$'
);
return $renderer;
}
/**
- * Performs the rendering and returns the rendered element that needs
to be embedded.
+ * Performs the rendering and returns the rendered element that needs
to be embedded.
*
* @return string of rendered HTML
*/
- abstract public function render();
-
+ abstract public function render();
+
/**
- * texvc error messages
- * TODO: update to MathML
+ * texvc error messages
+ * TODO: update to MathML
* Returns an internationalized HTML error string
*
* @param string $msg message key for specific error
@@ -159,13 +160,13 @@
}
/**
- * Writes rendering entry to database.
- *
- * WARNING: Use writeCache() instead of this method to be sure that all
- * renderer specific (such as squid caching) are taken into account.
- * This function stores the values that are currently present in the
class to the database even if they are empty.
- *
- * This function can be seen as protected function.
+ * Writes rendering entry to database.
+ *
+ * WARNING: Use writeCache() instead of this method to be sure that all
+ * renderer specific (such as squid caching) are taken into account.
+ * This function stores the values that are currently present in the
class to the database even if they are empty.
+ *
+ * This function can be seen as protected function.
*/
public function writeToDatabase() {
# Now save it back to the DB:
@@ -229,4 +230,96 @@
public function getTex() {
return $this->tex;
}
+ /**
+ * @return int
+ */
+ public function getMode() {
+ return $this->mode;
+ }
+
+
+ /**
+ * @param string $tex
+ */
+ public function setTex( $tex ) {
+ $this->changed = true;
+ $this->tex = $tex;
+ }
+
+ /**
+ * @return string hash
+ */
+ public function getHash() {
+ return $this->hash;
+ }
+
+ /**
+ * @param string $hash
+ */
+ public function setHash( $hash ) {
+ $this->changed = true;
+ $this->hash = $hash;
+ }
+
+ /**
+ * Returns the html-representation of the mathematical formula.
+ * @return string
+ */
+ public function getHtml() {
+ return $this->html;
+ }
+
+ /**
+ * @param string $html
+ */
+ public function setHtml( $html ) {
+ $this->changed = true;
+ $this->html = $html;
+ }
+
+ /**
+ * @return string
+ */
+ public function getMathml() {
+ return $this->mathml;
+ }
+
+ /**
+ * @param string $mathml
+ */
+ public function setMathml( $mathml ) {
+ $this->changed = true;
+ $this->mathml = $mathml;
+ }
+
+ /**
+ * @return int
+ */
+ public function getConservativeness() {
+ return $this->conservativeness;
+ }
+
+ /**
+ * @param int $conservativeness
+ */
+ public function setConservativeness( $conservativeness ) {
+ $this->changed = true;
+ $this->conservativeness = $conservativeness;
+ }
+
+ /**
+ * @return array()
+ */
+ public function getParams() {
+ return $this->params;
+ }
+
+ /**
+ * @param array() $params
+ */
+ public function setParams( $params ) {
+ $this->params = $params;
+ }
+
+
}
diff --git a/MathSource.php b/MathSource.php
index ebc6ffd..ceecd45 100644
--- a/MathSource.php
+++ b/MathSource.php
@@ -35,7 +35,7 @@
'dir' => 'ltr'
)
),
- '$ ' . str_replace( "\n", " ", $this->tex ) . ' $'
+ '$ ' . str_replace( "\n", " ", $this->getTex() ) . ' $'
);
}
diff --git a/MathTexvc.php b/MathTexvc.php
index 9fc8e7e..d9e2477 100644
--- a/MathTexvc.php
+++ b/MathTexvc.php
@@ -46,7 +46,7 @@
function getHashPath() {
$path = $this->getBackend()->getRootStoragePath() .
'/math-render/' . $this->getHashSubPath();
- wfDebug( "TeX: getHashPath, hash is: $this->hash, path is:
$path\n" );
+ wfDebugLog("Math", "TeX: getHashPath, hash is:
{$this->getHash()}, path is: $path\n" );
return $path;
}
@@ -56,9 +56,9 @@
* @return string Relative directory
*/
function getHashSubPath() {
- return substr( $this->hash, 0, 1 )
- . '/' . substr( $this->hash, 1, 1 )
- . '/' . substr( $this->hash, 2, 1 );
+ return substr( $this->getHash(), 0, 1 )
+ . '/' . substr( $this->getHash(), 1, 1 )
+ . '/' . substr( $this->getHash(), 2, 1 );
}
/**
@@ -69,7 +69,7 @@
function getMathImageUrl() {
global $wgMathPath;
$dir = $this->getHashSubPath();
- return "$wgMathPath/$dir/{$this->hash}.png";
+ return "$wgMathPath/$dir/{$this->getHash()}.png";
}
/**
@@ -111,7 +111,7 @@
$cmd = $wgTexvc . ' ' .
$escapedTmpDir . ' ' .
$escapedTmpDir . ' ' .
- wfEscapeShellArg( $this->tex ) . ' ' .
+ wfEscapeShellArg( $this->getTex() ) . ' ' .
wfEscapeShellArg( 'UTF-8' ) . ' ' .
wfEscapeShellArg( $wgTexvcBackgroundColor );
@@ -131,43 +131,43 @@
}
}
- $tempFsFile = new TempFSFile( "$tmpDir/{$this->hash}.png" );
+ $tempFsFile = new TempFSFile( "$tmpDir/{$this->getHash()}.png"
);
$tempFsFile->autocollect(); // destroy file when $tempFsFile
leaves scope
$retval = substr( $contents, 0, 1 );
$errmsg = '';
if ( ( $retval == 'C' ) || ( $retval == 'M' ) || ( $retval ==
'L' ) ) {
if ( $retval == 'C' ) {
- $this->conservativeness = self::CONSERVATIVE;
+ $this->setConservativeness( self::CONSERVATIVE
);
} elseif ( $retval == 'M' ) {
- $this->conservativeness = self::MODERATE;
+ $this->setConservativeness( self::MODERATE );
} else {
- $this->conservativeness = self::LIBERAL;
+ $this->setConservativeness( self::LIBERAL );
}
$outdata = substr( $contents, 33 );
$i = strpos( $outdata, "\000" );
- $this->html = substr( $outdata, 0, $i );
- $this->mathml = substr( $outdata, $i + 1 );
+ $this->setHtml( substr( $outdata, 0, $i ) );
+ $this->setMathml( substr( $outdata, $i + 1 ) );
} elseif ( ( $retval == 'c' ) || ( $retval == 'm' ) || (
$retval == 'l' ) ) {
- $this->html = substr( $contents, 33 );
+ $this->setHtml( substr( $contents, 33 ) );
if ( $retval == 'c' ) {
- $this->conservativeness = self::CONSERVATIVE;
+ $this->setConservativeness( self::CONSERVATIVE
) ;
} elseif ( $retval == 'm' ) {
- $this->conservativeness = self::MODERATE;
+ $this->setConservativeness( self::MODERATE );
} else {
- $this->conservativeness = self::LIBERAL;
+ $this->setConservativeness( self::LIBERAL );
}
- $this->mathml = null;
+ $this->setMathml( null );
} elseif ( $retval == 'X' ) {
- $this->html = null;
- $this->mathml = substr( $contents, 33 );
- $this->conservativeness = self::LIBERAL;
+ $this->setHtml( null );
+ $this->setMathml( substr( $contents, 33 ) );
+ $this->setConservativeness( self::LIBERAL );
} elseif ( $retval == '+' ) {
- $this->html = null;
- $this->mathml = null;
- $this->conservativeness = self::LIBERAL;
+ $this->setHtml( null );
+ $this->setMathml( null );
+ $this->setConservativeness( self::LIBERAL );
} else {
$errbit = htmlspecialchars( substr( $contents, 1 ) );
switch( $retval ) {
@@ -186,18 +186,18 @@
}
if ( !$errmsg ) {
- $this->hash = substr( $contents, 1, 32 );
+ $this->setHash( substr( $contents, 1, 32 ) );
}
wfRunHooks( 'MathAfterTexvc', array( &$this, &$errmsg ) );
if ( $errmsg ) {
return $errmsg;
- } elseif ( !preg_match( "/^[a-f0-9]{32}$/", $this->hash ) ) {
+ } elseif ( !preg_match( "/^[a-f0-9]{32}$/", $this->getHash() )
) {
return $this->getError( 'math_unknown_error' );
- } elseif ( !file_exists( "$tmpDir/{$this->hash}.png" ) ) {
+ } elseif ( !file_exists( "$tmpDir/{$this->getHash()}.png" ) ) {
return $this->getError( 'math_image_error' );
- } elseif ( filesize( "$tmpDir/{$this->hash}.png" ) == 0 ) {
+ } elseif ( filesize( "$tmpDir/{$this->getHash()}.png" ) == 0 ) {
return $this->getError( 'math_image_error' );
}
@@ -210,7 +210,7 @@
}
// Store the file at the final storage path...
if ( !$backend->quickStore( array(
- 'src' => "$tmpDir/{$this->hash}.png", 'dst' =>
"$hashpath/{$this->hash}.png"
+ 'src' => "$tmpDir/{$this->getHash()}.png", 'dst' =>
"$hashpath/{$this->getHash()}.png"
) )->isOK()
) {
return $this->getError( 'math_output_error' );
@@ -247,15 +247,15 @@
* @return string HTML string
*/
function doHTMLRender() {
- if ( $this->mode == MW_MATH_MATHML && $this->mathml != '' ) {
+ if ( $this->getMode() == MW_MATH_MATHML && $this->getMathml()
!= '' ) {
return Xml::tags( 'math',
$this->getAttributes( 'math',
array( 'xmlns' =>
'http://www.w3.org/1998/Math/MathML' ) ),
$this->mathml );
}
- if ( ( $this->mode == MW_MATH_PNG ) || ( $this->html == '' ) ||
- ( ( $this->mode == MW_MATH_SIMPLE ) && (
$this->conservativeness != self::CONSERVATIVE ) ) ||
- ( ( $this->mode == MW_MATH_MODERN || $this->mode ==
MW_MATH_MATHML ) && ( $this->conservativeness == self::LIBERAL ) )
+ if ( ( $this->getMode() == MW_MATH_PNG ) || ( $this->getHtml()
== '' ) ||
+ ( ( $this->getMode() == MW_MATH_SIMPLE ) && (
$this->getConservativeness() != self::CONSERVATIVE ) ) ||
+ ( ( $this->getMode() == MW_MATH_MODERN ||
$this->getMode() == MW_MATH_MATHML ) && ( $this->getConservativeness() ==
self::LIBERAL ) )
)
{
return $this->getMathImageHTML();
@@ -300,7 +300,7 @@
// Short-circuit the file existence & migration
checks
return true;
}
- $filename = $this->getHashPath() .
"/{$this->hash}.png"; // final storage path
+ $filename = $this->getHashPath() .
"/{$this->getHash()}.png"; // final storage path
$backend = $this->getBackend();
if ( $backend->fileExists( array( 'src' => $filename )
) ) {
if ( $backend->getFileSize( array( 'src' =>
$filename ) ) == 0 ) {
diff --git a/tests/MathDatabaseTest.php b/tests/MathDatabaseTest.php
index 9014896..7ba07bb 100644
--- a/tests/MathDatabaseTest.php
+++ b/tests/MathDatabaseTest.php
@@ -51,9 +51,9 @@
*/
public function setValues() {
// set some values
- $this->renderer->tex = self::SOME_TEX ;
- $this->renderer->html = self::SOME_HTML;
- $this->renderer->mathml = self::SOME_MATHML;
+ $this->renderer->SetTex( self::SOME_TEX );
+ $this->renderer->SetHtml( self::SOME_HTML );
+ $this->renderer->SetMathml( self::SOME_MATHML );
}
/**
* Checks database access. Writes an etry and reads it back.
--
To view, visit https://gerrit.wikimedia.org/r/60882
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica15f77d96453d30edd3a117c7185c694ad3691e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits