Pablo Grass (WMDE) has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/366566 )
Change subject: SubPageFeedback: Add indication on page missing - WIP
......................................................................
SubPageFeedback: Add indication on page missing - WIP
Extends the "Subpages of this page" filter field by an error message if
the specified page name does not match an existing page, and the actual
search - if performed - thus will not be able to yield results.
T170280
Change-Id: If8cf41e9931eb48258930559bab933753718e916
---
M extension.json
M modules/ext.advancedSearch.init.js
A modules/handler/ext.advancedSearch.handler.SubPageFeedback.js
3 files changed, 83 insertions(+), 2 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AdvancedSearch
refs/changes/66/366566/1
diff --git a/extension.json b/extension.json
index 63c8fc5..67d286d 100644
--- a/extension.json
+++ b/extension.json
@@ -81,6 +81,7 @@
"ext.advancedSearch.util",
"ext.advancedSearch.dm.MenuDataModel",
"ext.advancedSearch.dm.SearchModel",
+ "ext.advancedSearch.handler.SubPageFeedback",
"ext.advancedSearch.ui.ArbitraryWordInput",
"ext.advancedSearch.ui.FileTypeSelection",
"ext.advancedSearch.ui.ExpandablePane",
@@ -94,6 +95,13 @@
"ext.advancedSearch.ui.TextInput"
]
},
+ "ext.advancedSearch.handler.SubPageFeedback": {
+ "scripts": [
+
"modules/handler/ext.advancedSearch.handler.SubPageFeedback.js"
+ ],
+ "dependencies": [
+ ]
+ },
"ext.advancedSearch.ui.ArbitraryWordInput": {
"scripts": [
"modules/ui/ext.advancedSearch.ArbitraryWordInput.js"
diff --git a/modules/ext.advancedSearch.init.js
b/modules/ext.advancedSearch.init.js
index f115cb2..2c01625 100644
--- a/modules/ext.advancedSearch.init.js
+++ b/modules/ext.advancedSearch.init.js
@@ -192,9 +192,26 @@
id: 'subpage',
placeholder: 'prefix:…',
formatter: function ( val ) {
- return 'prefix:' + val;
+ return 'prefix:' + val.replace( /^\/+|\/+$/g,
'' ) + '/';
},
- greedy: true
+ greedy: true,
+ layout: function ( widget, option ) {
+ var fieldLayout = new OO.ui.FieldLayout(
widget, {
+ label: mw.msg( 'advancedsearch-field-'
+ option.id ),
+ align: 'right'
+ } );
+ var handler = new
mw.libs.advancedSearch.handler.SubPageFeedback(
+ fieldLayout,
+ option.formatter,
+ new mw.Api(),
+ state,
+ 400,
+ mw.msg(
'advancedsearch-error-missing-subpages' )
+ );
+ widget.connect( handler, { change: 'onChange' }
);
+
+ return fieldLayout;
+ }
},
{
group: 'structure',
diff --git a/modules/handler/ext.advancedSearch.handler.SubPageFeedback.js
b/modules/handler/ext.advancedSearch.handler.SubPageFeedback.js
new file mode 100644
index 0000000..ca780bd
--- /dev/null
+++ b/modules/handler/ext.advancedSearch.handler.SubPageFeedback.js
@@ -0,0 +1,56 @@
+( function ( mw ) {
+ 'use strict';
+
+ mw.libs = mw.libs || {};
+ mw.libs.advancedSearch = mw.libs.advancedSearch || {};
+ mw.libs.advancedSearch.handler = mw.libs.advancedSearch.handler || {};
+
+ /**
+ * @param {OO.ui.FieldLayout} fieldLayout
+ * @param {function} valueFormatter
+ * @param {mw.Api} api
+ * @param {ext.advancedSearch.dm.SearchModel} store
+ * @param {integer} delay
+ * @param {string} errorMessage
+ * @constructor
+ */
+ mw.libs.advancedSearch.handler.SubPageFeedback = function (
fieldLayout, valueFormatter, api, store, delay, errorMessage ) {
+ this.fieldLayout = fieldLayout;
+ this.valueFormatter = valueFormatter;
+ this.api = api;
+ this.store = store;
+ this.delay = delay;
+ this.errorMessage = errorMessage;
+
+ this.apiThrottle = null;
+ };
+
+ mw.libs.advancedSearch.handler.SubPageFeedback.prototype.onChange =
function ( value ) {
+ clearTimeout( this.apiThrottle );
+
+ if ( value.trim() === '' ) {
+ this.showError( false );
+ return;
+ }
+
+ this.apiThrottle = setTimeout( this.queryApi.bind( this ),
this.delay, value );
+ };
+
+ mw.libs.advancedSearch.handler.SubPageFeedback.prototype.queryApi =
function ( value ) {
+ this.api.get( {
+ action: 'query',
+ list: 'search',
+ srnamespace: this.store.getNamespaces().join( '|' ),
+ srsearch: this.valueFormatter( value )
+ } ).done( this.onSearchResult.bind( this ) );
+ };
+
+ mw.libs.advancedSearch.handler.SubPageFeedback.prototype.onSearchResult
= function ( data ) {
+ this.showError( ( data.query.searchinfo.totalhits === 0 ) );
+ };
+
+ mw.libs.advancedSearch.handler.SubPageFeedback.prototype.showError =
function ( isError ) {
+ this.fieldLayout.setErrors( isError ? [ this.errorMessage ] :
[] );
+ };
+
+}( mediaWiki ) );
--
To view, visit https://gerrit.wikimedia.org/r/366566
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: If8cf41e9931eb48258930559bab933753718e916
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/AdvancedSearch
Gerrit-Branch: master
Gerrit-Owner: Pablo Grass (WMDE) <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits