Merge "MWTemplateTitleInputWidget: Filter out templates named '…/doc'"

This commit is contained in:
jenkins-bot 2019-01-31 22:29:51 +00:00 committed by Gerrit Code Review
commit dae36e4ea1
2 changed files with 22 additions and 3 deletions

View file

@ -1986,6 +1986,7 @@
],
"messages": [
"quotation-marks",
"templatedata-doc-subpage",
"visualeditor-changedesc-mwtransclusion",
"visualeditor-dialog-template-title",
"visualeditor-dialog-transclusion-add-content",

View file

@ -48,12 +48,15 @@ OO.inheritClass( ve.ui.MWTemplateTitleInputWidget, mw.widgets.TitleInputWidget )
ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
var widget = this,
originalResponse,
templateDataMessage = mw.message( 'templatedata-doc-subpage' ),
templateDataInstalled = templateDataMessage.exists(),
templateDocPageFragment = '/' + templateDataMessage.text(),
promise = ve.ui.MWTemplateTitleInputWidget.super.prototype.getLookupRequest.call( this );
if ( this.showTemplateDescriptions ) {
return promise
.then( function ( response ) {
var xhr, pageId, index, redirIndex,
var xhr, pageId, redirIndex,
redirects = ( response.query && response.query.redirects ) || {},
origPages = ( response.query && response.query.pages ) || {},
newPages = [],
@ -77,10 +80,24 @@ ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
}
}
for ( index in newPages ) {
titles.push( newPages[ index ].title );
// T54448: Filter out matches which end in /doc or as configured on-wiki
if ( templateDataInstalled ) {
newPages = newPages.filter( function ( page ) {
// Can't use String.endsWith() as that's ES6.
// page.title.endsWith( templateDocPageFragment )
return page.title.slice( 0 - templateDocPageFragment.length ) !== templateDocPageFragment;
} );
} else {
// Even if not filtering /doc, collapse the sparse array
newPages = newPages.filter( function ( page ) {
return page;
} );
}
titles = newPages.map( function ( page ) {
return page.title;
} );
ve.setProp( response, 'query', 'pages', newPages );
originalResponse = response; // lie!
@ -105,6 +122,7 @@ ve.ui.MWTemplateTitleInputWidget.prototype.getLookupRequest = function () {
// Look for descriptions and cache them
for ( index in pages ) {
page = pages[ index ];
if ( page.missing ) {
// Remmeber templates that don't exist in the link cache
// { title: { missing: true|false }