Physikerwelt has submitted this change and it was merged.
Change subject: Styling and struggling with HTTP:post
......................................................................
Styling and struggling with HTTP:post
for some reason HTTP:post does not return the correct error status
Change-Id: I25dac7c0ce0bbc5a65f0e96b3e6a168c3e03d985
---
M FormulaInfo.php
M MathObject.php
M MathSearch.hooks.php
M SpecialMathDebug.php
M SpecialMathSearch.php
A db/CosProd.sql
A db/getNorm.sql
7 files changed, 79 insertions(+), 34 deletions(-)
Approvals:
Physikerwelt: Verified; Looks good to me, approved
diff --git a/FormulaInfo.php b/FormulaInfo.php
index 093da30..31bf4b5 100644
--- a/FormulaInfo.php
+++ b/FormulaInfo.php
@@ -66,7 +66,7 @@
$mo = MathObject::constructformpage( $pid, $eid );
$wgOut->addWikiText( "Occurences on the following pages:" );
wfDebugLog( "MathSearch", var_export( $mo->getAllOccurences(),
true ) );
- //$wgOut->addWikiText('<b>:'.var_export($res,true).'</b>');
+ // $wgOut->addWikiText('<b>:'.var_export($res,true).'</b>');
$wgOut->addWikiText( 'TeX : <code>' . $mo->getTex() . '</code>'
);
$wgOut->addWikiText( 'MathML : ', false );
@@ -90,7 +90,7 @@
$wgOut->addWikiText( '==LOG and Debug==' );
$wgOut->addWikiText( 'Rendered at : <code>' .
$mo->getTimestamp()
. '</code> an idexed at <code>' .
$mo->getIndexTimestamp() . '</code>' );
- $wgOut->addWikiText( 'validxml : <code>' .
MathLaTeXML::isValidMathML($mo->getMathml()) . '</code> recheck:', false );
+ $wgOut->addWikiText( 'validxml : <code>' .
MathLaTeXML::isValidMathML( $mo->getMathml() ) . '</code> recheck:', false );
$wgOut->addHtml( MathLaTeXML::isValidMathML( $mo->getMathml() )
? "valid":"invalid" );
$wgOut->addWikiText( 'status : <code>' . $mo->getStatusCode() .
'</code>' );
$wgOut->addHtml( htmlspecialchars( $mo->getLog() ) );
diff --git a/MathObject.php b/MathObject.php
index 73adcbd..2975fcf 100644
--- a/MathObject.php
+++ b/MathObject.php
@@ -5,10 +5,10 @@
protected $index_timestamp = null;
protected $inputHash = '';
- private static function DebugPrint($s){
- //$s= Sanitizer::safeEncodeAttribute($s);
- wfDebugLog( "MathSearch", $s);
- }
+ private static function DebugPrint( $s ) {
+ // $s= Sanitizer::safeEncodeAttribute($s);
+ wfDebugLog( "MathSearch", $s );
+ }
public function getAnchorID() {
return $this->anchorID;
@@ -25,10 +25,10 @@
public function getIndexTimestamp() {
return $this->index_timestamp;
}
- public function getInputHash(){
- wfDebugLog('MathSearch', 'Debugger dies here');
- //die('end of debug toolbar');
- if ($this->inputHash){
+ public function getInputHash() {
+ wfDebugLog( 'MathSearch', 'Debugger dies here' );
+ // die('end of debug toolbar');
+ if ( $this->inputHash ) {
return $this->inputHash;
} else {
return parent::getInputHash();
diff --git a/MathSearch.hooks.php b/MathSearch.hooks.php
index 6097c05..1579222 100644
--- a/MathSearch.hooks.php
+++ b/MathSearch.hooks.php
@@ -84,7 +84,7 @@
}
}
$url = SpecialPage::getTitleFor( 'FormulaInfo' )->getLocalUrl(
array( 'pid' => $pid, 'eid' => $eid ) );
- $Result = '<a href="' . $url . '" id="math'.$eid.'">' . $Result
. '</a>';
+ $Result = '<a href="' . $url . '" id="math' . $eid . '">' .
$Result . '</a>';
return true;
}
diff --git a/SpecialMathDebug.php b/SpecialMathDebug.php
index daf973f..e5f7d6f 100644
--- a/SpecialMathDebug.php
+++ b/SpecialMathDebug.php
@@ -86,10 +86,10 @@
if ( $diff->isEmpty() ) {
$out->addWikiText( 'Output is
identical' );
} else {
- $out->addWikiText('Requst A <source
lang="bash"> curl -d \''.
- $renderer->getPostValue().'\'
'.$parserA.'</source>');
- $out->addWikiText('Requst B <source
lang="bash"> curl -d \''.
- $renderer->getPostValue().'\'
'.$parserB.'</source>');
+ $out->addWikiText( 'Requst A <source
lang="bash"> curl -d \'' .
+ $renderer->getPostValue() . '\'
' . $parserA . '</source>' );
+ $out->addWikiText( 'Requst B <source
lang="bash"> curl -d \'' .
+ $renderer->getPostValue() . '\'
' . $parserB . '</source>' );
$out->addWikiText( 'Diff: <source
lang="diff">' . $diffFormatter->format( $diff ) . '</source>' );
$out->addWikiText( 'XML Element based:'
);
$XMLA = explode( '>', $stringA );
@@ -111,13 +111,13 @@
global $wgUseMathJax, $wgUseLaTeXML, $wgTexvc;
$out = $this->getOutput();
$out->addModules( array( 'ext.math.mathjax.enabler' ) );
- //die('END');
+ // die('END');
$i = 0;
foreach ( array_slice( self::getMathTagsFromPage( $page ),
$offset, $length, true ) as $key => $t ) {
$out->addWikiText( "=== Test #" . ( $offset + $i++ ) .
": $key === " );
$out->addHTML( self::render( $t, MW_MATH_SOURCE ) );
$out->addHTML( self::render( $t, MW_MATH_PNG ) );
- $out->addWikiText('<source
lang="latex">'.$this->getTexvcTex($t).'</source>');
+ $out->addWikiText( '<source lang="latex">' .
$this->getTexvcTex( $t ) . '</source>' );
if ( $wgUseLaTeXML ) {
$out->addHTML( self::render( $t,
MW_MATH_LATEXML ) );
}
@@ -155,11 +155,11 @@
return true;
}
private static function render( $t, $mode, $aimJax = true ) {
- $renderer = MathRenderer::getRenderer($t, array(), $mode);
- $renderer->setPurge(true);
+ $renderer = MathRenderer::getRenderer( $t, array(), $mode );
+ $renderer->setPurge( true );
$fragment = $renderer->render();
$res = $mode . ':' . $fragment;
- wfDebugLog('MathSearch', 'rendered:' .$res);
+ wfDebugLog( 'MathSearch', 'rendered:' . $res );
if ( $aimJax ) {
self::aimHTMLFromJax( $res );
}
@@ -182,12 +182,12 @@
// leads to array('\1'->'\2') with \1 eg Bug 2345 and \2 the
math content
return $math[1];
}
- private function getTexvcTex($tex){
+ private function getTexvcTex( $tex ) {
$tmpDir = wfTempDir();
- $renderer = MathRenderer::getRenderer($tex,array(),MW_MATH_PNG);
- $renderer->setPurge(true);
+ $renderer = MathRenderer::getRenderer( $tex, array(),
MW_MATH_PNG );
+ $renderer->setPurge( true );
$renderer->callTexvc();
return $renderer->getSecureTex();
-
+
}
}
diff --git a/SpecialMathSearch.php b/SpecialMathSearch.php
index 3e8dd60..53d65af 100644
--- a/SpecialMathSearch.php
+++ b/SpecialMathSearch.php
@@ -77,8 +77,9 @@
$ls = self::getLucene() ;
if ( $ls ) {
$ls->limit = 1000000;
+ if ( $text ) {
$sres = $ls->searchText( $text );
- if ( $sres ) {
+ if ( $sres && $sres->hasResults() ) {
$wgOut->addWikiText( "You searched for the text '$text'
and the TeX-Pattern '$pattern'." );
$wgOut->addWikiText( "The text search results in
[{{canonicalurl:search|search=$text}} " .
$sres->getTotalHits()
@@ -106,7 +107,7 @@
wfDebugLog( 'mathsearch', 'EOF' );
wfDebugLog( 'mathsearch', var_export(
$this->mathResults , true ) );
- }
+ } }
}
// $wgOut->addHtml(htmlspecialchars( $pattern) );
$wgOut->addWikiText( "<math> $pattern </math>" );
@@ -218,9 +219,10 @@
* @return string|boolean
*/
function render( $tex ) {
- $renderer = new MathLaTeXML($texcmd);
- $renderer->setLaTeXMLSettings('profile=mwsquery');
- $renderer->render(true);
+ $renderer = new MathLaTeXML( $tex );
+ $renderer->setLaTeXMLSettings( 'profile=mwsquery' );
+ $renderer->setAllowedRootElments( array(
'http://search.mathweb.org/ns:query' ) );
+ $renderer->render( true );
$contents = $renderer->getMathml();
if ( strlen( $contents ) == 0 ) {
return 'ERROR unknown';
@@ -236,14 +238,25 @@
function genSerachString( $cmml ) {
global $wgMWSUrl;
- $out = ""; $numProcess = 30000;
- $mwsExpr = str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $cmml );
- $mwsExpr = str_replace( "m:", "", $mwsExpr );
+ $numProcess = 30000;
+ $tmp = str_replace( "answsize=\"30\"",
"answsize=\"$numProcess\" totalreq=\"yes\"", $cmml );
+ $mwsExpr = str_replace( "m:", "", $tmp );
wfDebugLog( 'mathsearch', 'MWS query:' . $mwsExpr );
$res = Http::post( $wgMWSUrl, array( "postData" => $mwsExpr,
"timeout" => 60 ) );
-
if ( $res == false ) {
- wfDebugLog( "MathSearch", "Nothing retreived from
$wgMWSUrl. Check if mwsd is running." );
+ if ( function_exists( 'curl_init' ) ) {
+ $handle = curl_init();
+ $options = array(
+ CURLOPT_URL => $wgMWSUrl,
+ CURLOPT_CUSTOMREQUEST => 'POST', // GET POST
PUT PATCH DELETE HEAD OPTIONS
+ );
+ curl_setopt_array( $handle, $options );
+ $details = curl_exec( $handle );
+ } else {
+ $details = "curl is not installed.";
+ }
+ wfDebugLog( "MathSearch", "Nothing retreived from
$wgMWSUrl. Check if mwsd is running. Error:" .
+ var_export( $details, true ) );
return false;
}
$xres = new SimpleXMLElement( $res );
diff --git a/db/CosProd.sql b/db/CosProd.sql
new file mode 100644
index 0000000..b9add42
--- /dev/null
+++ b/db/CosProd.sql
@@ -0,0 +1,17 @@
+delimiter $$
+
+CREATE DEFINER=`root`@`localhost` FUNCTION `CosProd`(IDA INT,IDB INT )
RETURNS decimal(20,10)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+-- Calculates the CosineSimilarity of two pages
+return (
+ SELECT SUM(CAST(LOG( a.`pagestat_featurecount`)*
LOG(b.`pagestat_featurecount`) as DECIMAL(20,10))
+ /(LOG(varstat_featurecount)*LOG(varstat_featurecount))
)/(getNorm(IDA)* getNorm(IDB))
+ from mathpagestat as a, mathpagestat as b, mathvarstat as s
+ WHERE (b.`pagestat_pageid`= IDA and a.`pagestat_pageid`=IDB
+ and a.`pagestat_featureid`=b.`pagestat_featureid`
+ and a.`pagestat_featureid`=s.varstat_id)
+);
+END$$
+
diff --git a/db/getNorm.sql b/db/getNorm.sql
new file mode 100644
index 0000000..b0581c2
--- /dev/null
+++ b/db/getNorm.sql
@@ -0,0 +1,15 @@
+delimiter $$
+
+CREATE DEFINER=`root`@`localhost` FUNCTION `getNorm`(pid INT) RETURNS
decimal(20,10)
+ READS SQL DATA
+ DETERMINISTIC
+BEGIN
+DECLARE output DECIMAL(20,10);
+SELECT SUM(POW(LOG(CAST(`pagestat_featurecount`as
decimal(20,10)))/LOG(varstat_featurecount),2)) as norm
+INTO output
+FROM `mathpagestat`
+JOIN mathvarstat on `pagestat_featureid` = varstat_id
+WHERE `pagestat_pageid` =pid order by norm desc;
+return POW(output,1/2);
+END$$
+
--
To view, visit https://gerrit.wikimedia.org/r/72770
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I25dac7c0ce0bbc5a65f0e96b3e6a168c3e03d985
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <[email protected]>
Gerrit-Reviewer: Physikerwelt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits