From: yaron Date: Wed, 5 Sep 2012 02:21:09 +0000 (+0400) Subject: New hook, 'SearchResultInitFromTitle' X-Git-Tag: 1.31.0-rc.0~22433^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/cotisations/rappels.php?a=commitdiff_plain;h=13b2fe802eb00a7ee2c84c7bb526c7c486326c2b;p=lhc%2Fweb%2Fwiklou.git New hook, 'SearchResultInitFromTitle' This hook lets you change the revision ID used for a page (a Title object), when displaying that page in search results. It's useful for the Approved Revs extension, so that pages whose approved revision is not their latest can have their approved revision, not the latest one, show up when doing a search text. It's also potentially useful for other, similar extensions, like FlaggedRevs. Change-Id: Ic4bad8dfaa83de131db9c8e7667d7f5767d8d5f5 --- diff --git a/docs/hooks.txt b/docs/hooks.txt index 7844aaf48c..3560856cce 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -1703,6 +1703,11 @@ in the $searchEngine->namespaces array. $query : Original query. &$parsed : Resultant query with the prefixes stripped. +'SearchResultInitFromTitle': Set the revision used when displaying a page in +search results. +$title : Current Title object being displayed in search results. +&$id: Revision ID (default is false, for latest) + 'SearchableNamespaces': An option to modify which namespaces are searchable. &$arr : Array of namespaces ($nsId => $name) which will be used. diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index b50559224d..2ccb6d3164 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -756,8 +756,10 @@ class SearchResult { protected function initFromTitle( $title ) { $this->mTitle = $title; if ( !is_null( $this->mTitle ) ) { + $id = false; + wfRunHooks( 'SearchResultInitFromTitle', array( $title, &$id ) ); $this->mRevision = Revision::newFromTitle( - $this->mTitle, false, Revision::READ_NORMAL ); + $this->mTitle, $id, Revision::READ_NORMAL ); if ( $this->mTitle->getNamespace() === NS_FILE ) $this->mImage = wfFindFile( $this->mTitle ); }