Amire80 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/245583
Change subject: Handle invalid title when loading the source
......................................................................
Handle invalid title when loading the source
Bug: T111544
Change-Id: I8bfe01abe8e967d8f8c87876884f21ffeab3240b
---
M modules/source/ext.cx.source.js
1 file changed, 26 insertions(+), 21 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ContentTranslation
refs/changes/83/245583/1
diff --git a/modules/source/ext.cx.source.js b/modules/source/ext.cx.source.js
index 82c9bb4..2ab5b78 100644
--- a/modules/source/ext.cx.source.js
+++ b/modules/source/ext.cx.source.js
@@ -19,6 +19,7 @@
function ContentTranslationSource( element, siteMapper, options ) {
this.$container = $( element );
this.siteMapper = siteMapper;
+ this.title = null;
this.options = $.extend( true, {}, $.fn.cxSource.defaults,
options );
this.$title = null;
@@ -29,6 +30,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 +39,14 @@
mw.hook( 'mw.cx.error.anonuser' ).fire();
return;
}
- if ( !mw.cx.sourceTitle || !mw.cx.sourceLanguage ||
!mw.cx.targetLanguage ) {
+
+ this.title = mw.Title.newFromText( mw.cx.sourceTitle );
+
+ if ( !mw.cx.sourceTitle ||
+ !mw.cx.sourceLanguage ||
+ !mw.cx.targetLanguage ||
+ ( this.title === null )
+ ) {
this.showDashboard();
return;
}
@@ -89,33 +98,29 @@
* Render the source content column.
*/
ContentTranslationSource.prototype.render = function () {
- var sourceLanguageDir, title, namespace,
+ var namespace, sourceLanguageDir,
$languageLabel, $articleLink, userLanguage, $subHeading;
+
+ if ( this.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 +
this.title.getNameText();
+ } else {
+ // In the main space, normalize simply
+ mw.cx.sourceTitle = this.title.getPrefixedText();
+ }
sourceLanguageDir = $.uls.data.getDir( mw.cx.sourceLanguage );
this.$container.prop( {
lang: mw.cx.sourceLanguage,
dir: sourceLanguageDir
} );
-
- title = mw.Title.newFromText( mw.cx.sourceTitle );
-
- 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();
- }
- }
this.$title = $( '<h2>' )
.attr( {
--
To view, visit https://gerrit.wikimedia.org/r/245583
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bfe01abe8e967d8f8c87876884f21ffeab3240b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/ContentTranslation
Gerrit-Branch: master
Gerrit-Owner: Amire80 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits