From 872679aeec3f2135e00130d2f34baa5a74b8be73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Mon, 29 May 2023 02:12:08 +0200 Subject: [PATCH] =?UTF-8?q?DesktopArticleTarget.init:=20Support=20'&editin?= =?UTF-8?q?tro=3D=E2=80=A6'=20in=20edit=20links?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Support gadgets adding '&editintro=…' to the default edit link. It was already supported when opening the link in a new window, or following an external link, or when clicking a section edit link. Also, clean up these parameters when leaving the editor. This also applies to 'preload', 'preloadparams', 'preloadtitle', 'summary'. KNOWN BUG: Only works the first time the editor is loaded on the page. Afterwards, DesktopArticleTarget.init lets DesktopArticleTarget handle initialization, and it ignores extra parameters. I made a few attempts at fixing this, but I only broke it further. I don't understand why the history handling code even works. Maybe I'll come back to this. Bug: T56029 Change-Id: I38fcde573f728250aaa125b391815e7fac7df362 --- .../ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js | 7 +++++++ .../ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js | 8 ++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js index 9fead040df..378a78d92c 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -1170,6 +1170,13 @@ ve.init.mw.DesktopArticleTarget.prototype.restorePage = function () { url.searchParams.delete( 'oldid' ); } + // Remove parameters which are only intended for the editor, not for read mode + url.searchParams.delete( 'editintro' ); + url.searchParams.delete( 'preload' ); + url.searchParams.delete( 'preloadparams[]' ); + url.searchParams.delete( 'preloadtitle' ); + url.searchParams.delete( 'summary' ); + // If there are any other query parameters left, re-use that URL object. // Otherwise use the canonical style view URL (T44553, T102363). var keys = []; diff --git a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js index b4efe7b72a..ec16f98c3f 100644 --- a/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js +++ b/modules/ve-mw/preinit/ve.init.mw.DesktopArticleTarget.init.js @@ -645,10 +645,10 @@ // way to do this. See also similar code in the DesktopArticleTarget constructor. history.replaceState( { tag: 'visualeditor' }, '', url ); // Set action=edit or veaction=edit/editsource - history.pushState( { tag: 'visualeditor' }, '', mode === 'source' ? veEditSourceUrl : veEditUrl ); - + // Use linkUrl to preserve parameters like 'editintro' (T56029) + history.pushState( { tag: 'visualeditor' }, '', linkUrl || ( mode === 'source' ? veEditSourceUrl : veEditUrl ) ); // Update URL instance - url = veEditUrl; + url = linkUrl || veEditUrl; } activateTarget( mode, section, undefined, modified ); @@ -1282,7 +1282,7 @@ // back button from breaking when used to exit VE. FIXME: there should be a better // way to do this. See also similar code in the DesktopArticleTarget constructor. history.replaceState( { tag: 'visualeditor' }, '', url ); - // Use linkUrl + // Use linkUrl to preserve the 'section' parameter and others like 'editintro' (T56029) history.pushState( { tag: 'visualeditor' }, '', linkUrl ); } // Update URL instance