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 0000000..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: I7871b83aed492292392a5c3d008c9f82e50eed86
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits