Gerrit Patch Uploader has uploaded a new change for review.
https://gerrit.wikimedia.org/r/175938
Change subject: Add autocompletion for tag filters
......................................................................
Add autocompletion for tag filters
On Newpages, Recentchanges, Contribs, Logs
Also adds 'contains' API option to list=tags.
Change-Id: Ic6c16a893c4b40702764d455fa21934686a8b162
---
M includes/api/ApiQueryTags.php
M includes/specials/SpecialContributions.php
M includes/specials/SpecialLog.php
M includes/specials/SpecialNewpages.php
M includes/specials/SpecialRecentchanges.php
M resources/Resources.php
A resources/src/mediawiki/mediawiki.tagSuggest.js
7 files changed, 64 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/38/175938/1
diff --git a/includes/api/ApiQueryTags.php b/includes/api/ApiQueryTags.php
index f3b2652..9e3d774 100644
--- a/includes/api/ApiQueryTags.php
+++ b/includes/api/ApiQueryTags.php
@@ -47,6 +47,8 @@
public function execute() {
$params = $this->extractRequestParams();
+ $db = $this->getDB();
+
$prop = array_flip( $params['prop'] );
$this->fld_displayname = isset( $prop['displayname'] );
@@ -60,6 +62,13 @@
$this->addFields( 'ct_tag' );
$this->addFieldsIf( array( 'hitcount' => 'COUNT(*)' ),
$this->fld_hitcount );
+
+ if ( isset( $params['contains'] ) ) {
+ $this->addWhere( 'ct_tag' . $db->buildLike(
+ $db->anyString(),
+ $params['contains'],
+ $db->anyString() ) );
+ }
$this->addOption( 'LIMIT', $this->limit + 1 );
$this->addOption( 'GROUP BY', 'ct_tag' );
@@ -145,6 +154,7 @@
ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
),
+ 'contains' => null,
'prop' => array(
ApiBase::PARAM_DFLT => 'name',
ApiBase::PARAM_TYPE => array(
diff --git a/includes/specials/SpecialContributions.php
b/includes/specials/SpecialContributions.php
index 59e2bba..03ba823 100644
--- a/includes/specials/SpecialContributions.php
+++ b/includes/specials/SpecialContributions.php
@@ -473,6 +473,8 @@
$form .= "\t" . Html::hidden( $name, $value ) . "\n";
}
+ $this->getOutput()->addModules( 'mediawiki.tagSuggest' );
+
$tagFilter = ChangeTags::buildTagFilterSelector(
$this->opts['tagfilter'] );
if ( $tagFilter ) {
diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php
index 99704a9..3f1fe89 100644
--- a/includes/specials/SpecialLog.php
+++ b/includes/specials/SpecialLog.php
@@ -48,6 +48,7 @@
$this->setHeaders();
$this->outputHeader();
$this->getOutput()->addModules( 'mediawiki.userSuggest' );
+ $this->getOutput()->addModules( 'mediawiki.tagSuggest' );
$opts = new FormOptions;
$opts->add( 'type', '' );
diff --git a/includes/specials/SpecialNewpages.php
b/includes/specials/SpecialNewpages.php
index b3b3d48..64a7645 100644
--- a/includes/specials/SpecialNewpages.php
+++ b/includes/specials/SpecialNewpages.php
@@ -200,6 +200,7 @@
protected function form() {
$out = $this->getOutput();
$out->addModules( 'mediawiki.userSuggest' );
+ $out->addModules( 'mediawiki.tagSuggest' );
// Consume values
$this->opts->consumeValue( 'offset' ); // don't carry offset,
DWIW
diff --git a/includes/specials/SpecialRecentchanges.php
b/includes/specials/SpecialRecentchanges.php
index 58b51b3..35111d1 100644
--- a/includes/specials/SpecialRecentchanges.php
+++ b/includes/specials/SpecialRecentchanges.php
@@ -488,6 +488,9 @@
parent::addModules();
$out = $this->getOutput();
$out->addModules( 'mediawiki.special.recentchanges' );
+ if ( !$this->including() ) {
+ $out->addModules( 'mediawiki.tagSuggest' );
+ }
}
/**
diff --git a/resources/Resources.php b/resources/Resources.php
index c39ba3b..9fdc7c3 100644
--- a/resources/Resources.php
+++ b/resources/Resources.php
@@ -952,6 +952,13 @@
'mediawiki.api',
),
),
+ 'mediawiki.tagSuggest' => array(
+ 'scripts' => 'resources/src/mediawiki/mediawiki.tagSuggest.js',
+ 'dependencies' => array(
+ 'jquery.suggestions',
+ 'mediawiki.api'
+ )
+ ),
'mediawiki.Title' => array(
'scripts' => 'resources/src/mediawiki/mediawiki.Title.js',
'dependencies' => array(
diff --git a/resources/src/mediawiki/mediawiki.tagSuggest.js
b/resources/src/mediawiki/mediawiki.tagSuggest.js
new file mode 100644
index 0000000..f4ab2e9
--- /dev/null
+++ b/resources/src/mediawiki/mediawiki.tagSuggest.js
@@ -0,0 +1,40 @@
+/*!
+ * Add autocomplete suggestions for tags.
+ */
+( function ( mw, $ ) {
+ var api, config;
+
+ config = {
+ fetch: function ( userInput ) {
+ var $textbox = this,
+ node = this[0];
+
+ api = api || new mw.Api();
+
+ $.data( node, 'request', api.get( {
+ action: 'query',
+ list: 'tags',
+ tgcontains: userInput
+ } ).done( function ( data ) {
+ var tags = $.map( data.query.tags, function (
tagObj ) {
+ return tagObj.name;
+ } );
+ // Set the results as the autocomplete options
+ $textbox.suggestions( 'suggestions', tags );
+ } ) );
+ },
+ cancel: function () {
+ var node = this[0],
+ request = $.data( node, 'request' );
+
+ if ( request ) {
+ request.abort();
+ $.removeData( node, 'request' );
+ }
+ }
+ };
+
+ $( function () {
+ $( '.mw-tagfilter-input' ).suggestions( config );
+ } );
+}( mediaWiki, jQuery ) );
--
To view, visit https://gerrit.wikimedia.org/r/175938
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic6c16a893c4b40702764d455fa21934686a8b162
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Gerrit Patch Uploader <[email protected]>
Gerrit-Reviewer: Gerrit Patch Uploader <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits