Physikerwelt has uploaded a new change for review.

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

Change subject: Deduplicate code to find math tags
......................................................................

Deduplicate code to find math tags

* Step 1 all code that uses a content handler

Change-Id: Ib16e96762f3567d3a8e9f086b666548590fb6508
---
M MathSearch.hooks.php
M includes/MathIdGenerator.php
M includes/special/SpecialMlpEval.php
3 files changed, 14 insertions(+), 16 deletions(-)


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

diff --git a/MathSearch.hooks.php b/MathSearch.hooks.php
index b8738e8..a414e4e 100644
--- a/MathSearch.hooks.php
+++ b/MathSearch.hooks.php
@@ -351,9 +351,9 @@
                        )->warning( "Empty update for 
{$article->getTitle()->getFullText()}." );
                        return true;
                }
-               $mathTags =
-                       MathObject::extractMathTagsFromWikiText( 
ContentHandler::getContentText( $content ) );
                $revId = $revision->getId();
+               $idGenerator = MathIdGenerator::newFromRevisionId( $revId );
+               $mathTags= $idGenerator->getMathTags();
                $harvest = "";
                if ( $mathTags ) {
                        $dw = new MwsDumpWriter();
diff --git a/includes/MathIdGenerator.php b/includes/MathIdGenerator.php
index df578d4..c7dd7ab 100644
--- a/includes/MathIdGenerator.php
+++ b/includes/MathIdGenerator.php
@@ -92,4 +92,11 @@
        public function getMathTags() {
                return $this->mathTags;
        }
+
+       /**
+        * @return string
+        */
+       public function getWikiText() {
+               return $this->wikiText;
+       }
 }
diff --git a/includes/special/SpecialMlpEval.php 
b/includes/special/SpecialMlpEval.php
index 7b1eaba..1c61fd8 100644
--- a/includes/special/SpecialMlpEval.php
+++ b/includes/special/SpecialMlpEval.php
@@ -145,26 +145,17 @@
                        $this->lastError = "Redirects are not supported";
                        return false;
                }
-               $revision = $title->getLatestRevID();
-               if ( $revision ) {
-                       $revision = Revision::newFromId( $revision );
-                       if ( $revision->getContentModel() !== 
CONTENT_MODEL_WIKITEXT ) {
-                               $this->lastError = "Has invalid format";
-                               return false;
-                       }
-                       $handler = new WikitextContentHandler();
-                       $wikiText = $handler->getContentText( 
$revision->getContent() );
-                       $wikiText = Sanitizer::removeHTMLcomments( $wikiText );
-                       // Remove <nowiki /> tags to avoid confusion
-                       $wikiText = preg_replace( '#<nowiki>(.*)</nowiki>#', 
'', $wikiText );
-                       $wikiText = Parser::extractTagsAndParams( array( 'math' 
), $wikiText, $mathTags );
+               $revId = $title->getLatestRevID();
+               if ( $revId ) {
+                       $idGenerator = MathIdGenerator::newFromRevisionId( 
$revId );
+                       $mathTags = $idGenerator->getMathTags();
                        $tagCount = count( $mathTags );
                        if ( $tagCount == 0 ) {
                                $this->lastError = "has no math tags";
                                return false;
                        }
                        $this->title = $title;
-                       $this->wikitext = $wikiText;
+                       $this->wikitext = $idGenerator->getWikiText();
                        $this->mathTags = $mathTags;
                        return true;
                } else {

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib16e96762f3567d3a8e9f086b666548590fb6508
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MathSearch
Gerrit-Branch: master
Gerrit-Owner: Physikerwelt <w...@physikerwelt.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to