From: Ed Sanders Date: Fri, 30 Sep 2016 19:38:19 +0000 (-0400) Subject: Add an option to the title widget to exclude the current page X-Git-Tag: 1.31.0-rc.0~5210^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=d90a89fa83acd019cbfac221e9e2c2df0b6af6f5;p=lhc%2Fweb%2Fwiklou.git Add an option to the title widget to exclude the current page Useful when suggesting links, as linking to the current page is discouraged. Bug: T147050 Change-Id: Ieade9d0ffc05b358df6af0b65d58e60f5b87577e --- diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js index 17324076c3..b25b2d492f 100644 --- a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js +++ b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js @@ -33,6 +33,7 @@ * @cfg {boolean} [showRedlink] Show red link to exact match if it doesn't exist * @cfg {boolean} [showImages] Show page images * @cfg {boolean} [showDescriptions] Show page descriptions + * @cfg {boolean} [excludeCurrentPage] Exclude the current page from suggestions * @cfg {boolean} [validateTitle=true] Whether the input must be a valid title (if set to true, * the widget will marks itself red for invalid inputs, including an empty query). * @cfg {Object} [cache] Result cache which implements a 'set' method, taking keyed values as an argument @@ -54,6 +55,7 @@ this.showRedlink = !!config.showRedlink; this.showImages = !!config.showImages; this.showDescriptions = !!config.showDescriptions; + this.excludeCurrentPage = !!config.excludeCurrentPage; this.validateTitle = config.validateTitle !== undefined ? config.validateTitle : true; this.cache = config.cache; @@ -162,6 +164,7 @@ */ mw.widgets.TitleWidget.prototype.getOptionsFromData = function ( data ) { var i, len, index, pageExists, pageExistsExact, suggestionPage, page, redirect, redirects, + currentPageName = new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getPrefixedText(), items = [], titles = [], titleObj = mw.Title.newFromText( this.getQueryValue() ), @@ -178,6 +181,10 @@ for ( index in data.pages ) { suggestionPage = data.pages[ index ]; + // When excludeCurrentPage is set, don't list the current page unless the user has type the full title + if ( this.excludeCurrentPage && suggestionPage.title === currentPageName && suggestionPage.title !== titleObj.getPrefixedText() ) { + continue; + } pageData[ suggestionPage.title ] = { missing: suggestionPage.missing !== undefined, redirect: suggestionPage.redirect !== undefined,