Physikerwelt has uploaded a new change for review.

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

Change subject: Fix: Correct select field for MathEngine
......................................................................

Fix: Correct select field for MathEngine

* label and value were switched

Change-Id: I7ee1cf1a777b2b93e81f38b12bbac9c85ac9c51d
---
M MathQueryObject.php
M SpecialMathSearch.php
M XQueryGeneratorBaseX.php
3 files changed, 25 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MathSearch 
refs/changes/32/111432/1

diff --git a/MathQueryObject.php b/MathQueryObject.php
index b1bfe7a..dc7fe34 100644
--- a/MathQueryObject.php
+++ b/MathQueryObject.php
@@ -32,7 +32,7 @@
                'texvc'),
        );
 
-       public function __construct( $texquery='' , $xQueryDialect = 'DB2' ) {
+       public function __construct( $texquery='' , $xQueryDialect = 'db2' ) {
                $this->texquery = $texquery;
                $this->xQueryDialect = $xQueryDialect;
        }
@@ -212,18 +212,25 @@
         * @throws Exception
         */
        public function setXQueryGenerator( $dialect = false ){
-               if ($dialect === false){
+               if ($dialect !== false){
                        $dialect = $this->xQueryDialect;
                }
                switch ($dialect) {
-                       case 'DB2':
+                       case 'db2':
                                $this->xQuery = new XQueryGeneratorDB2( 
$this->getCQuery() );
                                break;
-                       case 'BaseX':
+                       case 'basex':
                                $this->xQuery = new XQueryGeneratorBaseX( 
$this->getCQuery() );
                                break;
                        default:
                                throw new Exception($dialect . 'is not a valid 
XQueryDialect');
+               }
+               return $this->xQuery;
+       }
+
+       public function getXQueryGenerator(){
+               if ($this->xQuery === false){
+                       $this->setXQueryGenerator();
                }
                return $this->xQuery;
        }
@@ -233,8 +240,7 @@
         * @return String
         */
        public function getXQuery(){
-               $xQueryGenertor = $this->setXQueryGenerator();
-               return $xQueryGenertor->getXQuery();
+               return $this->getXQueryGenerator()->getXQuery();
        }
 
                /**
diff --git a/SpecialMathSearch.php b/SpecialMathSearch.php
index 7f4397c..ab71290 100644
--- a/SpecialMathSearch.php
+++ b/SpecialMathSearch.php
@@ -24,7 +24,7 @@
        var $displayQuery;
        private $mathBackend;
        private $resultID = 0;
-       private $xQueryEngines = array ('DB2', 'BaseX');
+       private $xQueryEngines = array ('db2', 'basex');
 
        /**
         *
@@ -74,9 +74,9 @@
                                'label' => 'Math engine',
                                'class' => 'HTMLSelectField',
                                'options' => array(
-                                       'mws' => 'MathWebSearch',
-                                       'db2' => 'DB2',
-                                       'basex' => 'BaseX'
+                    'MathWebSearch'=>'mws',
+                    'DB2' => 'db2',
+                    'BaseX' => 'basex'
                                ),
                                'default' => $this->mathEngine,
                        ),
@@ -187,19 +187,19 @@
                $out = $this->getOutput();
                $time_start = microtime( true );
                $out->addWikiText( '==Results==' );
-               $out->addWikiText( 'You serached for the LaTeX pattern "' . 
$this->mathpattern . '" and the text pattern "' . $this->textpattern . '".' );
+               $out->addWikiText( 'You searched for the LaTeX pattern "' . 
$this->mathpattern . '" and the text pattern "' . $this->textpattern . '".' );
                if ( $this->mathpattern ) {
                        $query = new MathQueryObject( $this->mathpattern );
                        switch ($this->mathEngine){
-                               case 'DB2':
-                                       $query->setXQueryGenerator( 'DB2' );
+                               case 'db2':
+                                       $query->setXQueryGenerator( 'db2' );
                                        break;
-                               case 'BaseX':
-                                       $query->setXQueryGenerator( 'BaseX' );
+                               case 'basex':
+                                       $query->setXQueryGenerator( 'basex' );
                        }
                        $cQuery = $query->getCQuery();
                        if ( $cQuery ) {
-                               $out->addWikiText( "Your mathpattern was 
suceessfully rendered!" );
+                               $out->addWikiText( "Your mathpattern was 
successfully rendered!" );
                                if ( $this->displayQuery === true){
                                        if (in_array( $this->mathEngine, 
$this->xQueryEngines )){
                                                
$this->printSource($query->getXQuery());
@@ -209,7 +209,7 @@
                                }
                                $this->mathBackend = new MathEngineMws($query);
                                if ( $this->mathBackend->postQuery() ) {
-                                       $out->addWikiText( "Your mathquery was 
sucessfully submitted and " . $this->mathBackend->getSize() . " hits were 
obtained." );
+                                       $out->addWikiText( "Your mathquery was 
successfully submitted and " . $this->mathBackend->getSize() . " hits were 
obtained." );
                                } else {
                                        $out->addWikiText( "Failed to post 
query." );
                                }
@@ -217,7 +217,7 @@
                                $time = $time_end - $time_start;
                                wfDebugLog( "MathSearch", "math searched in 
$time seconds" );
                        } else {
-                               $out->addWikiText( "Your query could not be 
renderded see the DebugLog for details." );
+                               $out->addWikiText( "Your query could not be 
rendered see the DebugLog for details." );
                        }
                        // $out->addHTML(var_export($this->mathResults, true));
                } else {
@@ -225,7 +225,7 @@
                        $out->addWikiText( "To view the text results click 
[{{canonicalurl:search|search=$this->textpattern}} Text-only search]." );
                }
 
-               if ( $this->textpattern == "" ) {
+               if ( $this->mathBackend && $this->textpattern == "" ) {
                        $mathout = "";
                        $results = $this->mathBackend->getResultSet();
                        if ( $results ) {
diff --git a/XQueryGeneratorBaseX.php b/XQueryGeneratorBaseX.php
index 1af080a..81584e3 100644
--- a/XQueryGeneratorBaseX.php
+++ b/XQueryGeneratorBaseX.php
@@ -14,7 +14,6 @@
         * @return string
         */
        protected function getHeader(){
-               global $wgMathSearchDB2Table;
                return 'declare default element namespace 
"http://www.w3.org/1998/Math/MathML";;
 for $m in //*:expr return';
        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ee1cf1a777b2b93e81f38b12bbac9c85ac9c51d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>

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

Reply via email to