diff --git a/extension.json b/extension.json index 92ddd31..5a1d91f 100644 --- a/extension.json +++ b/extension.json @@ -112,6 +112,15 @@ "speedscope-notification-link-json", "speedscope-notification-link-metadata" ] + }, + "ext.speedscope.edit": { + "localBasePath": "resources/ext.speedscope.edit", + "remoteExtPath": "Speedscope/resources/ext.speedscope.edit", + "dependencies": [], + "styles": [], + "packageFiles": [ + "fixLivePreview.js" + ] } }, "ServiceWiringFiles": [ diff --git a/resources/ext.speedscope.edit/fixLivePreview.js b/resources/ext.speedscope.edit/fixLivePreview.js new file mode 100644 index 0000000..4f52977 --- /dev/null +++ b/resources/ext.speedscope.edit/fixLivePreview.js @@ -0,0 +1,11 @@ +$( () => { + mw.hook( 'wikipage.preview' ).add( ( config ) => { + // eslint-disable-next-line no-jquery/no-global-selector + if ( !$( '#wpProfilePreview' ).is( ':checked' ) ) { + return; + } + const parseParams = config.parseParams || {}; + parseParams.wpProfilePreview = 1; + config.parseParams = parseParams; + } ); +} ); diff --git a/src/HookHandlers/ProfilePreviewsHooks.php b/src/HookHandlers/ProfilePreviewsHooks.php index 3b35435..432a784 100644 --- a/src/HookHandlers/ProfilePreviewsHooks.php +++ b/src/HookHandlers/ProfilePreviewsHooks.php @@ -45,6 +45,7 @@ public function onEditPageGetCheckboxesDefinition( $editpage, &$checkboxes ): vo 'title-message' => 'speedscope-editpage-profile-preview-title', 'label-message' => 'speedscope-editpage-profile-preview-label', ]; + $editpage->getContext()->getOutput()->addModules( 'ext.speedscope.edit' ); } /** @inheritDoc */ @@ -63,7 +64,7 @@ public function onGetPreferences( $user, &$preferences ): void { * @inheritDoc */ public function onParserBeforeInternalParse( $parser, &$text, $stripState ): void { - if ( $parser->getOptions()?->getRenderReason() !== 'page-preview' ) { + if ( !in_array( $parser->getOptions()?->getRenderReason(), [ 'page-preview', 'api-parse' ] ) ) { return; } if ( !RequestContext::getMain()->getRequest()->getCheck( 'wpProfilePreview' ) ) { @@ -132,7 +133,7 @@ public function onParserLimitReportFormat( $key, &$value, &$report, $isHTML, $lo * @inheritDoc */ public function onParserLimitReportPrepare( $parser, $output ): void { - if ( $parser->getOptions()?->getRenderReason() !== 'page-preview' ) { + if ( !in_array( $parser->getOptions()?->getRenderReason(), [ 'page-preview', 'api-parse' ] ) ) { return; } if ( !$output->getExtensionData( self::EXTENSION_DATA_KEY ) ) {