Physikerwelt has submitted this change and it was merged. Change subject: Force re-rendering ......................................................................
Force re-rendering * Add foreign key for mathindex * Add parameter to force re-rendering Change-Id: I2ed3a692913ae13705dbed7acbc9823e1e993fa4 --- M FormulaInfo.php M MathObject.php M MathSearch.hooks.php M db/mathindex.sql 4 files changed, 49 insertions(+), 42 deletions(-) Approvals: Physikerwelt: Looks good to me, approved jenkins-bot: Verified diff --git a/FormulaInfo.php b/FormulaInfo.php index 6fdf7da..af1ce7d 100644 --- a/FormulaInfo.php +++ b/FormulaInfo.php @@ -10,6 +10,7 @@ * @ingroup extensions */ class FormulaInfo extends SpecialPage { + private $purge = false; /** * */ @@ -24,15 +25,16 @@ global $wgRequest, $wgOut; $pid = $wgRequest->getVal( 'pid' );// Page ID $eid = $wgRequest->getVal( 'eid' );// Equation ID + $this->purge = $wgRequest->getVal( 'purge' , false ); if ( is_null( $pid ) or is_null( $eid ) ) { $tex = $wgRequest->getVal( 'tex', '' ); if ( $tex == '' ) { $wgOut->addHTML( '<b>Please specify page and equation id</b>' ); } else { - self::InfoTex( $tex ); + $this->InfoTex( $tex ); } } else { - self::DisplayInfo( $pid, $eid ); + $this->DisplayInfo( $pid, $eid ); } } public function InfoTex( $tex ) { @@ -158,10 +160,11 @@ * @param $mode * * @throws MWException + * * @internal param $out * @internal param $mo */ - private function DisplayRendering( $tex, $mode) { + private function DisplayRendering( $tex, $mode ) { global $wgExtensionAssetsPath, $wgMathValidModes; if ( !in_array( $mode, $wgMathValidModes ) ) { return; @@ -171,9 +174,10 @@ $name = $names[$mode]; $out->addWikiText( "=== $name rendering === " ); $renderer = MathRenderer::getRenderer( $tex, array(), $mode ); - if ( $renderer->isInDatabase() ) { - $out->addWikiText( "rendering found in database" ); - } else { + if ( $this->purge ){ + $renderer->render( true ); + } elseif ( ! $renderer->isInDatabase() ) { + $out->addWikiText( "No database entry. Start rendering" ); $renderer->render(); } if( self::hasMathMLSupport( $mode ) ){ @@ -181,16 +185,15 @@ $out->addWikiText( 'MathML (' . self::getlengh( $renderer->getMathml() ) . ') :', FALSE ); $imgUrl = $wgExtensionAssetsPath . "/MathSearch/images/math_search_logo.png"; $mathSearchImg = Html::element( 'img', array( 'src' => $imgUrl, 'width' => 15, 'height' => 15 ) ); - $out->addHtml( '<a href="/wiki/Special:MathSearch?mathpattern=' . - urlencode( $tex ) . '&searchx=Search">' . $mathSearchImg . - '</a>' ); + $out->addHtml( '<a href="/wiki/Special:MathSearch?mathpattern=' . urlencode( $tex ) . + '&searchx=Search">' . $mathSearchImg . '</a>' ); $out->addHtml( $renderer->getMathml() ); $out->addHtml( '</div><div class="NavContent">' ); $out->addWikiText( '<syntaxhighlight lang="xml">' . ( $renderer->getMathml() ) . '</syntaxhighlight>' ); $out->addHtml( '</div></div>' ); } if( self::hasSvgSupport( $mode ) ){ - $out->addWikiText( 'SVG (' . self::getlengh( $renderer->getSvg() ) . ') :', + $out->addWikiText( 'SVG (' . self::getlengh( $renderer->getSvg( 'render' ) ) . ') :', FALSE ); $out->addHtml( $renderer->getSvg() ); // FALSE, 'mwe-math-demo' ) ); $out->addHtml( "<br />\n" ); diff --git a/MathObject.php b/MathObject.php index 7d2b646..f00f7f5 100644 --- a/MathObject.php +++ b/MathObject.php @@ -79,8 +79,10 @@ $out = ""; $dbr = wfGetDB( DB_SLAVE ); try { - $res = $dbr->select( 'mathpagesimilarity', array( 'pagesimilarity_A as A', 'pagesimilarity_B as B', 'pagesimilarity_Value as V' ), "pagesimilarity_A=$pid OR pagesimilarity_B=$pid", __METHOD__, array( - "ORDER BY" => 'V DESC', "LIMIT" => 10 ) + $res = $dbr->select( 'mathpagesimilarity', + array( 'pagesimilarity_A as A', 'pagesimilarity_B as B', 'pagesimilarity_Value as V' ), + "pagesimilarity_A=$pid OR pagesimilarity_B=$pid", __METHOD__, + array( "ORDER BY" => 'V DESC', "LIMIT" => 10 ) ); foreach ( $res as $row ) { if ( $row->A == $pid ) { @@ -104,7 +106,8 @@ try { $res = $dbr->select( array( "mathobservation", "mathvarstat", 'mathpagestat' ) , array( "mathobservation_featurename", "mathobservation_featuretype", 'varstat_featurecount', - 'pagestat_featurecount', "count(*) as localcnt" ), array( "mathobservation_inputhash" => $this->getInputHash(), + 'pagestat_featurecount', "count(*) as localcnt" ), + array( "mathobservation_inputhash" => $this->getInputHash(), 'varstat_featurename = mathobservation_featurename', 'varstat_featuretype = mathobservation_featuretype', 'pagestat_pageid' => $this->getRevisionID(), @@ -128,20 +131,25 @@ $wgOut->addWikiText($res->numRows(). ' results'); if ( $res ) { foreach ( $res as $row ) { + $featureName = utf8_decode( $row->mathobservation_featurename ); + if ( bin2hex($featureName)== 'e281a2') { + $featureName = 'invisibe-times'; + } $wgOut->addWikiText( '*' . $row->mathobservation_featuretype . ' <code>' . - utf8_decode( $row->mathobservation_featurename ) . '</code> (' . $row->localcnt . '/' - . $row->pagestat_featurecount . "/" . $row->varstat_featurecount . ')' ); - $identifiers = $this->getNouns(utf8_decode( $row->mathobservation_featurename )) ; - if ( $identifiers ){ - foreach($identifiers as $identifier){ - $wgOut->addWikiText('**'.$identifier->noun .'('.$identifier->evidence.')'); + $featureName . '</code> (' . $row->localcnt . '/' . $row->pagestat_featurecount . + "/" . $row->varstat_featurecount . ')' ); + $identifiers = $this->getNouns( $row->mathobservation_featurename ); + if ( $identifiers ) { + foreach ( $identifiers as $identifier ) { + $wgOut->addWikiText( '**' . $identifier->noun . '(' . + $identifier->evidence . ')' ); + } + } else { + $wgOut->addWikiText( '** not found' ); } - } else { - $wgOut->addWikiText('** not found'); } } } - } /** * @param $identifier @@ -150,10 +158,10 @@ public function getNouns($identifier){ $dbr = wfGetDB( DB_SLAVE ); $pageName = $this->getPageTitle(); - if( $pageName === false ) return false; + if( $pageName === false ) { return false; } $identifiers = $dbr->select('mathidentifier', array( 'noun', 'evidence' ), - array( 'pageTitle' => $pageName, 'identifier' => $identifier), + array( 'pageTitle' => $pageName, 'identifier' => utf8_encode( $identifier )), __METHOD__ , array('ORDER BY' => 'evidence DESC', 'LIMIT' => 5) ); @@ -162,8 +170,6 @@ } public function updateObservations( $dbw = null ) { - global $wgMathUpdateObservations; - if ( $wgMathUpdateObservations ) $this->updateObservations(); $this->readFromDatabase(); preg_match_all( "#<(mi|mo|mtext)( ([^>].*?))?>(.*?)</\\1>#u", $this->getMathml(), $rule, PREG_SET_ORDER ); if ( $dbw == null ) { @@ -205,7 +211,6 @@ $res = $dbr->selectRow( array( 'mathindex' ), self::dbIndexFieldsArray(), 'mathindex_revision_id = ' . $pid . ' AND mathindex_anchor= "' . $eid . '"' ); - //self::DebugPrint( var_export( $res, true ) ); $start = microtime(true); $o = self::constructformpagerow( $res ); wfDebugLog("MathSearch", "Fetched in ". (microtime(true)-$start) ); @@ -286,7 +291,7 @@ //return '<mi>X</mi>'; $attribs = preg_replace('/title\s*=\s*"(.*)"/','',$arg[2]); $content = $arg[4]; - $nouns=$this->getNouns(utf8_decode($content)); + $nouns=$this->getNouns( $content ); $title ='not set'; if ( $nouns ){ foreach($nouns as $identifier){ @@ -336,10 +341,10 @@ . "ORDER BY CNT DESC"); $dbw->query( 'TRUNCATE TABLE `mathpagestat`' ); $dbw->query( 'INSERT INTO `mathpagestat`(`pagestat_featureid`,`pagestat_pageid`,`pagestat_featurecount`) ' - . 'SELECT varstat_id, mathindex_revision_id, count(*) as CNT FROM `mathobservation` ' - . 'JOIN mathindex on `mathobservation_inputhash` = mathindex_inputhash ' - . 'JOIN mathvarstat on varstat_featurename = `mathobservation_featurename` and varstat_featuretype = `mathobservation_featuretype` ' - . 'GROUP by `mathobservation_featurename`, `mathobservation_featuretype`, mathindex_revision_id ORDER BY CNT DESC' ); + . 'SELECT varstat_id, mathindex_revision_id, count(*) AS CNT FROM `mathobservation` ' + . 'JOIN mathindex ON `mathobservation_inputhash` = mathindex_inputhash ' + . 'JOIN mathvarstat ON varstat_featurename = `mathobservation_featurename` AND varstat_featuretype = `mathobservation_featuretype` ' + . 'GROUP BY `mathobservation_featurename`, `mathobservation_featuretype`, mathindex_revision_id ORDER BY CNT DESC' ); } /** diff --git a/MathSearch.hooks.php b/MathSearch.hooks.php index 6be7e91..541203c 100644 --- a/MathSearch.hooks.php +++ b/MathSearch.hooks.php @@ -69,26 +69,25 @@ /** * Updates the formula index in the database * - * @param int $pid Page-ID + * @param int $revId Page-ID * @param int $eid Equation-ID (get updated incrementally for every math element on the page) * @param string $inputHash hash of tex string (used as database entry) * @param string $tex the user input hash */ - private static function updateIndex($pid, $eid, $inputHash, $tex){ + private static function updateIndex($revId, $eid, $inputHash, $tex){ try { - $oldID = self::curId2OldId( $pid ); $dbr = wfGetDB( DB_SLAVE ); $exists = $dbr->selectRow( 'mathindex', array( 'mathindex_revision_id', 'mathindex_anchor', 'mathindex_inputhash' ), array( - 'mathindex_revision_id' => $oldID, + 'mathindex_revision_id' => $revId, 'mathindex_anchor' => $eid, 'mathindex_inputhash' => $inputHash) ) ; if ( $exists ) { wfDebugLog( "MathSearch", 'Index $' . $tex . '$ already in database.' ); } else { - self::writeMathIndex( $oldID, $eid, $inputHash, $tex ); + self::writeMathIndex( $revId, $eid, $inputHash, $tex ); } } catch ( Exception $e ) { wfDebugLog( "MathSearch", 'Problem writing to math index!' @@ -123,18 +122,18 @@ * Callback function that is called after a formula was rendered * @param MathRenderer $Renderer * @param string|null $Result reference to the rendering result - * @param int $pid + * @param int $revId * @param int $eid * @return bool */ - static function updateMathIndex( MathRenderer $Renderer, &$Result = null, $pid = 0, $eid = 0 ) { - if ( $pid > 0 ) { // Only store something if a pageid was set. + static function updateMathIndex( MathRenderer $Renderer, &$Result = null, $revId = 0, $eid = 0 ) { + if ( $revId > 0 ) { // Only store something if a pageid was set. // Use manually assigned IDs whenever possible // and fallback to automatic IDs otherwise. if ( ! self::setMathId( $eid , $Renderer ) ){ $Result = preg_replace( '/(class="mwe-math-mathml-(inline|display))/', "id=\"$eid\" \\1", $Result ); } - self::updateIndex( $pid , $eid , $Renderer->getInputHash() , $Renderer->getTex() ); + self::updateIndex( $revId , $eid , $Renderer->getInputHash() , $Renderer->getTex() ); } return true; } diff --git a/db/mathindex.sql b/db/mathindex.sql index e54000b..94892db 100644 --- a/db/mathindex.sql +++ b/db/mathindex.sql @@ -20,7 +20,7 @@ mathindex_timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (mathindex_revision_id,mathindex_anchor), - KEY ( /*i*/mathindex_inputhash ), -- FOREIGEN KEY .. REFERENCES mathoid( mathindex_inputhash ), + FOREIGN KEY ( /*i*/mathindex_inputhash ) REFERENCES mathlatexml( mathindex_inputhash ), FOREIGN KEY ( /*i*/mathindex_revision_id ) REFERENCES revision( rev_id ) ) /*$wgDBTableOptions*/; \ No newline at end of file -- To view, visit https://gerrit.wikimedia.org/r/189777 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I2ed3a692913ae13705dbed7acbc9823e1e993fa4 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/MathSearch Gerrit-Branch: master Gerrit-Owner: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: Physikerwelt <w...@physikerwelt.de> Gerrit-Reviewer: Springle <sprin...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits