summaryrefslogtreecommitdiff
path: root/includes/search
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
commitd9022f63880ce039446fba8364f68e656b7bf4cb (patch)
tree16b40fbf17bf7c9ee6f4ead25b16dd192378050a /includes/search
parent27cf83d177256813e2e802241085fce5dd0f3fb9 (diff)
Update to MediaWiki 1.19.0
Diffstat (limited to 'includes/search')
-rw-r--r--includes/search/SearchEngine.php191
-rw-r--r--includes/search/SearchMySQL.php3
-rw-r--r--includes/search/SearchOracle.php4
-rw-r--r--includes/search/SearchUpdate.php4
4 files changed, 106 insertions, 96 deletions
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 40b992de..2f7dfd7e 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -67,6 +67,7 @@ class SearchEngine {
* @deprecated since 1.18 Call supports( 'list-redirects' );
*/
function acceptListRedirects() {
+ wfDeprecated( __METHOD__, '1.18' );
return $this->supports( 'list-redirects' );
}
@@ -148,7 +149,7 @@ class SearchEngine {
* Really find the title match.
*/
private static function getNearMatchInternal( $searchterm ) {
- global $wgContLang;
+ global $wgContLang, $wgEnableSearchContributorsByIP;
$allSearchTerms = array( $searchterm );
@@ -161,8 +162,6 @@ class SearchEngine {
return $titleResult;
}
- $context = new RequestContext;
-
foreach ( $allSearchTerms as $term ) {
# Exact match? No need to look further.
@@ -171,14 +170,13 @@ class SearchEngine {
return null;
}
- if ( $title->getNamespace() == NS_SPECIAL || $title->isExternal() || $title->exists() ) {
+ if ( $title->isSpecialPage() || $title->isExternal() || $title->exists() ) {
return $title;
}
# See if it still otherwise has content is some sane sense
- $context->setTitle( $title );
- $article = Article::newFromTitle( $title, $context );
- if ( $article->hasViewableContent() ) {
+ $page = WikiPage::factory( $title );
+ if ( $page->hasViewableContent() ) {
return $title;
}
@@ -218,10 +216,13 @@ class SearchEngine {
$title = Title::newFromText( $searchterm );
+
# Entering an IP address goes to the contributions page
- if ( ( $title->getNamespace() == NS_USER && User::isIP( $title->getText() ) )
- || User::isIP( trim( $searchterm ) ) ) {
- return SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() );
+ if ( $wgEnableSearchContributorsByIP ) {
+ if ( ( $title->getNamespace() == NS_USER && User::isIP( $title->getText() ) )
+ || User::isIP( trim( $searchterm ) ) ) {
+ return SpecialPage::getTitleFor( 'Contributions', $title->getDBkey() );
+ }
}
@@ -343,20 +344,22 @@ class SearchEngine {
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;
}
@@ -1098,7 +1101,7 @@ class SearchHighlighter {
} else {
// if begin of the article contains the whole phrase, show only that !!
if ( array_key_exists( $first, $snippets ) && preg_match( $pat1, $snippets[$first] )
- && $offsets[$first] < $contextchars * 2 ) {
+ && $offsets[$first] < $contextchars * 2 ) {
$snippets = array ( $first => $snippets[$first] );
}
@@ -1119,10 +1122,10 @@ class SearchHighlighter {
// add more lines
$add = $index + 1;
while ( $len < $targetchars - 20
- && array_key_exists( $add, $all )
- && !array_key_exists( $add, $snippets ) ) {
- $offsets[$add] = 0;
- $tt = "\n" . $this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
+ && array_key_exists( $add, $all )
+ && !array_key_exists( $add, $snippets ) ) {
+ $offsets[$add] = 0;
+ $tt = "\n" . $this->extract( $all[$add], 0, $targetchars - $len, $offsets[$add] );
$extended[$add] = $tt;
$len += strlen( $tt );
$add++;
@@ -1152,7 +1155,7 @@ class SearchHighlighter {
if ( ! isset( $processed[$term] ) ) {
$pat3 = "/$patPre(" . $term . ")$patPost/ui"; // highlight word
$extract = preg_replace( $pat3,
- "\\1<span class='searchmatch'>\\2</span>\\3", $extract );
+ "\\1<span class='searchmatch'>\\2</span>\\3", $extract );
$processed[$term] = true;
}
}
@@ -1187,8 +1190,9 @@ class SearchHighlighter {
global $wgContLang;
if ( strlen( $matches[0] ) > 1 ) {
return '[' . $wgContLang->lc( $matches[0] ) . $wgContLang->uc( $matches[0] ) . ']';
- } else
+ } else {
return $matches[0];
+ }
}
/**
@@ -1202,22 +1206,27 @@ class SearchHighlighter {
* @return String
*/
function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) {
- if ( $start != 0 )
+ if ( $start != 0 ) {
$start = $this->position( $text, $start, 1 );
- if ( $end >= strlen( $text ) )
+ }
+ if ( $end >= strlen( $text ) ) {
$end = strlen( $text );
- else
+ } else {
$end = $this->position( $text, $end );
+ }
- if ( !is_null( $posStart ) )
+ if ( !is_null( $posStart ) ) {
$posStart = $start;
- if ( !is_null( $posEnd ) )
+ }
+ if ( !is_null( $posEnd ) ) {
$posEnd = $end;
+ }
- if ( $end > $start )
+ if ( $end > $start ) {
return substr( $text, $start, $end - $start );
- else
+ } else {
return '';
+ }
}
/**
@@ -1342,61 +1351,61 @@ class SearchHighlighter {
}
/**
- * Simple & fast snippet extraction, but gives completely unrelevant
- * snippets
- *
- * @param $text String
- * @param $terms Array
- * @param $contextlines Integer
- * @param $contextchars Integer
- * @return String
- */
- public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
- global $wgContLang;
- $fname = __METHOD__;
-
- $lines = explode( "\n", $text );
-
- $terms = implode( '|', $terms );
- $max = intval( $contextchars ) + 1;
- $pat1 = "/(.*)($terms)(.{0,$max})/i";
-
- $lineno = 0;
-
- $extract = "";
- wfProfileIn( "$fname-extract" );
- foreach ( $lines as $line ) {
- if ( 0 == $contextlines ) {
- break;
- }
- ++$lineno;
- $m = array();
- if ( ! preg_match( $pat1, $line, $m ) ) {
- continue;
- }
- --$contextlines;
- // truncate function changes ... to relevant i18n message.
- $pre = $wgContLang->truncate( $m[1], - $contextchars, '...', false );
-
- if ( count( $m ) < 3 ) {
- $post = '';
- } else {
- $post = $wgContLang->truncate( $m[3], $contextchars, '...', false );
- }
-
- $found = $m[2];
-
- $line = htmlspecialchars( $pre . $found . $post );
- $pat2 = '/(' . $terms . ")/i";
- $line = preg_replace( $pat2,
- "<span class='searchmatch'>\\1</span>", $line );
-
- $extract .= "${line}\n";
- }
- wfProfileOut( "$fname-extract" );
-
- return $extract;
- }
+ * Simple & fast snippet extraction, but gives completely unrelevant
+ * snippets
+ *
+ * @param $text String
+ * @param $terms Array
+ * @param $contextlines Integer
+ * @param $contextchars Integer
+ * @return String
+ */
+ public function highlightSimple( $text, $terms, $contextlines, $contextchars ) {
+ global $wgContLang;
+ $fname = __METHOD__;
+
+ $lines = explode( "\n", $text );
+
+ $terms = implode( '|', $terms );
+ $max = intval( $contextchars ) + 1;
+ $pat1 = "/(.*)($terms)(.{0,$max})/i";
+
+ $lineno = 0;
+
+ $extract = "";
+ wfProfileIn( "$fname-extract" );
+ foreach ( $lines as $line ) {
+ if ( 0 == $contextlines ) {
+ break;
+ }
+ ++$lineno;
+ $m = array();
+ if ( ! preg_match( $pat1, $line, $m ) ) {
+ continue;
+ }
+ --$contextlines;
+ // truncate function changes ... to relevant i18n message.
+ $pre = $wgContLang->truncate( $m[1], - $contextchars, '...', false );
+
+ if ( count( $m ) < 3 ) {
+ $post = '';
+ } else {
+ $post = $wgContLang->truncate( $m[3], $contextchars, '...', false );
+ }
+
+ $found = $m[2];
+
+ $line = htmlspecialchars( $pre . $found . $post );
+ $pat2 = '/(' . $terms . ")/i";
+ $line = preg_replace( $pat2,
+ "<span class='searchmatch'>\\1</span>", $line );
+
+ $extract .= "${line}\n";
+ }
+ wfProfileOut( "$fname-extract" );
+
+ return $extract;
+ }
}
diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php
index c52c9e5b..af8f3875 100644
--- a/includes/search/SearchMySQL.php
+++ b/includes/search/SearchMySQL.php
@@ -45,7 +45,7 @@ class SearchMySQL extends SearchEngine {
* become part of a WHERE clause
*
* @param $filteredText string
- * @param $fullText string
+ * @param $fulltext string
*
* @return string
*/
@@ -290,6 +290,7 @@ class SearchMySQL extends SearchEngine {
/**
* Get the base part of the search query.
*
+ * @param &$query Search query array
* @param $filteredTerm String
* @param $fulltext Boolean
* @since 1.18 (changed)
diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php
index 85337ca1..2d6fc3e2 100644
--- a/includes/search/SearchOracle.php
+++ b/includes/search/SearchOracle.php
@@ -257,9 +257,9 @@ class SearchOracle extends SearchEngine {
// ALTER SESSION SET CURRENT_SCHEMA = ...
// was used.
$dbw->query( "CALL ctx_ddl.sync_index(" .
- $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', false ) ) . ")" );
+ $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_text_idx', 'raw' ) ) . ")" );
$dbw->query( "CALL ctx_ddl.sync_index(" .
- $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', false ) ) . ")" );
+ $dbw->addQuotes( $dbw->getDBname() . '.' . $dbw->tableName( 'si_title_idx', 'raw' ) ) . ")" );
}
/**
diff --git a/includes/search/SearchUpdate.php b/includes/search/SearchUpdate.php
index f79092cb..a162d2b3 100644
--- a/includes/search/SearchUpdate.php
+++ b/includes/search/SearchUpdate.php
@@ -13,7 +13,7 @@
*
* @ingroup Search
*/
-class SearchUpdate {
+class SearchUpdate implements DeferrableUpdate {
private $mId = 0, $mNamespace, $mTitle, $mText;
private $mTitleWords;
@@ -37,7 +37,7 @@ class SearchUpdate {
global $wgContLang, $wgDisableSearchUpdate;
if( $wgDisableSearchUpdate || !$this->mId ) {
- return false;
+ return;
}
wfProfileIn( __METHOD__ );