From 7dbe38577346768ec6b90c203dc6127eb15982a3 Mon Sep 17 00:00:00 2001 From: Sam Wilson Date: Fri, 24 Mar 2023 14:12:34 +0800 Subject: [PATCH] Move the diff-mode selector to the new DifferenceEngineBeforeDiffTable hook Use the new hook to add the diff-mode selector to the area directly before the diff table. Also toggles the new inline-diff legend, when the initial diff-type is 'inline'. Depends-On: I6de30bf79eb5ac262285951792782b870d075e00 Bug: T324759 Change-Id: Ifc133856dd793693c3a2722a7b1319dfe74555a2 --- extension.json | 7 ++++++- includes/Hooks.php | 11 +++++------ modules/ve-mw/preinit/styles/ve.init.mw.DiffPage.less | 5 ----- modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js | 6 ++++++ 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/extension.json b/extension.json index 1b61635b2f..f332e3e936 100644 --- a/extension.json +++ b/extension.json @@ -228,7 +228,7 @@ "BeforePageDisplay": "MediaWiki\\Extension\\VisualEditor\\Hooks::onBeforePageDisplay", "ChangeTagsListActive": "MediaWiki\\Extension\\VisualEditor\\Hooks::onListDefinedTags", "CustomEditor": "MediaWiki\\Extension\\VisualEditor\\Hooks::onCustomEditor", - "DifferenceEngineViewHeader": "MediaWiki\\Extension\\VisualEditor\\Hooks::onDifferenceEngineViewHeader", + "DifferenceEngineBeforeDiffTable": "VisualEditorHooks", "EditPage::showEditForm:fields": "MediaWiki\\Extension\\VisualEditor\\Hooks::onEditPageShowEditFormFields", "GetBetaFeaturePreferences": "MediaWiki\\Extension\\VisualEditor\\Hooks::onGetBetaPreferences", "GetPreferences": "MediaWiki\\Extension\\VisualEditor\\Hooks::onGetPreferences", @@ -248,6 +248,11 @@ ], "UserLoggedIn": "MediaWiki\\Extension\\VisualEditor\\Hooks::onUserLoggedIn" }, + "HookHandlers": { + "VisualEditorHooks": { + "class": "MediaWiki\\Extension\\VisualEditor\\Hooks" + } + }, "ResourceModules": { "socket.io": { "scripts": [ diff --git a/includes/Hooks.php b/includes/Hooks.php index 566806a05a..0cc9120591 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -19,6 +19,7 @@ use ExtensionRegistry; use Html; use Language; use MediaWiki; +use MediaWiki\Diff\Hook\DifferenceEngineBeforeDiffTableHook; use MediaWiki\MediaWikiServices; use MediaWiki\ResourceLoader\ResourceLoader; use MediaWiki\User\UserIdentity; @@ -35,7 +36,7 @@ use Title; use User; use WebRequest; -class Hooks { +class Hooks implements DifferenceEngineBeforeDiffTableHook { // Known parameters that VE does not handle // TODO: Other params too? @@ -141,7 +142,7 @@ class Hooks { * @param DifferenceEngine $diff The difference engine * @return void */ - public static function onDifferenceEngineViewHeader( DifferenceEngine $diff ) { + public function onDifferenceEngineBeforeDiffTable( DifferenceEngine $diff, array &$parts ) { $services = MediaWikiServices::getInstance(); $veConfig = $services->getConfigFactory() ->makeConfig( 'visualeditor' ); @@ -173,8 +174,7 @@ class Hooks { ] ); $output->addModules( 'ext.visualEditor.diffPage.init' ); $output->enableOOUI(); - $output->addHTML( - '
' . + $parts['ve-init-mw-diffPage-diffMode'] = '
' . // Will be replaced by a ButtonSelectWidget in JS new ButtonGroupWidget( [ 'items' => [ @@ -192,8 +192,7 @@ class Hooks { ] ) ] ] ) . - '
' - ); + '
'; } /** diff --git a/modules/ve-mw/preinit/styles/ve.init.mw.DiffPage.less b/modules/ve-mw/preinit/styles/ve.init.mw.DiffPage.less index cd01a7b315..ad57461b45 100644 --- a/modules/ve-mw/preinit/styles/ve.init.mw.DiffPage.less +++ b/modules/ve-mw/preinit/styles/ve.init.mw.DiffPage.less @@ -7,11 +7,6 @@ @import 'mediawiki.mixins'; -.ve-init-mw-diffPage-diffMode { - text-align: right; - margin: 1em 0; -} - .client-nojs .ve-init-mw-diffPage-diffMode { display: none; } diff --git a/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js b/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js index 06108a7c08..d2d7b35dcd 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js +++ b/modules/ve-mw/preinit/ve.init.mw.DiffPage.init.js @@ -15,6 +15,7 @@ progress = new OO.ui.ProgressBarWidget( { classes: [ 've-init-mw-diffPage-loading' ] } ), originalUrl = new URL( location.href ), initMode = originalUrl.searchParams.get( 'diffmode' ) || mw.user.options.get( 'visualeditor-diffmode-historical' ) || 'source', + initType = originalUrl.searchParams.get( 'diff-type' ), conf = mw.config.get( 'wgVisualEditorConfig' ), pluginModules = conf.pluginModules.filter( mw.loader.getState ); @@ -45,6 +46,11 @@ $wikitextDiffBody.toggleClass( 'oo-ui-element-hidden', isVisual ); var $revSlider = $( '.mw-revslider-container' ); $revSlider.toggleClass( 've-init-mw-diffPage-revSlider-visual', isVisual ); + if ( initType === 'inline' ) { + $( 'body' ) + .toggleClass( 'mw-diff-type-not-inline', isVisual ) + .toggleClass( 'mw-diff-type-inline', !isVisual ); + } if ( isVisual ) { // Highlight the headers using the same styles as the diff, to better indicate // the meaning of headers when not using two-column diff.