includes/paths.php
changeset 499 6b7fdd898ba3
parent 463 0857911fb7f1
child 505 3b5b78182ce5
equal deleted inserted replaced
498:a85af9c28355 499:6b7fdd898ba3
   609         $word = preg_replace("/[']{2,}/", '', $word);
   609         $word = preg_replace("/[']{2,}/", '', $word);
   610       if ( strlen($word) < 2 )
   610       if ( strlen($word) < 2 )
   611         unset($text[$i]);
   611         unset($text[$i]);
   612     }
   612     }
   613     $text = array_unique(array_values($text));
   613     $text = array_unique(array_values($text));
       
   614     // for debugging purposes (usually XSS safe because of character stripping)
       
   615     // echo ' ' . implode(' ', $text) . '<br />';
   614     return $text;
   616     return $text;
   615   }
   617   }
   616   
   618   
   617   /**
   619   /**
   618    * Rebuilds the site's entire search index. Considerably more exciting if run from the command line.
   620    * Rebuilds the site's entire search index. Considerably more exciting if run from the command line.
   667       $texts = $db->sql_query('SELECT p.name, t.page_id, t.namespace, t.page_text FROM ' . table_prefix . "page_text AS t\n"
   669       $texts = $db->sql_query('SELECT p.name, t.page_id, t.namespace, t.page_text FROM ' . table_prefix . "page_text AS t\n"
   668                             . "  LEFT JOIN " . table_prefix . "pages AS p\n"
   670                             . "  LEFT JOIN " . table_prefix . "pages AS p\n"
   669                             . "    ON ( p.urlname = t.page_id AND p.namespace = t.namespace )\n"
   671                             . "    ON ( p.urlname = t.page_id AND p.namespace = t.namespace )\n"
   670                             . "  WHERE ( p.password = '' OR p.password = '$sha1_blank' )\n"
   672                             . "  WHERE ( p.password = '' OR p.password = '$sha1_blank' )\n"
   671                             . "    AND ( p.visible = 1 )\n"
   673                             . "    AND ( p.visible = 1 )\n"
   672                             . "  LIMIT $offset, $pages_in_batch;", false);
   674                             . "  LIMIT $pages_in_batch OFFSET $offset;", false);
   673       if ( !$texts )
   675       if ( !$texts )
   674         $db->_die();
   676         $db->_die();
   675       
   677       
   676       $k = $offset;
   678       $k = $offset;
   677       
   679       
   701           foreach ( $wordlist as $word )
   703           foreach ( $wordlist as $word )
   702           {
   704           {
   703             if ( in_array($word, $stopwords) || strval(intval($word)) === $word || strlen($word) < 3 )
   705             if ( in_array($word, $stopwords) || strval(intval($word)) === $word || strlen($word) < 3 )
   704               continue;
   706               continue;
   705             $word_db = $db->escape($word);
   707             $word_db = $db->escape($word);
       
   708             $word_db_lc = $db->escape(strtolower($word));
   706             if ( !in_array($word, $master_word_list) )
   709             if ( !in_array($word, $master_word_list) )
   707             {
   710             {
   708               $inserts[] = "( '$word_db', '$page_uniqid' )";
   711               $inserts[] = "( '$word_db', '$word_db_lc', '$page_uniqid' )";
   709             }
   712             }
   710             else
   713             else
   711             {
   714             {
   712               if ( $verbose && $debug )
   715               if ( $verbose && $debug )
   713                 echo '.';
   716                 echo '.';
   722           if ( count($inserts) > 0 )
   725           if ( count($inserts) > 0 )
   723           {
   726           {
   724             if ( $verbose && $debug )
   727             if ( $verbose && $debug )
   725               echo 'i';
   728               echo 'i';
   726             $inserts = implode(",\n  ", $inserts);
   729             $inserts = implode(",\n  ", $inserts);
   727             $q = $db->sql_query('INSERT INTO ' . table_prefix . "search_index(word, page_names) VALUES\n  $inserts;", false);
   730             $q = $db->sql_query('INSERT INTO ' . table_prefix . "search_index(word, word_lcase, page_names) VALUES\n  $inserts;", false);
   728             if ( !$q )
   731             if ( !$q )
   729               $db->_die();
   732               $db->_die();
   730           }
   733           }
   731           
   734           
   732           $master_word_list = array_unique(array_merge($master_word_list, $wordlist));
   735           $master_word_list = array_unique(array_merge($master_word_list, $wordlist));