Legoktm has uploaded a new change for review. https://gerrit.wikimedia.org/r/315723
Change subject: Use EditFilterMergedContent hook ...................................................................... Use EditFilterMergedContent hook Bug: T147390 Change-Id: I37bc43392ffa950e230fbff6a902c061ca04b970 Depends-On: I1f0e463841298b8c59ed8bd898c8a4661c5e3aa4 --- M Scribunto.php M common/Hooks.php 2 files changed, 15 insertions(+), 25 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Scribunto refs/changes/23/315723/1 diff --git a/Scribunto.php b/Scribunto.php index 883b663..67b2d04 100644 --- a/Scribunto.php +++ b/Scribunto.php @@ -72,7 +72,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 b6582a4..accc89c 100644 --- a/common/Hooks.php +++ b/common/Hooks.php @@ -367,40 +367,30 @@ } /** - * @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: newchange Gerrit-Change-Id: I37bc43392ffa950e230fbff6a902c061ca04b970 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Scribunto Gerrit-Branch: master Gerrit-Owner: Legoktm <legoktm.wikipe...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits