From 0071df8981b62322c5d5ab63dc55df9771e7a62b Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sat, 25 Sep 2021 12:50:01 +0000 Subject: [PATCH] EditPage: Only update title part of firstHeading on live preview The message wgEditMessage can contain code for the extension ParserFunctions which is not supported by mediawiki.jqueryMsg. This change updates only the title in the firstHeading instead of creating the whole message including the title again. The title gets identified by a new HTML element with id="firstHeadingTitle". The title in the HTML title gets not updated anymore. For a preview of the display title the title in the firstHeading should be enough. The 6 messages 'creating', 'editconflict', 'editing', 'editingcomment', 'editingsection', 'pagetitle' are not needed anymore in JavaScript and removed from the module. The global JavaScript variable 'wgEditMessage' is not needed anymore in the live preview module. Other user scripts uses this variable and therefor this variable is kept for compatibility. Bug: T105214 Change-Id: I8d8dc79c6bf1a94a55f1d0f6b5611ca478fd9e18 --- includes/EditPage.php | 10 +++++-- resources/Resources.php | 7 ----- .../mediawiki.action.edit.preview.js | 27 ++----------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index fe95ca6792d..c0ebc2ac1d4 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2662,12 +2662,18 @@ class EditPage implements IEditObject { } else { $out->setDisplayTitle( $displayTitle ); } + + // Enclose the title with an element. This is used on live preview to update the + // preview of the display title. + $displayTitle = Html::rawElement( 'span', [ 'id' => 'firstHeadingTitle' ], $displayTitle ); + $out->setPageTitle( $this->context->msg( $msg, $displayTitle ) ); $config = $this->context->getConfig(); - # Transmit the name of the message to JavaScript for live preview - # Keep Resources.php/mediawiki.action.edit.preview in sync with the possible keys + # Transmit the name of the message to JavaScript. This was added for live preview. + # Live preview doesn't use this anymore. The variable is still transmitted because + # other scripts uses this variable. $out->addJsConfigVars( [ 'wgEditMessage' => $msg, ] ); diff --git a/resources/Resources.php b/resources/Resources.php index 5866a0c658d..05a16da7a18 100644 --- a/resources/Resources.php +++ b/resources/Resources.php @@ -1290,16 +1290,9 @@ return [ 'oojs-ui-core', ], 'messages' => [ - // Keep these message keys in sync with EditPage#setHeaders 'continue-editing', - 'creating', 'currentrev', 'diff-empty', - 'editconflict', - 'editing', - 'editingcomment', - 'editingsection', - 'pagetitle', 'otherlanguages', 'summary-preview', 'subject-preview', diff --git a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js index 0f59775607f..d26621a0a46 100644 --- a/resources/src/mediawiki.action/mediawiki.action.edit.preview.js +++ b/resources/src/mediawiki.action/mediawiki.action.edit.preview.js @@ -12,7 +12,7 @@ * @param {Object} response Response data */ function parsePreviewRequest( response ) { - var indicators, newList, $displaytitle, $content, $parent, $list, arrow, $previewHeader, $wikiPreview, $editform; + var indicators, newList, $content, $parent, $list, arrow, $previewHeader, $wikiPreview, $editform; $editform = $( '#editform' ); $wikiPreview = $( '#wikiPreview' ); @@ -48,30 +48,7 @@ $( '.mw-indicators' ).empty().append( newList ); if ( response.parse.displaytitle ) { - $displaytitle = $( $.parseHTML( response.parse.displaytitle ) ); - // The following messages can be used here: - // * editconflict - // * editingcomment - // * editingsection - // * editing - // * creating - $( '#firstHeading' ).msg( - mw.config.get( 'wgEditMessage', 'editing' ), - $displaytitle - ); - document.title = mw.msg( - 'pagetitle', - // The following messages can be used here: - // * editconflict - // * editingcomment - // * editingsection - // * editing - // * creating - mw.msg( - mw.config.get( 'wgEditMessage', 'editing' ), - $displaytitle.text() - ) - ); + $( '#firstHeadingTitle' ).html( response.parse.displaytitle ); } if ( response.parse.categorieshtml ) { $content = $( $.parseHTML( response.parse.categorieshtml ) );