Petar.petkovic has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/393230 )

Change subject: Make mw.widget.TitleWidget results more flexible
......................................................................

Make mw.widget.TitleWidget results more flexible

* Factor out addition of exact input query to mw.widget.TitleWidget results,
enabling subclasses to make it optional.

Change-Id: Ic7a3aaf38a3827917e4d349cc6b828f37cc64b67
---
M resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
1 file changed, 29 insertions(+), 22 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/30/393230/1

diff --git a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js 
b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
index 83a2612..1f807bb 100644
--- a/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
+++ b/resources/src/mediawiki.widgets/mw.widgets.TitleWidget.js
@@ -211,7 +211,7 @@
         * @return {OO.ui.OptionWidget[]} Menu items
         */
        mw.widgets.TitleWidget.prototype.getOptionsFromData = function ( data ) 
{
-               var i, len, index, pageExists, pageExistsExact, suggestionPage, 
page, redirect, redirects,
+               var i, len, index, suggestionPage, page, redirect, redirects,
                        currentPageName = new mw.Title( mw.config.get( 
'wgRelevantPageName' ) ).getPrefixedText(),
                        items = [],
                        titles = [],
@@ -272,31 +272,12 @@
                        return pageData[ a ].index - pageData[ b ].index;
                } );
 
-               // If not found, run value through mw.Title to avoid treating a 
match as a
-               // mismatch where normalisation would make them matching 
(T50476)
-
-               pageExistsExact = (
-                       Object.prototype.hasOwnProperty.call( pageData, 
this.getQueryValue() ) &&
-                       (
-                               !pageData[ this.getQueryValue() ].missing ||
-                               pageData[ this.getQueryValue() ].known
-                       )
-               );
-               pageExists = pageExistsExact || (
-                       titleObj &&
-                       Object.prototype.hasOwnProperty.call( pageData, 
titleObj.getPrefixedText() ) &&
-                       (
-                               !pageData[ titleObj.getPrefixedText() ].missing 
||
-                               pageData[ titleObj.getPrefixedText() ].known
-                       )
-               );
-
                if ( this.cache ) {
                        this.cache.set( pageData );
                }
 
-               // Offer the exact text as a suggestion if the page exists
-               if ( pageExists && !pageExistsExact ) {
+               if ( this.shouldAddQueryInput( pageData ) ) {
+                       // Offer the exact text as a suggestion if the page 
exists
                        titles.unshift( this.getQueryValue() );
                }
 
@@ -319,6 +300,32 @@
        };
 
        /**
+        * Determines whether exact input query should be added to the 
suggestions.
+        *
+        * @param {Array} pageData
+        * @return {boolean} True if exact user input query should be added to 
the suggestions.
+        */
+       mw.widgets.TitleWidget.prototype.shouldAddQueryInput = function ( 
pageData ) {
+               var queryValue = this.getQueryValue(),
+                       titleObj = mw.Title.newFromText( queryValue );
+
+               if ( !titleObj ) {
+                       return false;
+               }
+
+               function pageExists( title ) {
+                       return Object.prototype.hasOwnProperty.call( pageData, 
title ) &&
+                               (
+                                       !pageData[ title ].missing ||
+                                       pageData[ title ].known
+                               );
+               }
+
+               // We want normalized page to exist, and page exact to input 
query NOT to exist in pageData
+               return pageExists( titleObj.getPrefixedText() ) && !pageExists( 
queryValue );
+       };
+
+       /**
         * Get menu option widget data from the title and page data
         *
         * @param {string} title Title object

-- 
To view, visit https://gerrit.wikimedia.org/r/393230
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic7a3aaf38a3827917e4d349cc6b828f37cc64b67
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Petar.petkovic <ppetko...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to