/**
* Basic search engine
*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
* @file
* @ingroup Search
*/
/**
* If this search backend can list/unlist redirects
* @deprecated since 1.18 Call supports( 'list-redirects' );
+ * @return bool
*/
function acceptListRedirects() {
+ wfDeprecated( __METHOD__, '1.18' );
return $this->supports( 'list-redirects' );
}
* @since 1.18
* @param $feature String
* @param $data Mixed
- * @return Noolean
+ * @return bool
*/
public function setFeatureData( $feature, $data ) {
$this->features[$feature] = $data;
/**
* Really find the title match.
+ * @return null|\Title
*/
private static function getNearMatchInternal( $searchterm ) {
global $wgContLang, $wgEnableSearchContributorsByIP;
* or namespace names
*
* @param $query String
+ * @return string
*/
function replacePrefixes( $query ) {
global $wgContLang;
return $parsed;
}
- $allkeyword = wfMsgForContent( 'searchall' ) . ":";
+ $allkeyword = wfMessage( 'searchall' )->inContentLanguage()->text() . ":";
if ( strncmp( $query, $allkeyword, strlen( $allkeyword ) ) == 0 ) {
$this->namespaces = null;
$parsed = substr( $query, strlen( $allkeyword ) );
public static function userNamespaces( $user ) {
global $wgSearchEverythingOnlyLoggedIn;
- // get search everything preference, that can be set to be read for logged-in users
- $searcheverything = false;
- if ( ( $wgSearchEverythingOnlyLoggedIn && $user->isLoggedIn() )
- || !$wgSearchEverythingOnlyLoggedIn )
- $searcheverything = $user->getOption( 'searcheverything' );
-
- // searcheverything overrides other options
- if ( $searcheverything )
- return array_keys( SearchEngine::searchableNamespaces() );
-
- $arr = Preferences::loadOldSearchNs( $user );
$searchableNamespaces = SearchEngine::searchableNamespaces();
- $arr = array_intersect( $arr, array_keys( $searchableNamespaces ) ); // Filter
+ // get search everything preference, that can be set to be read for logged-in users
+ // it overrides other options
+ if ( !$wgSearchEverythingOnlyLoggedIn || $user->isLoggedIn() ) {
+ if ( $user->getOption( 'searcheverything' ) ) {
+ return array_keys( $searchableNamespaces );
+ }
+ }
+
+ $arr = array();
+ foreach ( $searchableNamespaces as $ns => $name ) {
+ if ( $user->getOption( 'searchNs' . $ns ) ) {
+ $arr[] = $ns;
+ }
+ }
return $arr;
}
* and preferences
*
* @param $namespaces Array
+ * @return array
*/
public static function namespacesAsText( $namespaces ) {
global $wgContLang;
$formatted = array_map( array( $wgContLang, 'getFormattedNsText' ), $namespaces );
foreach ( $formatted as $key => $ns ) {
if ( empty( $ns ) )
- $formatted[$key] = wfMsg( 'blanknamespace' );
+ $formatted[$key] = wfMessage( 'blanknamespace' )->text();
}
return $formatted;
}
protected function initFromTitle( $title ) {
$this->mTitle = $title;
if ( !is_null( $this->mTitle ) ) {
- $this->mRevision = Revision::newFromTitle( $this->mTitle );
+ $this->mRevision = Revision::newFromTitle(
+ $this->mTitle, false, Revision::READ_NORMAL );
if ( $this->mTitle->getNamespace() === NS_FILE )
$this->mImage = wfFindFile( $this->mTitle );
}
}
/**
- * @return Double or null if not supported
+ * @return float|null if not supported
*/
function getScore() {
return null;
*/
protected function initText() {
if ( !isset( $this->mText ) ) {
- if ( $this->mRevision != null )
- $this->mText = $this->mRevision->getText();
- else // TODO: can we fetch raw wikitext for commons images?
+ if ( $this->mRevision != null ) {
+ $content = $this->mRevision->getContent();
+ $this->mText = $content->getTextForSearchIndex(); //XXX: maybe we don't even need the text, but the content object?
+ } else { // TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
-
+ }
}
}
global $wgUser, $wgAdvancedSearchHighlighting;
$this->initText();
list( $contextlines, $contextchars ) = SearchEngine::userHighlightPrefs( $wgUser );
- $h = new SearchHighlighter();
+ $h = new SearchHighlighter(); // TODO: make highliter take a content object. Make ContentHandler a factory for SearchHighliter.
if ( $wgAdvancedSearchHighlighting )
return $h->highlightText( $this->mText, $terms, $contextlines, $contextchars );
else
* Do manual case conversion for non-ascii chars
*
* @param $matches Array
+ * @return string
*/
function caseCallback( $matches ) {
global $wgContLang;
/**
* Basic wikitext removal
* @protected
+ * @return mixed
*/
function removeWiki( $text ) {
$fname = __METHOD__;