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 0000000..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 = [];
+ foreach ( $projects as $project ) {
+ $projectOptions[] = $project->pap_project_title;
+ }
+ $this->getOutput()->addJsConfigVars(
'wgPageAssessmentProjects', $projectOptions );
+
+ // Define the form fields.
$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',
],
];
+
+ // Construct and return the form.
$form = HTMLForm::factory( 'ooui', $formDescriptor,
$this->getContext() );
$form->setMethod( 'get' );
$form->setSubmitTextMsg( 'pageassessments-search' );
--
To view, visit https://gerrit.wikimedia.org/r/326894
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I7871b83aed492292392a5c3d008c9f82e50eed86
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Samwilson <[email protected]>
Gerrit-Reviewer: Fomafix <[email protected]>
Gerrit-Reviewer: Kaldari <[email protected]>
Gerrit-Reviewer: Samwilson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits