Pass phpcs-strict on includes/search/
authorSiebrand Mazeland <siebrand@kitano.nl>
Fri, 9 May 2014 20:32:17 +0000 (22:32 +0200)
committerSiebrand Mazeland <siebrand@kitano.nl>
Fri, 9 May 2014 20:32:17 +0000 (22:32 +0200)
Change-Id: Ia38af607b1f2a8e49f60f1a659a14b801e7dcda0

includes/search/SearchEngine.php
includes/search/SearchHighlighter.php
includes/search/SearchMssql.php
includes/search/SearchMySQL.php
includes/search/SearchOracle.php
includes/search/SearchSqlite.php

index 827d8c3..907047e 100644 (file)
  * @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;
                }
        }
 
index 5e734fe..b8b2bae 100644 (file)
@@ -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 .= '<b> ... </b>' . $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 );
index ed76ff8..4960c42 100644 (file)
@@ -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 );
        }
 
index cc20d02..77a0c43 100644 (file)
@@ -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;
index c944152..4cfcec3 100644 (file)
@@ -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 );
        }
 
index 6b1a6b2..62fb236 100644 (file)
@@ -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;