jenkins-bot has submitted this change and it was merged.
Change subject: Handle invalid title when loading the source
......................................................................
Handle invalid title when loading the source
This is not supposed to happen in the first place,
because the title is supposed to be validated by
the page selector, but it can be checked to be on the safe side.
To test, add a '[' key to mw.cx.sourceTitle
Bug: T111544
Change-Id: I8bfe01abe8e967d8f8c87876884f21ffeab3240b
---
M modules/source/ext.cx.source.js
1 file changed, 19 insertions(+), 16 deletions(-)
Approvals:
Santhosh: Looks good to me, approved
jenkins-bot: Verified
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 82c9bb4..c55def8 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -29,6 +29,7 @@
ContentTranslationSource.prototype.init = function () {
var query = new mw.Uri().query;
+
mw.cx.sourceTitle = query.page;
mw.cx.targetLanguage = query.to;
mw.cx.sourceLanguage = query.from;
@@ -37,7 +38,12 @@
mw.hook( 'mw.cx.error.anonuser' ).fire();
return;
}
- if ( !mw.cx.sourceTitle || !mw.cx.sourceLanguage ||
!mw.cx.targetLanguage ) {
+
+ if ( !mw.cx.sourceTitle ||
+ !mw.cx.sourceLanguage ||
+ !mw.cx.targetLanguage ||
+ ( mw.Title.newFromText( mw.cx.sourceTitle ) === null )
+ ) {
this.showDashboard();
return;
}
@@ -99,22 +105,19 @@
} );
title = mw.Title.newFromText( mw.cx.sourceTitle );
+ if ( title.getNamespaceId() ) { // Non-main
+ // mw.Title's getPrefixedText() adds the localized
namespace name,
+ // but it's localized for the current wiki's content
language,
+ // and here we need the source. See
+ // https://phabricator.wikimedia.org/T86744
+ // Avoid this problem for non-main-space pages by taking
+ // the namespace name from the current source title.
+ namespace = mw.cx.sourceTitle.match( '.+?:' )[ 0 ];
- if ( title ) {
- if ( title.getNamespaceId() ) { // Non-main
- // mw.Title's getPrefixedText() adds the
localized namespace name,
- // but it's localized for the current wiki's
content language,
- // and here we need the source. See
- // https://phabricator.wikimedia.org/T86744
- // Avoid this problem for non-main-space pages
by taking
- // the namespace name from the current source
title.
- namespace = mw.cx.sourceTitle.match( '.+?:' )[
0 ];
-
- mw.cx.sourceTitle = namespace +
title.getNameText();
- } else {
- // In the main space, normalize simply
- mw.cx.sourceTitle = title.getPrefixedText();
- }
+ mw.cx.sourceTitle = namespace + title.getNameText();
+ } else {
+ // In the main space, normalize simply
+ mw.cx.sourceTitle = title.getPrefixedText();
}
this.$title = $( '<h2>' )
--
To view, visit https://gerrit.wikimedia.org/r/245583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8bfe01abe8e967d8f8c87876884f21ffeab3240b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Nikerabbit <[email protected]>
Gerrit-Reviewer: Santhosh <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits