From 09fec16583212834ef54111f1ce359ab2cff3790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20Dziewo=C5=84ski?= Date: Thu, 1 Jun 2023 00:09:29 +0200 Subject: [PATCH] Don't try to prefix browser title if a custom message is incompatible Some wikis customize the 'pagetitle' in ways that are not compatible with the client-side message parser. Depends-On: If1979da12777e4ee4e97937640fc5e6176f9b5fe Bug: T317600 Change-Id: Ie7c1813552582e10de9e57cd8d772c2134146289 --- .../ve.init.mw.DesktopArticleTarget.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 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 378a78d92c..12b62015f8 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js +++ b/modules/ve-mw/init/targets/ve.init.mw.DesktopArticleTarget.js @@ -985,24 +985,32 @@ ve.init.mw.DesktopArticleTarget.prototype.teardownToolbar = function () { */ ve.init.mw.DesktopArticleTarget.prototype.changeDocumentTitle = function () { var title = mw.Title.newFromText( this.getPageName() ); - - // Use the real title if we loaded a view page, otherwise reconstruct it - this.originalDocumentTitle = this.isViewPage ? document.title : ve.msg( 'pagetitle', title.getPrefixedText() ); - - // Reconstruct an edit title - document.title = ve.msg( 'pagetitle', + var pageTitleMsg = mw.message( 'pagetitle', ve.msg( this.pageExists ? 'editing' : 'creating', title.getPrefixedText() ) ); + + // T317600 + if ( pageTitleMsg.isParseable() ) { + // Use the real title if we loaded a view page, otherwise reconstruct it + this.originalDocumentTitle = this.isViewPage ? document.title : ve.msg( 'pagetitle', title.getPrefixedText() ); + // Reconstruct an edit title + document.title = pageTitleMsg.text(); + } else { + mw.log.warn( 'VisualEditor: MediaWiki:Pagetitle contains unsupported syntax. ' + + 'https://www.mediawiki.org/wiki/Manual:Messages_API#Feature_support_in_JavaScript' ); + } }; /** * Restore the original document title. */ ve.init.mw.DesktopArticleTarget.prototype.restoreDocumentTitle = function () { - document.title = this.originalDocumentTitle; + if ( this.originalDocumentTitle ) { + document.title = this.originalDocumentTitle; + } }; /**