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

Change subject: Use EditFilterMergedContent hook
......................................................................


Use EditFilterMergedContent hook

Bug: T147565
Change-Id: I37bc43392ffa950e230fbff6a902c061ca04b970
Depends-On: I1f0e463841298b8c59ed8bd898c8a4661c5e3aa4
---
M Scribunto.php
M common/Hooks.php
2 files changed, 17 insertions(+), 25 deletions(-)

Approvals:
  Tim Starling: Looks good to me, approved
  Anomie: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/Scribunto.php b/Scribunto.php
index 9e4f09f..a703463 100644
--- a/Scribunto.php
+++ b/Scribunto.php
@@ -74,7 +74,7 @@
 $wgHooks['EditPageBeforeEditChecks'][] = 'ScribuntoHooks::beforeEditChecks';
 $wgHooks['EditPage::showReadOnlyForm:initial'][] = 
'ScribuntoHooks::showReadOnlyFormInitial';
 $wgHooks['EditPageBeforeEditButtons'][] = 'ScribuntoHooks::beforeEditButtons';
-$wgHooks['EditFilterMerged'][] = 'ScribuntoHooks::validateScript';
+$wgHooks['EditFilterMergedContent'][] = 'ScribuntoHooks::validateScript';
 $wgHooks['ArticleViewHeader'][] = 'ScribuntoHooks::showDocPageHeader';
 $wgHooks['ContentHandlerDefaultModelFor'][] = 
'ScribuntoHooks::contentHandlerDefaultModelFor';
 
diff --git a/common/Hooks.php b/common/Hooks.php
index 86449af..cf27836 100644
--- a/common/Hooks.php
+++ b/common/Hooks.php
@@ -367,40 +367,32 @@
        }
 
        /**
-        * @todo this should use the EditFilterMergedContent hook instead
-        *       so it can use ScribuntoContent::validate()
-        * @param EditPage $editor
-        * @param string $text
-        * @param string $error
-        * @param string $summary
+        * @param IContextSource $context
+        * @param Content $content
+        * @param Status $status
         * @return bool
         */
-       public static function validateScript( EditPage $editor, $text, 
&$error, $summary ) {
-               $title = $editor->getTitle();
+       public static function validateScript( IContextSource $context, Content 
$content,
+               Status $status
+       ) {
+               $title = $context->getTitle();
 
-               if ( !$title->hasContentModel( CONTENT_MODEL_SCRIBUNTO ) ) {
+               if ( !$content instanceof ScribuntoContent ) {
                        return true;
                }
 
-               $engine = Scribunto::newDefaultEngine();
-               $engine->setTitle( $title );
-               $status = $engine->validate( $text, $title->getPrefixedDBkey() 
);
-               if ( $status->isOK() ) {
+               $validateStatus = $content->validate( $title );
+               if ( $validateStatus->isOK() ) {
                        return true;
                }
 
-               $errmsg = $status->getWikiText( 'scribunto-error-short', 
'scribunto-error-long' );
-               $error = <<<WIKI
-<div class="errorbox">
-{$errmsg}
-</div>
-<br clear="all" />
-WIKI;
-               if ( isset( $status->scribunto_error->params['module'] ) ) {
-                       $module = $status->scribunto_error->params['module'];
-                       $line = $status->scribunto_error->params['line'];
+               $status->merge( $validateStatus );
+
+               if ( isset( $validateStatus->scribunto_error->params['module'] 
) ) {
+                       $module = 
$validateStatus->scribunto_error->params['module'];
+                       $line = 
$validateStatus->scribunto_error->params['line'];
                        if ( $module === $title->getPrefixedDBkey() && 
preg_match( '/^\d+$/', $line ) ) {
-                               $out = 
$editor->getArticle()->getContext()->getOutput();
+                               $out = $context->getOutput();
                                $out->addInlineScript( 'window.location.hash = 
' . Xml::encodeJsVar( "#mw-ce-l$line" ) );
                        }
                }

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I37bc43392ffa950e230fbff6a902c061ca04b970
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Scribunto
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Anomie <bjor...@wikimedia.org>
Gerrit-Reviewer: Jackmcbarn <jackmcb...@gmail.com>
Gerrit-Reviewer: Reedy <re...@wikimedia.org>
Gerrit-Reviewer: Tim Starling <tstarl...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to