Index: trunk/phase3/docs/hooks.txt |
— | — | @@ -1283,10 +1283,27 @@ |
1284 | 1284 | $title : Page title |
1285 | 1285 | $text : Current text being indexed |
1286 | 1286 | |
1287 | | -'SearchGetNearMatch': An extra chance for exact-title-matches in "go" searches |
| 1287 | +'SearchGetNearMatchBefore': Perform exact-title-matches in "go" searches before the normal operations |
| 1288 | +$allSearchTerms : Array of the search terms in all content languages |
| 1289 | +&$titleResult : Outparam; the value to return. A Title object or null. |
| 1290 | + |
| 1291 | +'SearchGetNearMatch': An extra chance for exact-title-matches in "go" searches if nothing was found |
1288 | 1292 | $term : Search term string |
1289 | 1293 | &$title : Outparam; set to $title object and return false for a match |
1290 | 1294 | |
| 1295 | +'SearchGetNearMatchComplete': A chance to modify exact-title-matches in "go" searches |
| 1296 | +$term : Search term string |
| 1297 | +&$title : Current Title object that is being returned (null if none found). |
| 1298 | + |
| 1299 | +'SearchEngineReplacePrefixesComplete': Run after SearchEngine::replacePrefixes(). |
| 1300 | +$searchEngine : The SearchEngine object. Users of this hooks will be interested |
| 1301 | +in the $searchEngine->namespaces array. |
| 1302 | +$query : Original query. |
| 1303 | +&$parsed : Resultant query with the prefixes stripped. |
| 1304 | + |
| 1305 | +'SearchableNamespaces': An option to modify which namespaces are searchable. |
| 1306 | +&$arr : Array of namespaces ($nsId => $name) which will be used. |
| 1307 | + |
1291 | 1308 | 'SetupAfterCache': Called in Setup.php, after cache objects are set |
1292 | 1309 | |
1293 | 1310 | 'ShowMissingArticle': Called when generating the output for a non-existent page |
Index: trunk/phase3/includes/search/SearchEngine.php |
— | — | @@ -63,16 +63,30 @@ |
64 | 64 | * @return Title |
65 | 65 | */ |
66 | 66 | public static function getNearMatch( $searchterm ) { |
| 67 | + $title = self::getNearMatchInternal( $searchterm ); |
| 68 | + |
| 69 | + wfRunHooks( 'SearchGetNearMatchComplete', array( $searchterm, &$title ) ); |
| 70 | + return $title; |
| 71 | + } |
| 72 | + |
| 73 | + /** |
| 74 | + * Really find the title match. |
| 75 | + */ |
| 76 | + private static function getNearMatchInternal( $searchterm ) { |
67 | 77 | global $wgContLang; |
68 | 78 | |
69 | 79 | $allSearchTerms = array($searchterm); |
70 | 80 | |
71 | | - if($wgContLang->hasVariants()){ |
| 81 | + if ( $wgContLang->hasVariants() ) { |
72 | 82 | $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm)); |
73 | 83 | } |
74 | 84 | |
75 | | - foreach($allSearchTerms as $term){ |
| 85 | + if( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) { |
| 86 | + return $titleResult; |
| 87 | + } |
76 | 88 | |
| 89 | + foreach($allSearchTerms as $term) { |
| 90 | + |
77 | 91 | # Exact match? No need to look further. |
78 | 92 | $title = Title::newFromText( $term ); |
79 | 93 | if (is_null($title)) |
— | — | @@ -196,10 +210,12 @@ |
197 | 211 | function replacePrefixes( $query ){ |
198 | 212 | global $wgContLang; |
199 | 213 | |
200 | | - if( strpos($query,':') === false ) |
201 | | - return $query; // nothing to do |
202 | | - |
203 | 214 | $parsed = $query; |
| 215 | + if( strpos($query,':') === false ) { // nothing to do |
| 216 | + wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); |
| 217 | + return $parsed; |
| 218 | + } |
| 219 | + |
204 | 220 | $allkeyword = wfMsgForContent('searchall').":"; |
205 | 221 | if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){ |
206 | 222 | $this->namespaces = null; |
— | — | @@ -213,8 +229,10 @@ |
214 | 230 | } |
215 | 231 | } |
216 | 232 | if(trim($parsed) == '') |
217 | | - return $query; // prefix was the whole query |
| 233 | + $parsed = $query; // prefix was the whole query |
218 | 234 | |
| 235 | + wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) ); |
| 236 | + |
219 | 237 | return $parsed; |
220 | 238 | } |
221 | 239 | |
— | — | @@ -230,6 +248,8 @@ |
231 | 249 | $arr[$ns] = $name; |
232 | 250 | } |
233 | 251 | } |
| 252 | + |
| 253 | + wfRunHooks( 'SearchableNamespaces', array( &$arr ) ); |
234 | 254 | return $arr; |
235 | 255 | } |
236 | 256 | |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -304,6 +304,7 @@ |
305 | 305 | * (bug 16281) Show copyright system message on special pages |
306 | 306 | * Upload license preview now uses the API instead of action=ajax |
307 | 307 | * (bug 7346) Add <guid> to RSS to avoid duplicates |
| 308 | +* (bug 19996) Added new hooks for Special:Search, which allow to further restrict/expand it. |
308 | 309 | |
309 | 310 | === Bug fixes in 1.16 === |
310 | 311 | |
— | — | @@ -714,8 +715,6 @@ |
715 | 716 | skin-specific JS pages |
716 | 717 | * (bug 5061) Use the more precise thumbcaption thumbimage and thumbinner classes |
717 | 718 | for image divs. |
718 | | -* IE50Fixes.css and IE55Fixes.css have been dropped from the Monobook and Chick |
719 | | - skins |
720 | 719 | |
721 | 720 | == API changes in 1.16 == |
722 | 721 | |