Index: trunk/extensions/GoToCategory/GoToCategory.php |
— | — | @@ -0,0 +1,41 @@ |
| 2 | +<?php |
| 3 | +/** \file |
| 4 | +* \brief Contains code for the GoToCategory extension |
| 5 | +*/ |
| 6 | + |
| 7 | +# Not a valid entry point, skip unless MEDIAWIKI is defined |
| 8 | +if (!defined('MEDIAWIKI')) { |
| 9 | + echo "GoToCategory extension"; |
| 10 | + exit(1); |
| 11 | +} |
| 12 | + |
| 13 | +$wgExtensionCredits['other'][] = array( |
| 14 | + 'name' => 'GoToCategory', |
| 15 | + 'version' => '1.0', |
| 16 | + 'author' => 'Tim Laqua', |
| 17 | + 'description' => "Checks search terms against the Category: namespace for Go 'jump to page' functionality", |
| 18 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:GoToCategory', |
| 19 | +); |
| 20 | + |
| 21 | +$wgExtensionFunctions[] = 'efGoToCategory_Setup'; |
| 22 | + |
| 23 | +function efGoToCategory_Setup() { |
| 24 | + global $wgHooks; |
| 25 | + $wgHooks['SpecialSearchNogomatch'][] = 'efGoToCategory_SpecialSearchNogomatch'; |
| 26 | + return true; |
| 27 | +} |
| 28 | + |
| 29 | +function efGoToCategory_SpecialSearchNogomatch($t) { |
| 30 | + global $wgOut, $wgRequest; |
| 31 | + |
| 32 | + $term = $wgRequest->getText('search'); |
| 33 | + if( !empty( $term ) && strpos( 'category:', strtolower( $term ) ) !== 0 ) { |
| 34 | + $term = "Category:{$term}"; |
| 35 | + } |
| 36 | + |
| 37 | + $title = SearchEngine::getNearMatch( $term ); |
| 38 | + if( !is_null( $title ) ) { |
| 39 | + $wgOut->redirect( $title->getFullURL() ); |
| 40 | + } |
| 41 | + return true; |
| 42 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/GoToCategory/GoToCategory.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 43 | + native |