[MediaWiki-commits] [Gerrit] mediawiki...PageAssessments[master]: Add autocompletion to search fields
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/326894 ) Change subject: Add autocompletion to search fields .. Add autocompletion to search fields Add autocompletion (using jquery.suggestions) to the 'Project' and 'Page title' search fields on the PageAssessments special page. Bug: T152758 Change-Id: I7871b83aed492292392a5c3d008c9f82e50eed86 --- M .jshintrc M extension.json A modules/ext.pageassessments.special.js M src/SpecialPage.php 4 files changed, 89 insertions(+), 2 deletions(-) Approvals: jenkins-bot: Verified Kaldari: Looks good to me, approved diff --git a/.jshintrc b/.jshintrc index fe6e40e..6c9a3d6 100644 --- a/.jshintrc +++ b/.jshintrc @@ -16,5 +16,11 @@ "globals": { "mw": false, "$": false - } + }, + + "predef": [ +"jQuery", +"mediaWiki", +"OO" + ] } diff --git a/extension.json b/extension.json index 3fdfa11..09d6aa1 100644 --- a/extension.json +++ b/extension.json @@ -53,6 +53,15 @@ "localBasePath": "", "remoteExtPath": "examples/PageAssessments" }, + "ResourceModules": { + "ext.pageassessments.special": { + "scripts": "modules/ext.pageassessments.special.js", + "dependencies": [ + "oojs-ui-core", + "jquery.suggestions" + ] + } + }, "SpecialPages": { "PageAssessments": "PageAssessments\\SpecialPage" }, diff --git a/modules/ext.pageassessments.special.js b/modules/ext.pageassessments.special.js new file mode 100644 index 000..d9a8129 --- /dev/null +++ b/modules/ext.pageassessments.special.js @@ -0,0 +1,49 @@ +( function ( $, mw, OO ) { + + /** +* Page title autocompletion. +*/ + $( 'input[name="page_title"]' ).suggestions( { + fetch: function ( userInput, response, maxRows ) { + var apiParams, request, + node = this[ 0 ], + namespace = OO.ui.infuse( 'pageassessments-namespace' ), + api = new mw.Api(); + apiParams = { + action: 'opensearch', + namespace: namespace.getValue(), + search: userInput, + limit: maxRows + }; + request = api.get( apiParams ) + .done( function ( data ) { + response( data[ 1 ] ); + } ); + $.data( node, 'request', request ); + }, + cancel: function () { + var node = this[ 0 ], + request = $.data( node, 'request' ); + if ( request ) { + request.abort(); + $.removeData( node, 'request' ); + } + } + } ); + + /** +* Project name autocompletion. +*/ + $( 'input[name="project"]' ).suggestions( { + fetch: function ( userInput, response, maxRows ) { + var projects = []; + $.each( mw.config.get( 'wgPageAssessmentProjects' ), function ( index, value ) { + if ( value.substring( 0, userInput.length ).toLocaleLowerCase() === userInput.toLocaleLowerCase() ) { + projects.push( value ); + } + } ); + response( projects.slice( 0, maxRows ) ); + } + } ); + +} )( jQuery, mediaWiki, OO ); diff --git a/src/SpecialPage.php b/src/SpecialPage.php index 692c857..262b8c7 100644 --- a/src/SpecialPage.php +++ b/src/SpecialPage.php @@ -255,27 +255,50 @@ } /** -* Get the search form. +* Get the search form. This also loads the required Javascript module and global JS variable. * @return HTMLForm */ protected function getForm() { + $this->getOutput()->addModules( 'ext.pageassessments.special' ); + + // Add a list of all currently-used projects to the page's JS. + $projects = wfGetDB( DB_SLAVE )->select( + [ 'page_assessments_projects', 'page_assessments' ], + 'pap_project_title', + '', + __METHOD__, + [ 'ORDER BY' => 'pap_project_title' ], + [ 'page_assessments_projects' => [ 'JOIN', 'pa_project_id = pap_project_id' ] ] + ); + $projectOptions = []; +
[MediaWiki-commits] [Gerrit] mediawiki...PageAssessments[master]: Add autocompletion to search fields
Samwilson has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/326894 ) Change subject: Add autocompletion to search fields .. Add autocompletion to search fields Add autocompletion (using jquery.suggestions) to the Project and Page search fields on the PageAssessments special page. Change-Id: I7871b83aed492292392a5c3d008c9f82e50eed86 --- M extension.json A modules/ext.pageassessments.js M src/NamespaceSelect.php M src/SpecialPage.php 4 files changed, 43 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageAssessments refs/changes/94/326894/1 diff --git a/extension.json b/extension.json index 015c803..fbc9179 100644 --- a/extension.json +++ b/extension.json @@ -51,6 +51,12 @@ "localBasePath": "", "remoteExtPath": "examples/PageAssessments" }, + "ResourceModules": { + "ext.pageassessments": { + "scripts": "modules/ext.pageassessments.js", + "dependencies": "jquery.suggestions" + } + }, "SpecialPages": { "PageAssessments": "PageAssessments\\SpecialPage" }, diff --git a/modules/ext.pageassessments.js b/modules/ext.pageassessments.js new file mode 100644 index 000..c3402aa --- /dev/null +++ b/modules/ext.pageassessments.js @@ -0,0 +1,30 @@ +( function ( $, mw, OO ) { + + var config = { + + fetch: function ( userInput, response, maxRows ) { + var node = this[ 0 ], + namespace = OO.ui.infuse( 'pageassessments-namespace' ), + api = api || new mw.Api(); + $.data( node, 'request', api.get( { + action: 'opensearch', + namespace: namespace.getValue(), + search: userInput + } ).done( function ( data ) { + response( data[ 1 ] ); + } ) ); + }, + + cancel: function () { + var node = this[ 0 ], + request = $.data( node, 'request' ); + if ( request ) { + request.abort(); + $.removeData( node, 'request' ); + } + } + }; + + $( 'input[name="page_title"]' ).suggestions( config ); + +} )( jQuery, mediaWiki, OO ); diff --git a/src/NamespaceSelect.php b/src/NamespaceSelect.php index 49a09b4..864fac3 100644 --- a/src/NamespaceSelect.php +++ b/src/NamespaceSelect.php @@ -21,9 +21,9 @@ */ public function getInputOOUI( $value ) { $nsIds = array_keys( MWNamespace::getCanonicalNamespaces() ); - $excludedNsIds = array_filter( $nsIds, function( $ns ) { + $excludedNsIds = array_values( array_filter( $nsIds, function( $ns ) { return MWNamespace::isTalk( $ns ); - } ); + } ) ); $widget = new NamespaceInputWidget( [ 'value' => $value, 'name' => $this->mName, diff --git a/src/SpecialPage.php b/src/SpecialPage.php index 692c857..70da1a1 100644 --- a/src/SpecialPage.php +++ b/src/SpecialPage.php @@ -3,6 +3,7 @@ namespace PageAssessments; use Html; +use HTMLComboboxField; use HTMLForm; use HTMLTextField; use IDatabase; @@ -259,18 +260,22 @@ * @return HTMLForm */ protected function getForm() { + $this->getOutput()->addModules( 'ext.pageassessments' ); $formDescriptor = [ 'project' => [ + 'id' => 'pageassessments-project', 'class' => HTMLTextField::class, 'name' => 'project', 'label-message' => 'pageassessments-project', ], 'namespace' => [ + 'id' => 'pageassessments-namespace', 'class' => NamespaceSelect::class, 'name' => 'namespace', 'label-message' => 'pageassessments-page-namespace', ], 'page_title' => [ + 'id' => 'pageassessments-page-title', 'class' => HTMLTextField::class, 'name' => 'page_title', 'label-message' => 'pageassessments-page-title', -- To view, visit https://gerrit.wikimedia.org/r/326894 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: