Extension talk:GoToCategory

From mediawiki.org
Latest comment: 2 years ago by Ribewiki in topic What happened to this extension?

Lovely![edit]

Should have found this 1 year ago. --Subfader 17:43, 8 April 2008 (UTC)Reply

Capz?[edit]

Let's say you have a "Category:UpperCase" if you search "uppercase" it won't find it. Searching "upperCase" will do. I just wonder if it's a buig since it finds "Category:Upper Case" by searching "upper case" --Subfader 17:56, 8 April 2008 (UTC)Reply

It didn't exist a year ago, I wrote it in response to your request.  ;-) As far as the bug, it's the nature of MediaWiki. The first character's case won't matter because, by default, MW capitalizes the first letter of every article name. So that's why you see that behavior. The Go functionality won't hit on pages in the Main namespase (NS_MAIN) that use wierd PascalCase either. For this, we often just create redirect pages w/ different case options (i.e. disambiguation). Tim Laqua talk 18:43, 8 April 2008 (UTC)Reply
Wow you indeed just wrote it :) Ok, no big thing as there are only 2 categories with ThoseCapz i can think of atm. Thanks a lot! --Subfader 20:05, 8 April 2008 (UTC)Reply
I think I quite don't understand it anyway.
  • yes: "abcd" > "Category:ABCD"
  • no: "abcd" > "Category:AbCd" or "ab cde" > "Category:AB Cde"?
--Subfader 07:19, 9 April 2008 (UTC)Reply
Do pages in the main namespace exhibit differeng behavior? Tim Laqua talk 11:45, 9 April 2008 (UTC)Reply
Same, so it's only the general MW problem. Never used Go for Main since my articles all have long names you'd never search complete. --Subfader 20:46, 9 April 2008 (UTC)Reply

3 letter search[edit]

Just recognized that it even has more added value compared to the standard search which doesn't search 3 letter words.
So while search won't find "Category:The dot", the Go button will take you there directly :) --Subfader 07:12, 9 April 2008 (UTC)Reply

Umlauts problem[edit]

Found out that I can't GO to cats with umlauts in the name anymore. Regular search is done. Dunno how long it is that way already, maybe since my 1.13 upgrade. Sort keys: ä = ä | Ö = ö | ü = ü I think it's correct?

I ran maintenance/refreshLinks.php, populateCategory.php and updateSearchIndex.php successfully but no luck. I experience no ther problems with the umlauts in cat names except the GoTo which worked some while ago. What can I do? Cheers --Subfader 15:26, 28 September 2008 (UTC)Reply

Don't go to deleted cats[edit]

If teh category page was deleted you will still land on that page. This is pretty annoying. Could it be easily avoided? I never created redirects on cat pages though. --Subfader 15:03, 21 September 2009 (UTC)Reply

How to get it working with SphinxSearch[edit]

Replace the default PHP with the following:

<?php
/** \file
* \brief Contains code for the GoToCategory extension
*/

# Not a valid entry point, skip unless MEDIAWIKI is defined
if (!defined('MEDIAWIKI')) {
	echo "GoToCategory extension";
	exit(1);
}

$wgExtensionCredits['other'][] = array(
	'path'           => __FILE__,
	'name'           => 'GoToCategory',
	'version'        => '1.0',
	'author'         => 'Tim Laqua',
	'description'    => "Checks search terms against the Category: namespace for Go 'jump to page' functionality",
	'descriptionmsg' => 'gotocategory-desc',
	'url'            => 'http://www.mediawiki.org/wiki/Extension:GoToCategory',
);

$wgExtensionFunctions[] = 'efGoToCategory_Setup';

function efGoToCategory_Setup() {
	global $wgHooks;
	$wgHooks['SpecialSearchNogomatch'][]   = 'efGoToCategory_SpecialSearchNogomatch';
	$wgHooks['SphinxSearchGetNearMatch'][] = 'efGoToCategory_SphinxSearchGetNearMatch';
	return true;
}

function efGoToCategory_SpecialSearchNogomatch($t) {
	global $wgOut, $wgRequest;

	$term = $wgRequest->getText('search');
	if( !empty( $term ) && strpos( 'category:', strtolower( $term ) ) !== 0 ) {
		$term = "Category:{$term}";
	}

	$title = SearchEngine::getNearMatch( $term );
	if( !is_null( $title ) ) {
		$wgOut->redirect( $title->getFullURL() );
	}
	return true;
}

function efGoToCategory_SphinxSearchGetNearMatch($term, $t) {

	# test if we have no match so far
	# then we know we can continue with the no go match function
	if( is_null( $t ) ) {
		efGoToCategory_SpecialSearchNogomatch($term);
	}
	return true;
}

Redlink categories[edit]

Great extension! Could this be tweaked to search also for redlink categories? Thanks. --Blicarea 01:57, 11 August 2011 (UTC)Reply

There are not suggestion[edit]

Great extension, but without a suggestion of the existing categories is not really useful.

--WhiteTigerItaly (talk) 13:53, 3 October 2012 (UTC)Reply

I accomplished this by installing Extension:MixedNamespaceSearchSuggestions and swapping out some lines in /extensions/MixedNamespaceSearchSuggestions/resources/ext.mnss.search.js
$( document ).ready( function () {
		var $searchInput = $( '#searchInput' );

		$searchInput.suggestions( {
			fetch: function ( query ) {
				var $el;

				if ( query.length !== 0 ) {
					$el = $( this );
					$el.data( 'request', ( new mw.Api() ).get( {
						action: 'opensearch',
						search: query,
						namespace: mw.config.get( 'wgContentNamespaces' ).join( '|' ),
						suggest: ''
					} ).done( function ( data ) {
						$el.suggestions( 'suggestions', data[1] );
					} ) );
				}
			},
			result: {
				render: customRenderFunction
			}
		} );
	} );
becomes
$( document ).ready( function () {
		var $searchInput = $( '#searchInput' );
		$searchInput.suggestions( {
			fetch: function ( query ) {
				var $el;

				if ( query.length !== 0 ) {
					$el = $( this );
					$el.data( 'request', ( new mw.Api() ).get( {
						action: 'opensearch',
						search: query,
						namespace: mw.config.get( 'wgContentNamespaces' ).join( '|' ),
						suggest: ''
					} ).done( function ( data ) {
						$el.data('articles', data[1]);
						$el.data('request2', (new mw.Api()).get({action: 'opensearch',search: query,namespace: '14',suggest: ''}).done(function (data) {
							$el.suggestions( 'suggestions', $el.data('articles').concat(data[1]) );
						}));
					} ) );
				}
			},
			result: {
				render: customRenderFunction
			}
		} );
	} );
This has the added benefit of other article namespaces also showing up in search.
James Kevin Martindale (talk) 15:46, 22 October 2016 (UTC)Reply
I wrapped up the patch in an extension at Extension:CategorySearchSuggestions if you're interested. James Kevin Martindale (talk) 00:50, 23 October 2016 (UTC)Reply

What happened to this extension?[edit]

The extension works no more in mw version 1.35 and results in fault, can someone please update it, because I need it?? --Ribewiki (talk) 22:53, 10 August 2021 (UTC)Reply

Hmm, looks like only this is needed: --Ribewiki (talk) 00:49, 11 August 2021 (UTC)Reply

wfLoadExtension( 'MixedNamespaceSearchSuggestions' );	
$wgContentNamespaces = [ NS_MAIN, NS_CATEGORY, NS_TEMPLATE ];