jenkins-bot has submitted this change and it was merged.

Change subject: Minor clean up, optimisations and documentation corrections
......................................................................


Minor clean up, optimisations and documentation corrections

* Handle-error-first approach for consistent function body
  termination at the root with the main intend, and less indention.

* __DIR__ instead of dirname( __FILE__ )

* Single quotes.

* Correct pickHost documentation: wgMathMathMLUrl is not an array,
  and is not used in this method, that's at a different level
  of abstraction (via the constructor).

* White spacing.

* require_once is not a function.

Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
---
M Math.hooks.php
M Math.php
M MathMathML.php
M maintenance/MathGenerateTests.php
M tests/MathCoverageTest.php
5 files changed, 59 insertions(+), 57 deletions(-)

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



diff --git a/Math.hooks.php b/Math.hooks.php
index c71c959..c9e6482 100644
--- a/Math.hooks.php
+++ b/Math.hooks.php
@@ -224,32 +224,32 @@
 
                $type = $updater->getDB()->getType();
 
-               if ( in_array( $type, $map ) ) {
-                       $sql = dirname( __FILE__ ) . '/db/math.' . $type . 
'.sql';
-                       $updater->addExtensionTable( 'math', $sql );
-                       if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
-                               if ( in_array( $type, array( 'mysql', 'sqlite', 
'postgres' ) ) ) {
-                                       $sql = dirname( __FILE__ ) . 
'/db/mathlatexml.' . $type . '.sql';
-                                       $updater->addExtensionTable( 
'mathlatexml', $sql );
-                                       if ( $type == 'mysql' ){
-                                               $sql = dirname( __FILE__ ) . 
'/db/patches/mathlatexml.mathml-length-adjustment.mysql.sql';
-                                               $updater->modifyExtensionField( 
'mathlatexml', 'math_mathml', $sql );
-                                       }
-                               } else {
-                                       throw new Exception( "Math extension 
does not currently support $type database for LaTeXML." );
-                               }
-                       }
-                       if ( in_array( MW_MATH_MATHML, $wgMathValidModes ) ) {
-                               if ( in_array( $type, array( 'mysql', 'sqlite', 
'postgres' ) ) ) {
-                                       $sql = dirname( __FILE__ ) . 
'/db/mathoid.' . $type . '.sql';
-                                       $updater->addExtensionTable( 'mathoid', 
$sql );
-                               } else {
-                                       throw new Exception( "Math extension 
does not currently support $type database for Mathoid." );
-                               }
-                       }
-               } else {
+               if ( !in_array( $type, $map ) ) {
                        throw new Exception( "Math extension does not currently 
support $type database." );
                }
+               $sql = __DIR__ . '/db/math.' . $type . '.sql';
+               $updater->addExtensionTable( 'math', $sql );
+               if ( in_array( MW_MATH_LATEXML, $wgMathValidModes ) ) {
+                       if ( in_array( $type, array( 'mysql', 'sqlite', 
'postgres' ) ) ) {
+                               $sql = __DIR__ . '/db/mathlatexml.' . $type . 
'.sql';
+                               $updater->addExtensionTable( 'mathlatexml', 
$sql );
+                               if ( $type == 'mysql' ){
+                                       $sql = __DIR__ . 
'/db/patches/mathlatexml.mathml-length-adjustment.mysql.sql';
+                                       $updater->modifyExtensionField( 
'mathlatexml', 'math_mathml', $sql );
+                               }
+                       } else {
+                               throw new Exception( "Math extension does not 
currently support $type database for LaTeXML." );
+                       }
+               }
+               if ( in_array( MW_MATH_MATHML, $wgMathValidModes ) ) {
+                       if ( in_array( $type, array( 'mysql', 'sqlite', 
'postgres' ) ) ) {
+                               $sql = __DIR__ . '/db/mathoid.' . $type . 
'.sql';
+                               $updater->addExtensionTable( 'mathoid', $sql );
+                       } else {
+                               throw new Exception( "Math extension does not 
currently support $type database for Mathoid." );
+                       }
+               }
+
                return true;
        }
 
diff --git a/Math.php b/Math.php
index ad4390b..abd198d 100644
--- a/Math.php
+++ b/Math.php
@@ -118,8 +118,11 @@
 
 /**
  * The url of the mathoid server.
- * see http://www.formulasearchengine.com/mathoid
- * TODO: Move documentation to WMF
+ *
+ * Documentation: http://www.formulasearchengine.com/mathoid
+ * Example value: http://mathoid.example.org:10042
+ *
+ * @todo Move documentation to mediawiki.org
  */
 $wgMathMathMLUrl = 'http://mathoid.testme.wmflabs.org';
 
diff --git a/MathMathML.php b/MathMathML.php
index 6707059..8feae0b 100644
--- a/MathMathML.php
+++ b/MathMathML.php
@@ -13,6 +13,7 @@
        protected $defaultAllowedRootElements = array( 'math' );
        protected $allowedRootElements = '';
        protected $hosts;
+
        /** @var boolean if false MathML output is not validated */
        private $XMLValidation = true;
        protected $inputType = 'tex';
@@ -20,16 +21,14 @@
        /**
         * @param string $inputType
         */
-       public function setInputType($inputType)
-       {
+       public function setInputType($inputType) {
                $this->inputType = $inputType;
        }
 
        /**
         * @return string
         */
-       public function getInputType()
-       {
+       public function getInputType() {
                return $this->inputType;
        }
 
@@ -101,26 +100,26 @@
         */
        private function renderingRequired() {
                if ( $this->isPurge() ) {
-                       wfDebugLog( "Math", "Rerendering was requested." );
+                       wfDebugLog( 'Math', 'Rerendering was requested.' );
                        return true;
                } else {
                        $dbres = $this->isInDatabase();
                        if ( $dbres ) {
                                if ( $this->isValidMathML( $this->getMathml() ) 
) {
-                                       wfDebugLog( "Math", "Valid MathML entry 
found in database." );
+                                       wfDebugLog( 'Math', 'Valid MathML entry 
found in database.' );
                                        if ( $this->getSvg() ) {
-                                               wfDebugLog( "Math", 
"SVG-fallback found in database." );
+                                               wfDebugLog( 'Math', 
'SVG-fallback found in database.' );
                                                return false;
                                        } else {
-                                               wfDebugLog( "Math", 
"SVG-fallback missing." );
+                                               wfDebugLog( 'Math', 
'SVG-fallback missing.' );
                                                return true;
                                        }
                                } else {
-                                       wfDebugLog( "Math", "Malformatted entry 
found in database" );
+                                       wfDebugLog( 'Math', 'Malformatted entry 
found in database' );
                                        return true;
                                }
                        } else {
-                               wfDebugLog( "Math", "No entry found in 
database." );
+                               wfDebugLog( 'Math', 'No entry found in 
database.' );
                                return true;
                        }
                }
@@ -166,14 +165,14 @@
                        if ( $status->hasMessage( 'http-timed-out' ) ) {
                                $error = $this->getError( 'math_timeout', 
$this->getModeStr(), $host );
                                $res = false;
-                               wfDebugLog( "Math", "\nTimeout:"
+                               wfDebugLog( 'Math', "\nTimeout:"
                                        . var_export( array( 'post' => $post, 
'host' => $host
                                        , 'timeout' => $wgMathLaTeXMLTimeout ), 
true ) . "\n\n" );
                        } else {
                                // for any other unkonwn http error
                                $errormsg = $status->getHtml();
                                $error = $this->getError( 
'math_invalidresponse', $this->getModeStr(), $host, $errormsg, 
$this->getModeStr( MW_MATH_MATHML ) );
-                               wfDebugLog( "Math", "\nNoResponse:"
+                               wfDebugLog( 'Math', "\nNoResponse:"
                                        . var_export( array( 'post' => $post, 
'host' => $host
                                        , 'errormsg' => $errormsg ), true ) . 
"\n\n" );
                        }
@@ -183,9 +182,10 @@
        }
 
        /**
-        * Picks a MathML daemon.
-        * If more than one demon are available one is chosen from the
-        * $wgMathMathMLUrl array.
+        * Return a MathML daemon host.
+        *
+        * If more than one demon is available, one is chosen at random.
+        *
         * @return string
         */
        protected function pickHost() {
@@ -194,7 +194,7 @@
                } else {
                        $host = $this->hosts;
                }
-               wfDebugLog( "Math", "picking host " . $host );
+               wfDebugLog( 'Math', 'picking host ' . $host );
                return $host;
        }
 
@@ -217,7 +217,7 @@
                 $out = 'type=tex&q=' . rawurlencode( $input );
             }
                }
-               wfDebugLog( "Math", 'Get post data: ' . $out );
+               wfDebugLog( 'Math', 'Get post data: ' . $out );
                return $out;
        }
 
@@ -269,7 +269,7 @@
                                                $log = wfMessage( 
'math_unknown_error' )->inContentLanguage()->escaped();
                                        }
                                        $this->lastError = $this->getError( 
'math_mathoid_error', $host, $log );
-                                       wfDebugLog( 'Math', "Mathoid conversion 
error:"
+                                       wfDebugLog( 'Math', 'Mathoid conversion 
error:'
                                                . var_export( array( 'post' => 
$post, 'host' => $host
                                                , 'result'                  => 
$res ), true ) . "\n\n" );
                                        return false;
@@ -307,7 +307,7 @@
                }
                $xmlObject = new XmlTypeCheck( $XML, null, false );
                if ( !$xmlObject->wellFormed ) {
-                       wfDebugLog( "Math", "XML validation error:\n " . 
var_export( $XML, true ) . "\n" );
+                       wfDebugLog( 'Math', "XML validation error:\n " . 
var_export( $XML, true ) . "\n" );
                } else {
                        $name = $xmlObject->getRootElement();
                        $elementSplit = explode( ':', $name );
@@ -319,7 +319,7 @@
                        if ( in_array( $localName , 
$this->getAllowedRootElements() ) ) {
                                $out = true;
                        } else {
-                               wfDebugLog( "Math", "got wrong root element : 
$name" );
+                               wfDebugLog( 'Math', "got wrong root element : 
$name" );
                        }
                }
                return $out;
@@ -345,7 +345,7 @@
         */
        public function correctSvgStyle( $svg, &$style ) {
                if ( preg_match( '/style="([^"]*)"/', $svg, $styles ) ) {
-                       $style .= " ".$styles[1]; // merge styles
+                       $style .= ' ' . $styles[1]; // merge styles
                        if ( $this->getMathStyle() === MW_MATHSTYLE_DISPLAY ) {
                                // TODO: Improve style cleaning
                                $style = preg_replace( 
'/margin\-(left|right)\:\s*\d+(\%|in|cm|mm|em|ex|pt|pc|px)\;/', '', $style );
@@ -356,10 +356,10 @@
                // a SVGReader from a string that represents the SVG
                // content
                if ( preg_match( "/height=\"(.*?)\"/" , $this->getSvg(), 
$matches ) ) {
-                       $style .= "height: " . $matches[1] . "; ";
+                       $style .= 'height: ' . $matches[1] . '; ';
                }
                if ( preg_match( "/width=\"(.*?)\"/", $this->getSvg(), $matches 
) ) {
-                       $style .= "width: " . $matches[1] . ";";
+                       $style .= 'width: ' . $matches[1] . ';';
                }
        }
 
@@ -399,7 +399,7 @@
         * @return string the class name
         */
        private function getClassName( $fallback = false ) {
-               $class = "mwe-math-";
+               $class = 'mwe-math-';
                if ( $fallback ) {
                        $class .= 'fallback-image-';
                } else {
diff --git a/maintenance/MathGenerateTests.php 
b/maintenance/MathGenerateTests.php
index e942601..0724e75 100644
--- a/maintenance/MathGenerateTests.php
+++ b/maintenance/MathGenerateTests.php
@@ -19,7 +19,7 @@
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/../../../maintenance/Maintenance.php' );
+require_once __DIR__ . '/../../../maintenance/Maintenance.php';
 
 class MathGenerateTests extends Maintenance
 {
@@ -89,9 +89,9 @@
                        echo '.';
                }
                echo "Generated $i tests\n";
-               file_put_contents( dirname( __FILE__ ) . 
'/../tests/ParserTest.json', json_encode( $parserTests, JSON_PRETTY_PRINT ) );
+               file_put_contents( __DIR__ . '/../tests/ParserTest.json', 
json_encode( $parserTests, JSON_PRETTY_PRINT ) );
        }
 }
 
-$maintClass = "MathGenerateTests";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+$maintClass = 'MathGenerateTests';
+require_once RUN_MAINTENANCE_IF_MAIN;
diff --git a/tests/MathCoverageTest.php b/tests/MathCoverageTest.php
index 94af443..7b01c1e 100644
--- a/tests/MathCoverageTest.php
+++ b/tests/MathCoverageTest.php
@@ -79,9 +79,8 @@
         * Gets the test-data from the file ParserTest.json
         * @return array($input, $output) where $input is the test input string 
and $output is the rendered html5-output string
         */
-       public function testProvider()
-       {
-               return json_decode( file_get_contents( dirname( __FILE__ ) . 
'/ParserTest.json' ) );
+       public function testProvider() {
+               return json_decode( file_get_contents( __DIR__ . 
'/ParserTest.json' ) );
        }
 
        private function normalize( $input ) {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Id4bec8415893245e2569a39ab5406a0820238ae4
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to