[MediaWiki-commits] [Gerrit] Fine grained options for wgMathDisableTeXFilter - change (mediawiki...Math)

2014-10-10 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Fine grained options for wgMathDisableTeXFilter
..


Fine grained options for wgMathDisableTeXFilter

Add new option to filter only new input.
Now the complete list of possible settings is:
MW_MATH_CHECK_ALWAYS  backwards compatible to false
MW_MATH_CHECK_NEVER   backwards compatible to true
MW_MATH_CHECK_NEW new option

Change-Id: I455b41c8b8d918f4c34f6c115194d227a8394e0a
---
M Math.hooks.php
M Math.php
M MathRenderer.php
M tests/MathRendererTest.php
4 files changed, 144 insertions(+), 38 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/Math.hooks.php b/Math.hooks.php
index e315974..47bdf0c 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -92,7 +92,7 @@
 * @return array
 */
static function mathTagHook( $content, $attributes, $parser ) {
-   global $wgUseMathJax, $wgMathDisableTexFilter;
+   global $wgUseMathJax;
 
if ( trim( $content ) === '' ) { // bug 8372
return '';
@@ -111,14 +111,13 @@
 
$renderer = MathRenderer::getRenderer( $content, $attributes, 
$mode );
 
-   if ( !$wgMathDisableTexFilter ) {
-   $checkResult = $renderer-checkTex();
+   $checkResult = $renderer-checkTex();
 
-   if ( $checkResult !== true ) {
-   // Returns the error message
-   return $renderer-getLastError();
-   }
+   if ( $checkResult !== true ) {
+   // Returns the error message
+   return $renderer-getLastError();
}
+
if ( $renderer-render() ) {
wfDebugLog( Math , Rendering successful. Writing 
output );
$renderedMath = $renderer-getHtmlOutput();
diff --git a/Math.php b/Math.php
index 0314aaa..339810b 100644
--- a/Math.php
+++ b/Math.php
@@ -188,12 +188,29 @@
  * The link to the texvccheck executable
  */
 $wgMathTexvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck';
-/**
- * Option to disable the tex filter. If set to true any LaTeX espression is 
parsed
- * this can be a potential security risk. If set to false only a subset of the 
TeX
- * commands is allowed. See the wikipedia page Help:Math for details.
+
+/**@{
+ * Math check constants
  */
-$wgMathDisableTexFilter = false;
+define( 'MW_MATH_CHECK_ALWAYS', 0 ); /// backwards compatible to false
+define( 'MW_MATH_CHECK_NEVER' , 1 ); /// backwards compatible to true
+define( 'MW_MATH_CHECK_NEW'   , 2 );
+/**@}*/
+/**
+ * Option to disable the TeX security filter:
+ * In general every math object, which is rendered by the math extension has 
its rendering cached in
+ * a database.
+ * MW_MATH_CHECK_ALWAYS: If set to MW_MATH_CHECK_ALWAYS only a subset of the 
TeX commands is allowed.
+ * See the Wikipedia page Help:Math for details about the allowed commands.
+ * MW_MATH_CHECK_NONE: If set to MW_MATH_CHECK_NONE any TeX expression is 
parsed.
+ * This can be a potential security risk.
+ * MW_MATH_CHECK_NEW checks only new equations. If the database does not yet 
contain the given math object,
+ * then it is passed through texvccheck.
+ * Please make sure to truncate the database tables (math, mathoid, 
mathlatexml) when switching from
+ * MW_MATH_CHECK_NONE to MW_MATH_CHECK_NEW. Otherwise, unchecked content 
contained in the database
+ * will be displayed.
+ */
+$wgMathDisableTexFilter = MW_MATH_CHECK_NEW;
 
 /** Stores debug information in the database and provides more detailed debug 
output */
 $wgMathDebug = false;
diff --git a/MathRenderer.php b/MathRenderer.php
index 8e46583..c214a23 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -262,7 +262,7 @@
wfProfileIn( __METHOD__ );
/** @var DatabaseBase */
$dbr = wfGetDB( DB_SLAVE );
-   /** @var ResultWrapper asdf */
+   /** @var ResultWrapper */
$rpage = $dbr-selectRow( $this-getMathTableName(),
$this-dbInArray(),
array( 'math_inputhash' = $this-getInputHash() ),
@@ -600,8 +600,21 @@
return $this-texSecure;
}
 
+   /**
+* @global $wgMathDisableTexFilter
+* @return bool
+*/
public function checkTex() {
-   if ( !$this-texSecure ) {
+   global $wgMathDisableTexFilter;
+   if ( $this-texSecure || (int) $wgMathDisableTexFilter == 
MW_MATH_CHECK_NEVER ) {
+   // equation was already checked or checking is disabled
+   return true;
+   } else {
+   if( (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEW 
){
+   if( 

[MediaWiki-commits] [Gerrit] Fine grained options for wgMathDisableTeXFilter - change (mediawiki...Math)

2014-09-06 Thread Physikerwelt (Code Review)
Physikerwelt has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/158845

Change subject: Fine grained options for wgMathDisableTeXFilter
..

Fine grained options for wgMathDisableTeXFilter

Add new option to filter only new input.
Now the complete list of possible settings is:
MW_MATH_CHECK_ALWAYS  backwards compatible to false
MW_MATH_CHECK_NEVER   backwards compatible to true
MW_MATH_CHECK_NEW new option

Change-Id: I455b41c8b8d918f4c34f6c115194d227a8394e0a
---
M Math.hooks.php
M Math.php
M MathRenderer.php
3 files changed, 33 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/45/158845/3

diff --git a/Math.hooks.php b/Math.hooks.php
index 65819a1..6a9701a 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -111,14 +111,13 @@
 
$renderer = MathRenderer::getRenderer( $content, $attributes, 
$mode );
 
-   if ( !$wgMathDisableTexFilter ) {
-   $checkResult = $renderer-checkTex();
+   $checkResult = $renderer-checkTex();
 
-   if ( $checkResult !== true ) {
-   // Returns the error message
-   return $renderer-getLastError();
-   }
+   if ( $checkResult !== true ) {
+   // Returns the error message
+   return $renderer-getLastError();
}
+
if ( $renderer-render() ) {
wfDebugLog( Math , Rendering successful. Writing 
output );
$renderedMath = $renderer-getHtmlOutput();
diff --git a/Math.php b/Math.php
index c85bdb9..52d41d7 100644
--- a/Math.php
+++ b/Math.php
@@ -188,12 +188,22 @@
  * The link to the texvccheck executable
  */
 $wgMathTexvcCheckExecutable = __DIR__ . '/texvccheck/texvccheck';
-/**
- * Option to disable the tex filter. If set to true any LaTeX espression is 
parsed
- * this can be a potential security risk. If set to false only a subset of the 
TeX
- * commands is allowed. See the wikipedia page Help:Math for details.
+
+/**@{
+ * Math check constants
  */
-$wgMathDisableTexFilter = false;
+define( 'MW_MATH_CHECK_ALWAYS', 0 ); /// backwards compatible to false
+define( 'MW_MATH_CHECK_NEVER' , 1 );   /// backwards compatible to true
+define( 'MW_MATH_CHECK_NEW'   , 2 );
+/**@}*/
+/**
+ * Option to disable the tex filter. If set to MW_MATH_CHECK_NONE any LaTeX 
expression is parsed.
+ * This can be a potential security risk. If set to MW_MATH_CHECK_ALWAYS only 
a subset of the TeX
+ * commands is allowed. See the Wikipedia page Help:Math for details about the 
allowed commands.
+ * MW_MATH_CHECK_NEW checks only new equations
+ *
+ */
+$wgMathDisableTexFilter = MW_MATH_CHECK_ALWAYS;
 
 /** Stores debug information in the database and provides more detailed debug 
output */
 $wgMathDebug = false;
diff --git a/MathRenderer.php b/MathRenderer.php
index 8e46583..21f7fca 100644
--- a/MathRenderer.php
+++ b/MathRenderer.php
@@ -262,7 +262,7 @@
wfProfileIn( __METHOD__ );
/** @var DatabaseBase */
$dbr = wfGetDB( DB_SLAVE );
-   /** @var ResultWrapper asdf */
+   /** @var ResultWrapper */
$rpage = $dbr-selectRow( $this-getMathTableName(),
$this-dbInArray(),
array( 'math_inputhash' = $this-getInputHash() ),
@@ -600,8 +600,18 @@
return $this-texSecure;
}
 
+   /**
+* @global $wgMathDisableTexFilter
+* @return bool
+*/
public function checkTex() {
-   if ( !$this-texSecure ) {
+   global $wgMathDisableTexFilter;
+   if ( !$this-texSecure || (int) $wgMathDisableTexFilter == 
MW_MATH_CHECK_NEVER ) {
+   if( (int) $wgMathDisableTexFilter == MW_MATH_CHECK_NEW 
){
+   if( $this-readFromDatabase() ){
+   return true;
+   }
+   }
$checker = new MathInputCheckTexvc( $this-userInputTex 
);
if ( $checker-isValid() ) {
$this-setTex( $checker-getValidTex() );
@@ -611,9 +621,8 @@
$this-lastError = $checker-getError();
return false;
}
-   } else {
-   return true;
}
+   return true;
}
 
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I455b41c8b8d918f4c34f6c115194d227a8394e0a
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: