From: Siebrand Mazeland Date: Fri, 9 May 2014 20:32:17 +0000 (+0200) Subject: Pass phpcs-strict on includes/search/ X-Git-Tag: 1.31.0-rc.0~15812^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/banques/ajouter.php?a=commitdiff_plain;h=b1aa60af2578399284de91f247b967ce4f66781c;p=lhc%2Fweb%2Fwiklou.git Pass phpcs-strict on includes/search/ Change-Id: Ia38af607b1f2a8e49f60f1a659a14b801e7dcda0 --- diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php index 827d8c31d7..907047e947 100644 --- a/includes/search/SearchEngine.php +++ b/includes/search/SearchEngine.php @@ -30,11 +30,22 @@ * @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 */ @@ -106,8 +117,9 @@ class SearchEngine { } /** - * 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; @@ -148,7 +160,10 @@ class SearchEngine { $allSearchTerms = array( $searchterm ); if ( $wgContLang->hasVariants() ) { - $allSearchTerms = array_merge( $allSearchTerms, $wgContLang->autoConvertToAllVariants( $searchterm ) ); + $allSearchTerms = array_merge( + $allSearchTerms, + $wgContLang->autoConvertToAllVariants( $searchterm ) + ); } $titleResult = null; @@ -523,6 +538,7 @@ class SearchEngine { */ public static function getOpenSearchTemplate() { global $wgOpenSearchTemplate, $wgCanonicalServer; + if ( $wgOpenSearchTemplate ) { return $wgOpenSearchTemplate; } else { @@ -530,7 +546,9 @@ class SearchEngine { if ( !$ns ) { $ns = "0"; } - return $wgCanonicalServer . wfScript( 'api' ) . '?action=opensearch&search={searchTerms}&namespace=' . $ns; + + return $wgCanonicalServer . wfScript( 'api' ) + . '?action=opensearch&search={searchTerms}&namespace=' . $ns; } } diff --git a/includes/search/SearchHighlighter.php b/includes/search/SearchHighlighter.php index 5e734feea0..b8b2baece7 100644 --- a/includes/search/SearchHighlighter.php +++ b/includes/search/SearchHighlighter.php @@ -27,7 +27,7 @@ * @ingroup Search */ class SearchHighlighter { - var $mCleanWikitext = true; + protected $mCleanWikitext = true; function __construct( $cleanupWikitext = true ) { $this->mCleanWikitext = $cleanupWikitext; @@ -40,11 +40,11 @@ class SearchHighlighter { * @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 == '' ) { @@ -138,7 +138,11 @@ class SearchHighlighter { 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; } @@ -229,7 +233,12 @@ class SearchHighlighter { 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] ); } @@ -254,7 +263,9 @@ class SearchHighlighter { 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 .= ' ... ' . $line; @@ -360,7 +371,13 @@ class SearchHighlighter { $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 @@ -373,6 +390,7 @@ class SearchHighlighter { } $char = ord( $text[$point] ); } + return $point; } @@ -444,7 +462,11 @@ class SearchHighlighter { $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 ); diff --git a/includes/search/SearchMssql.php b/includes/search/SearchMssql.php index ed76ff8c64..4960c42462 100644 --- a/includes/search/SearchMssql.php +++ b/includes/search/SearchMssql.php @@ -34,7 +34,10 @@ class SearchMssql extends SearchDatabase { * @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 ); } @@ -46,7 +49,10 @@ class SearchMssql extends SearchDatabase { * @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 ); } diff --git a/includes/search/SearchMySQL.php b/includes/search/SearchMySQL.php index cc20d027ef..77a0c43431 100644 --- a/includes/search/SearchMySQL.php +++ b/includes/search/SearchMySQL.php @@ -29,8 +29,9 @@ * @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 @@ -43,6 +44,7 @@ class SearchMySQL extends SearchDatabase { */ function parseQuery( $filteredText, $fulltext ) { global $wgContLang; + $lc = $this->legalSearchChars(); // Minus format chars $searchon = ''; $this->searchTerms = array(); @@ -52,7 +54,9 @@ class SearchMySQL extends SearchDatabase { 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; diff --git a/includes/search/SearchOracle.php b/includes/search/SearchOracle.php index c944152199..4cfcec3988 100644 --- a/includes/search/SearchOracle.php +++ b/includes/search/SearchOracle.php @@ -29,7 +29,6 @@ * @ingroup Search */ class SearchOracle extends SearchDatabase { - private $reservedWords = array( 'ABOUT' => 1, 'ACCUM' => 1, @@ -70,7 +69,10 @@ class SearchOracle extends SearchDatabase { 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 ); } @@ -85,7 +87,10 @@ class SearchOracle extends SearchDatabase { 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 ); } diff --git a/includes/search/SearchSqlite.php b/includes/search/SearchSqlite.php index 6b1a6b24bc..62fb2364a8 100644 --- a/includes/search/SearchSqlite.php +++ b/includes/search/SearchSqlite.php @@ -50,7 +50,9 @@ class SearchSqlite extends SearchDatabase { 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;