Use mw.Title#getRelativeText to deal with titles relative to specific namespaces

Added in MW core in Ie554adef, was backported to 1.24.

Change-Id: Iedc0319042529d41d29846d1734b5481850e9552
This commit is contained in:
Alex Monk 2014-09-22 18:48:42 +01:00 committed by Catrope
parent ab3474f032
commit ef1cebd111
5 changed files with 6 additions and 33 deletions

View file

@ -17,7 +17,7 @@ class VisualEditorHooks {
// parties who attempt to install VisualEditor onto non-alpha wikis, as
// this should have no impact on deploying to Wikimedia's wiki cluster;
// is fine for release tarballs because 1.22wmf11 < 1.22alpha < 1.22.0.
wfUseMW( '1.24wmf20' );
wfUseMW( '1.24' );
}
/**

View file

@ -63,13 +63,7 @@ ve.ce.MWTransclusionNode.static.getDescription = function ( model ) {
.map( function ( template ) {
var title = mw.Title.newFromText( template, mw.config.get( 'wgNamespaceIds' ).template );
if ( title ) {
if ( title.getNamespaceId() === 10 ) {
return title.getMainText();
} else if ( title.getNamespaceId() === 0 ) {
return ':' + title.getPrefixedText();
} else {
return title.getPrefixedText();
}
return title.getRelativeText( 10 );
} else {
return template;
}

View file

@ -123,15 +123,7 @@ ve.dm.MWTemplateSpecModel.prototype.getLabel = function () {
try {
// Normalize and remove namespace prefix if in the Template: namespace
titleObj = new mw.Title( title );
if ( titleObj.getNamespaceId() === 10 ) {
// Template namespace, remove namespace prefix
title = titleObj.getMainText();
} else if ( titleObj.getNamespaceId() === 0 ) {
title = ':' + titleObj.getPrefixedText();
} else {
// Other namespace, already has a prefix
title = titleObj.getPrefixedText();
}
title = titleObj.getRelativeText( 10 );
} catch ( e ) { }
}

View file

@ -17,7 +17,7 @@
* @param {Object} [config] Configuration options
*/
ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
var title, titleText;
var title;
// Configuration initialization
config = ve.extendObject( {
@ -68,18 +68,11 @@ ve.ui.MWTemplatePage = function VeUiMWTemplatePage( template, name, config ) {
title = mw.Title.newFromText( title );
}
if ( title ) {
if ( title.getNamespaceId() === 10 ) {
titleText = title.getMainText();
} else if ( title.getNamespaceId() === 0 ) {
titleText = ':' + title.getPrefixedText();
} else {
titleText = title.getPrefixedText();
}
this.$description
.addClass( 've-ui-mwTemplatePage-description-missing' )
.append( ve.msg(
'visualeditor-dialog-transclusion-no-template-description',
titleText,
title.getRelativeText( 10 ),
ve.getHtmlAttributes( { target: '_blank', href: title.getUrl() } ),
mw.user
) );

View file

@ -112,13 +112,7 @@ ve.ui.MWTitleInputWidget.prototype.getLookupMenuItemsFromData = function ( data
title = new mw.Title( matchingPages[i] );
linkCacheUpdate[matchingPages[i]] = { missing: false };
if ( this.namespace !== null ) {
if ( title.getNamespaceId() === this.namespace ) {
value = title.getMainText();
} else if ( title.getNamespaceId() === 0 ) {
value = ':' + title.getPrefixedText();
} else {
value = title.getPrefixedText();
}
value = title.getRelativeText( this.namespace );
} else {
value = title.getPrefixedText();
}