Fix logic in link input widget

Previously pageExists thought matchingPages was an indexed object when
in fact it was an array. This didn't manifest as a bug as we subsequently
check the normalised URL in the correct manner (using indexOf), but it
did remove the optimisation of not running mw.Title if there was an exact match.

Change-Id: Ic616cbfa0d7ed5447e032dd1f772779db2dc19e5
This commit is contained in:
Ed Sanders 2013-06-21 16:42:54 +01:00
parent 1ea9016cf8
commit 51be472159

View file

@ -96,7 +96,11 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuItemsFromData = function (
menu$$ = this.lookupMenu.$$, menu$$ = this.lookupMenu.$$,
items = [], items = [],
matchingPages = data, matchingPages = data,
pageExists = this.value in matchingPages; // If not found, run value through mw.Title to avoid treating a match as a
// mismatch where normalisation would make them matching (bug 48476)
pageExists =
ve.indexOf( this.value, matchingPages ) !== -1 ||
ve.indexOf( new mw.Title( this.value ).getPrefixedText(), matchingPages ) !== -1;
// External link // External link
if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value ) ) { if ( ve.init.platform.getExternalLinkUrlProtocolsRegExp().test( this.value ) ) {
@ -111,15 +115,7 @@ ve.ui.MWLinkTargetInputWidget.prototype.getLookupMenuItemsFromData = function (
} }
// Internal link // Internal link
if ( if ( !pageExists ) {
!pageExists &&
(
!matchingPages ||
// Run value through mw.Title to avoid treating a match as a mismatch where
// normalisation would make them matching (bug 48476)
matchingPages.indexOf( new mw.Title( this.value ).getPrefixedText() ) === -1
)
) {
items.push( new ve.ui.MenuSectionItemWidget( items.push( new ve.ui.MenuSectionItemWidget(
'newPage', 'newPage',
{ '$$': menu$$, 'label': ve.msg( 'visualeditor-linkinspector-suggest-new-page' ) } { '$$': menu$$, 'label': ve.msg( 'visualeditor-linkinspector-suggest-new-page' ) }