* @ingroup Search
*/
class SearchEngine {
- var $limit = 10;
- var $offset = 0;
- var $prefix = '';
- var $searchTerms = array();
- var $namespaces = array( NS_MAIN );
+ /** @var string */
+ public $prefix = '';
+
+ /** @var int[] */
+ public $namespaces = array( NS_MAIN );
+
+ /** @var int */
+ protected $limit = 10;
+
+ /** @var int */
+ protected $offset = 0;
+
+ /** @var array|string */
+ protected $searchTerms = array();
+
+ /** @var bool */
protected $showSuggestion = true;
/** @var array Feature values */
}
/**
- * Transform search term in cases when parts of the query came as different GET params (when supported)
- * e.g. for prefix queries: search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive
+ * Transform search term in cases when parts of the query came as different
+ * GET params (when supported), e.g. for prefix queries:
+ * search=test&prefix=Main_Page/Archive -> test prefix:Main Page/Archive
*/
function transformSearchTerm( $term ) {
return $term;
$allSearchTerms = array( $searchterm );
if ( $wgContLang->hasVariants() ) {
- $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->autoConvertToAllVariants( $searchterm ) );
+ $allSearchTerms = array_merge(
+ $allSearchTerms,
+ $wgContLang->autoConvertToAllVariants( $searchterm )
+ );
}
$titleResult = null;
*/
public static function getOpenSearchTemplate() {
global $wgOpenSearchTemplate, $wgCanonicalServer;
+
if ( $wgOpenSearchTemplate ) {
return $wgOpenSearchTemplate;
} else {
if ( !$ns ) {
$ns = "0";
}
- return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
+
+ return $wgCanonicalServer . wfScript( 'api' )
+ . '?action=opensearch&search={searchTerms}&namespace=' . $ns;
}
}
* @ingroup Search
*/
class SearchHighlighter {
- var $mCleanWikitext = true;
+ protected $mCleanWikitext = true;
function __construct( $cleanupWikitext = true ) {
$this->mCleanWikitext = $cleanupWikitext;
* @param array $terms Terms to highlight (unescaped)
* @param int $contextlines
* @param int $contextchars
- * @return tring
+ * @return string
*/
public function highlightText( $text, $terms, $contextlines, $contextchars ) {
- global $wgContLang;
- global $wgSearchHighlightBoundaries;
+ global $wgContLang, $wgSearchHighlightBoundaries;
+
$fname = __METHOD__;
if ( $text == '' ) {
foreach ( $terms as $index => $term ) {
// manually do upper/lowercase stuff for utf-8 since PHP won't do it
if ( preg_match( '/[\x80-\xff]/', $term ) ) {
- $terms[$index] = preg_replace_callback( '/./us', array( $this, 'caseCallback' ), $terms[$index] );
+ $terms[$index] = preg_replace_callback(
+ '/./us',
+ array( $this, 'caseCallback' ),
+ $terms[$index]
+ );
} else {
$terms[$index] = $term;
}
if ( $len < $targetchars - 20 ) {
// complete this line
if ( $len < strlen( $all[$index] ) ) {
- $extended[$index] = $this->extract( $all[$index], $offsets[$index], $offsets[$index] + $targetchars, $offsets[$index] );
+ $extended[$index] = $this->extract(
+ $all[$index],
+ $offsets[$index],
+ $offsets[$index] + $targetchars,
+ $offsets[$index]
+ );
$len = strlen( $extended[$index] );
}
foreach ( $snippets as $index => $line ) {
if ( $last == - 1 ) {
$extract .= $line; // first line
- } elseif ( $last + 1 == $index && $offsets[$last] + strlen( $snippets[$last] ) >= strlen( $all[$last] ) ) {
+ } elseif ( $last + 1 == $index
+ && $offsets[$last] + strlen( $snippets[$last] ) >= strlen( $all[$last] )
+ ) {
$extract .= " " . $line; // continous lines
} else {
$extract .= '<b> ... </b>' . $line;
$s = max( 0, $point - $tolerance );
$l = min( strlen( $text ), $point + $tolerance ) - $s;
$m = array();
- if ( preg_match( '/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/', substr( $text, $s, $l ), $m, PREG_OFFSET_CAPTURE ) ) {
+
+ if ( preg_match(
+ '/[ ,.!?~!@#$%^&*\(\)+=\-\\\|\[\]"\'<>]/',
+ substr( $text, $s, $l ),
+ $m,
+ PREG_OFFSET_CAPTURE
+ ) ) {
return $m[0][1] + $s + $offset;
} else {
// check if point is on a valid first UTF8 char
}
$char = ord( $text[$point] );
}
+
return $point;
}
$text = preg_replace( "/\\{\\{([^|]+?)\\}\\}/", "", $text );
$text = preg_replace( "/\\{\\{([^|]+\\|)(.*?)\\}\\}/", "\\2", $text );
$text = preg_replace( "/\\[\\[([^|]+?)\\]\\]/", "\\1", $text );
- $text = preg_replace_callback( "/\\[\\[([^|]+\\|)(.*?)\\]\\]/", array( $this, 'linkReplace' ), $text );
+ $text = preg_replace_callback(
+ "/\\[\\[([^|]+\\|)(.*?)\\]\\]/",
+ array( $this, 'linkReplace' ),
+ $text
+ );
// $text = preg_replace("/\\[\\[([^|]+\\|)(.*?)\\]\\]/", "\\2", $text);
$text = preg_replace( "/<\/?[^>]+>/", "", $text );
$text = preg_replace( "/'''''/", "", $text );
* @access public
*/
function searchText( $term ) {
- $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
+ $resultSet = $this->db->resultObject(
+ $this->db->query( $this->getQuery( $this->filter( $term ), true ) )
+ );
+
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
* @access public
*/
function searchTitle( $term ) {
- $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
+ $resultSet = $this->db->resultObject(
+ $this->db->query( $this->getQuery( $this->filter( $term ), false ) )
+ );
+
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
* @ingroup Search
*/
class SearchMySQL extends SearchDatabase {
- var $strictMatching = true;
- static $mMinSearchLength;
+ protected $strictMatching = true;
+
+ private static $mMinSearchLength;
/**
* Parse the user's query and transform it into an SQL fragment which will
*/
function parseQuery( $filteredText, $fulltext ) {
global $wgContLang;
+
$lc = $this->legalSearchChars(); // Minus format chars
$searchon = '';
$this->searchTerms = array();
if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
$filteredText, $m, PREG_SET_ORDER ) ) {
foreach ( $m as $bits ) {
- @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+ wfSuppressWarnings();
+ list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+ wfRestoreWarnings();
if ( $nonQuoted != '' ) {
$term = $nonQuoted;
* @ingroup Search
*/
class SearchOracle extends SearchDatabase {
-
private $reservedWords = array(
'ABOUT' => 1,
'ACCUM' => 1,
return new SqlSearchResultSet( false, '' );
}
- $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), true ) ) );
+ $resultSet = $this->db->resultObject(
+ $this->db->query( $this->getQuery( $this->filter( $term ), true ) )
+ );
+
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
return new SqlSearchResultSet( false, '' );
}
- $resultSet = $this->db->resultObject( $this->db->query( $this->getQuery( $this->filter( $term ), false ) ) );
+ $resultSet = $this->db->resultObject(
+ $this->db->query( $this->getQuery( $this->filter( $term ), false ) )
+ );
+
return new SqlSearchResultSet( $resultSet, $this->searchTerms );
}
if ( preg_match_all( '/([-+<>~]?)(([' . $lc . ']+)(\*?)|"[^"]*")/',
$filteredText, $m, PREG_SET_ORDER ) ) {
foreach ( $m as $bits ) {
- @list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+ wfSuppressWarnings();
+ list( /* all */, $modifier, $term, $nonQuoted, $wildcard ) = $bits;
+ wfRestoreWarnings();
if ( $nonQuoted != '' ) {
$term = $nonQuoted;