r61150 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61149‎ | r61150 | r61151 >
Date:23:27, 16 January 2010
Author:platonides
Status:ok (Comments)
Tags:
Comment:
Bug 19996 (backend hooks) Finally adding the four hooks.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/docs/hooks.txt (modified) (history)
  • /trunk/phase3/includes/search/SearchEngine.php (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/hooks.txt
@@ -1283,10 +1283,27 @@
12841284 $title : Page title
12851285 $text : Current text being indexed
12861286
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
12881292 $term : Search term string
12891293 &$title : Outparam; set to $title object and return false for a match
12901294
 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+
12911308 'SetupAfterCache': Called in Setup.php, after cache objects are set
12921309
12931310 'ShowMissingArticle': Called when generating the output for a non-existent page
Index: trunk/phase3/includes/search/SearchEngine.php
@@ -63,16 +63,30 @@
6464 * @return Title
6565 */
6666 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 ) {
6777 global $wgContLang;
6878
6979 $allSearchTerms = array($searchterm);
7080
71 - if($wgContLang->hasVariants()){
 81+ if ( $wgContLang->hasVariants() ) {
7282 $allSearchTerms = array_merge($allSearchTerms,$wgContLang->convertLinkToAllVariants($searchterm));
7383 }
7484
75 - foreach($allSearchTerms as $term){
 85+ if( !wfRunHooks( 'SearchGetNearMatchBefore', array( $allSearchTerms, &$titleResult ) ) ) {
 86+ return $titleResult;
 87+ }
7688
 89+ foreach($allSearchTerms as $term) {
 90+
7791 # Exact match? No need to look further.
7892 $title = Title::newFromText( $term );
7993 if (is_null($title))
@@ -196,10 +210,12 @@
197211 function replacePrefixes( $query ){
198212 global $wgContLang;
199213
200 - if( strpos($query,':') === false )
201 - return $query; // nothing to do
202 -
203214 $parsed = $query;
 215+ if( strpos($query,':') === false ) { // nothing to do
 216+ wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) );
 217+ return $parsed;
 218+ }
 219+
204220 $allkeyword = wfMsgForContent('searchall').":";
205221 if( strncmp($query, $allkeyword, strlen($allkeyword)) == 0 ){
206222 $this->namespaces = null;
@@ -213,8 +229,10 @@
214230 }
215231 }
216232 if(trim($parsed) == '')
217 - return $query; // prefix was the whole query
 233+ $parsed = $query; // prefix was the whole query
218234
 235+ wfRunHooks( 'SearchEngineReplacePrefixesComplete', array( $this, $query, &$parsed ) );
 236+
219237 return $parsed;
220238 }
221239
@@ -230,6 +248,8 @@
231249 $arr[$ns] = $name;
232250 }
233251 }
 252+
 253+ wfRunHooks( 'SearchableNamespaces', array( &$arr ) );
234254 return $arr;
235255 }
236256
Index: trunk/phase3/RELEASE-NOTES
@@ -304,6 +304,7 @@
305305 * (bug 16281) Show copyright system message on special pages
306306 * Upload license preview now uses the API instead of action=ajax
307307 * (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.
308309
309310 === Bug fixes in 1.16 ===
310311
@@ -714,8 +715,6 @@
715716 skin-specific JS pages
716717 * (bug 5061) Use the more precise thumbcaption thumbimage and thumbinner classes
717718 for image divs.
718 -* IE50Fixes.css and IE55Fixes.css have been dropped from the Monobook and Chick
719 - skins
720719
721720 == API changes in 1.16 ==
722721

Follow-up revisions

RevisionCommit summaryAuthorDate
r61151(Bug 19996) Namespace hiding on Special:Search...platonides23:29, 16 January 2010
r61152It isn't overriding the go search. It is only called if the default checks ar...platonides23:32, 16 January 2010
r61153Readd line mistakenly removed on r61150platonides23:34, 16 January 2010
r61570Follow-up r61150: Do not pass objects as references in new hooks.platonides11:43, 27 January 2010
r61572Apply r61570 (Follow-up r61150: Do not pass objects as references in new hooks)....platonides11:52, 27 January 2010

Comments

#Comment by Tim Starling (talk | contribs)   03:07, 27 January 2010

Don't pass objects as references in new code, e.g. &$title. Please review the output of "svn diff" before you commit, to check for accidental changes such as the one made here to RELEASE-NOTES, or the UTF-8 screwup in r61052.

#Comment by Nikerabbit (talk | contribs)   13:47, 27 January 2010

[27-Jan-2010 13:43:28] PHP Notice: Undefined variable: titleResult in /www/w/includes/search/SearchEngine.php on line 96

Status & tagging log