Hi all,
I'm trying to build an autocompletion thingy that suggests categories based on user input using the opensearch API [1]. It sounds like a relatively simple thing and I was able to hack something that somewhat works in a few minutes...there's just one gotcha: this thing is supposed to suggest nothing but categories, so I don't need nor want the "Category:" label (or its localized equivalent) to show up. I've been able to manipulate the result set so that whenever the user clicks on a suggestion, whatever gets inserted into the <input> is correct...but what is *displayed* to the user still includes the "Category:" part in it. The various ways how I've been able to remove the "Category:" part from the value have been more or less hacky and inefficient.
What am I doing wrong here [2]? How can I totally strip out the "Category:" part and pretend it doesn't exist and never did?
[1] https://www.mediawiki.org/wiki/API:Opensearch [2] https://www.mediawiki.org/wiki/User:Jack_Phoenix/AutocompleteTest
Thanks and regards, -- Jack Phoenix MediaWiki developer
Florian set up something similar to this that you may be interested in: https://en.m.wikipedia.org/wiki/Barack%20Obama?mobileaction=alpha#/categorie...
On Wed, May 6, 2015 at 6:31 PM, Jack Phoenix jack@countervandalism.net wrote:
Hi all,
I'm trying to build an autocompletion thingy that suggests categories based on user input using the opensearch API [1]. It sounds like a relatively simple thing and I was able to hack something that somewhat works in a few minutes...there's just one gotcha: this thing is supposed to suggest nothing but categories, so I don't need nor want the "Category:" label (or its localized equivalent) to show up. I've been able to manipulate the result set so that whenever the user clicks on a suggestion, whatever gets inserted into the <input> is correct...but what is *displayed* to the user still includes the "Category:" part in it. The various ways how I've been able to remove the "Category:" part from the value have been more or less hacky and inefficient.
What am I doing wrong here [2]? How can I totally strip out the "Category:" part and pretend it doesn't exist and never did?
[1] https://www.mediawiki.org/wiki/API:Opensearch [2] https://www.mediawiki.org/wiki/User:Jack_Phoenix/AutocompleteTest
Thanks and regards,
Jack Phoenix MediaWiki developer _______________________________________________ Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Wed, May 6, 2015 at 1:31 PM, Jack Phoenix jack@countervandalism.net wrote:
I'm trying to build an autocompletion thingy that suggests categories based on user input using the opensearch API [1].
Sounds like https://en.wikipedia.org/wiki/Wikipedia:HotCat
How can I totally strip out the "Category:" part and pretend it doesn't exist and never did?
Hit api.php?action=query&meta=siteinfo&siprop=namespaces to get the localized name of the Category namespace. Or you should be safe just removing everything up to the first colon.
On Wed, May 6, 2015 at 9:06 PM, Brad Jorsch (Anomie) bjorsch@wikimedia.org wrote:
On Wed, May 6, 2015 at 1:31 PM, Jack Phoenix jack@countervandalism.net wrote:
I'm trying to build an autocompletion thingy that suggests categories
based
on user input using the opensearch API [1].
Sounds like https://en.wikipedia.org/wiki/Wikipedia:HotCat
Something like that, although not quite complicated. HotCat's current version is ~3k lines of code, my JS is ~40 lines.
How can I totally strip out the "Category:"
part and pretend it doesn't exist and never did?
Hit api.php?action=query&meta=siteinfo&siprop=namespaces to get the localized name of the Category namespace. Or you should be safe just removing everything up to the first colon.
Yeah, probably better to avoid the extra HTTP request.
In any case, I managed to solve my issue for the time being, or so I think. Defining a "response" callback and fiddling with the API-supplied data there seems to do the trick: https://www.mediawiki.org/w/index.php?title=User%3AJack_Phoenix%2FAutocomple... It does still feel a tad bit hacky to me, so if some JavaScript guru knows of the proper way to do this, feel free to let me know! But at least now I can safely throw out some old and icky code in favor of this new code. :)
Thanks and regards, -- Jack Phoenix MediaWiki developer
On 6 May 2015, at 20:26, Jack Phoenix jack@countervandalism.net wrote:
On Wed, May 6, 2015 at 9:06 PM, Brad Jorsch (Anomie) bjorsch@wikimedia.org wrote:
On Wed, May 6, 2015 at 1:31 PM, Jack Phoenix jack@countervandalism.net wrote:
How can I totally strip out the "Category:" [..]
Hit api.php?action=query&meta=siteinfo&siprop=namespaces to get the localized name of the Category namespace. Or you should be safe just removing everything up to the first colon.
Yeah, probably better to avoid the extra HTTP request.
Namespace information and variants thereof are readily available via mw.config wgNamespaceIds.
You can manually remove any values with id 14 (category), or use mw.Title to do it for you.
As for the UI library, I'd recommend using the jquery.suggestions module in a MediaWiki context. Avoid jQuery UI.
This is already used for page inputs (e.g. search), and user name inputs (e.g. Special:Log).
Creating an instance of it for categories should be straight forward.
You can use mediawiki.searchSuggest or mediawiki.userSuggest as starting point: https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki/m... https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki/mediawiki.userSuggest.js
-- Krinkle
or use mw.Title to do it for you.
That how i did it in the categories search in MobileFrontend, it's (in my opinion) the easiest solution: https://github.com/wikimedia/mediawiki-extensions-MobileFrontend/blob/master...
Best, Florian
-----Original-Nachricht----- Betreff: Re: [Wikitech-l] jQuery UI, opensearch API, categories and autocompletion -- oh my! Datum: Thu, 07 May 2015 01:16:38 +0000 Von: "Krinkle" krinklemail@gmail.com An: "wikitech-l Wikimedia List" wikitech-l@lists.wikimedia.org
On 6 May 2015, at 20:26, Jack Phoenix jack@countervandalism.net wrote:
On Wed, May 6, 2015 at 9:06 PM, Brad Jorsch (Anomie) bjorsch@wikimedia.org wrote:
On Wed, May 6, 2015 at 1:31 PM, Jack Phoenix jack@countervandalism.net wrote:
How can I totally strip out the "Category:" [..]
Hit api.php?action=query&meta=siteinfo&siprop=namespaces to get the localized name of the Category namespace. Or you should be safe just removing everything up to the first colon.
Yeah, probably better to avoid the extra HTTP request.
Namespace information and variants thereof are readily available via mw.config wgNamespaceIds.
You can manually remove any values with id 14 (category), or use mw.Title to do it for you.
As for the UI library, I'd recommend using the jquery.suggestions module in a MediaWiki context. Avoid jQuery UI.
This is already used for page inputs (e.g. search), and user name inputs (e.g. Special:Log).
Creating an instance of it for categories should be straight forward.
You can use mediawiki.searchSuggest or mediawiki.userSuggest as starting point: https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki/m... https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki/mediawiki.userSuggest.js-- Krinkle_______________________________________________Wikitech-l mailing listWikitech-l@lists.wikimedia.orghttps://lists.wikimedia.org/mailman/listinfo/wikitech-l
On 5/6/15, Jack Phoenix jack@countervandalism.net wrote:
On Wed, May 6, 2015 at 9:06 PM, Brad Jorsch (Anomie) bjorsch@wikimedia.org wrote:
On Wed, May 6, 2015 at 1:31 PM, Jack Phoenix jack@countervandalism.net wrote:
I'm trying to build an autocompletion thingy that suggests categories
based
on user input using the opensearch API [1].
Sounds like https://en.wikipedia.org/wiki/Wikipedia:HotCat
Something like that, although not quite complicated. HotCat's current version is ~3k lines of code, my JS is ~40 lines.
How can I totally strip out the "Category:"
part and pretend it doesn't exist and never did?
Hit api.php?action=query&meta=siteinfo&siprop=namespaces to get the localized name of the Category namespace. Or you should be safe just removing everything up to the first colon.
Yeah, probably better to avoid the extra HTTP request.
In any case, I managed to solve my issue for the time being, or so I think. Defining a "response" callback and fiddling with the API-supplied data there seems to do the trick: https://www.mediawiki.org/w/index.php?title=User%3AJack_Phoenix%2FAutocomple... It does still feel a tad bit hacky to me, so if some JavaScript guru knows of the proper way to do this, feel free to let me know! But at least now I can safely throw out some old and icky code in favor of this new code. :)
I tried to do something similar, it might be useful to you as a starting point: https://commons.wikimedia.org/wiki/MediaWiki:Gadget-advanced-search.js (I was also surprised at how frustrating it was to make what sounded trivial work right).
[I should note, I haven't really done any js in a long time, and that script was meant more as a proof of concept, so it might be slightly hacky]
-- bawolff
I'm trying to build an autocompletion thingy that suggests categories
based on user input using the opensearch API [1].
I also did something similar for our wm-metrics [1], ended up with some jqueryUI + cutting the prefix with a callback method [2] (I am JS-0.5 ;-)
[1] http://tools.wmflabs.org/wm-metrics/ [2] https://github.com/Commonists/wm_metrics/blob/master/app/static/commons-sear...
Hope that helps,
wikitech-l@lists.wikimedia.org