(bug 18609) Search index was empty for some pages
authorMax Semenik <maxsem@users.mediawiki.org>
Wed, 4 Nov 2009 15:18:30 +0000 (15:18 +0000)
committerMax Semenik <maxsem@users.mediawiki.org>
Wed, 4 Nov 2009 15:18:30 +0000 (15:18 +0000)
RELEASE-NOTES
includes/search/SearchUpdate.php
t/DatabaseMock.inc [new file with mode: 0644]
t/inc/SearchUpdate.t [new file with mode: 0644]

index 8c10923..a2316d2 100644 (file)
@@ -619,6 +619,7 @@ Hopefully we will remove this configuration var soon)
 * Removed section edit links in edit conflict form
 * Allow SpecialActiveusers to work on non-MySQL databases
 * (bug 6579) Fixed protecting images from uploading only 
+* (bug 18609) Search index was empty for some pages
 
 == API changes in 1.16 ==
 
index edf2bcb..b9c2335 100644 (file)
@@ -46,7 +46,7 @@ class SearchUpdate {
                $text = $wgContLang->stripForSearch( $this->mText );
 
                wfProfileIn( $fname.'-regexps' );
-               $text = preg_replace( "/<\\/?\\s*[A-Za-z][A-Za-z0-9]*\\s*([^>]*?)>/",
+               $text = preg_replace( "/<\\/?\\s*[A-Za-z][^>]*?>/",
                        ' ', $wgContLang->lc( " " . $text . " " ) ); # Strip HTML markup
                $text = preg_replace( "/(^|\\n)==\\s*([^\\n]+)\\s*==(\\s)/sD",
                  "\\1\\2 \\2 \\2\\3", $text ); # Emphasize headings
diff --git a/t/DatabaseMock.inc b/t/DatabaseMock.inc
new file mode 100644 (file)
index 0000000..59d380f
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Mock database class for tests, does nothing.
+ * Include after LocalSettings.php
+ */
+
+$wgDBtype = 'mock';
+
+class DatabaseMock extends DatabaseBase {
+       function __construct( $server = false, $user = false, $password = false, $dbName = false,
+               $failFunction = false, $flags = 0, $tablePrefix = 'get from global' )
+       {
+               $this->mConn = true;
+               $this->mOpened = true;
+       }
+
+       function open( $server, $user, $password, $dbName ) { return true; }
+       function doQuery( $sql ) {}
+       function fetchObject( $res ) {}
+       function fetchRow( $res ) {}
+       function numRows( $res ) {}
+       function numFields( $res ) {}
+       function fieldName( $res, $n ) {}
+       function insertId() {}
+       function dataSeek( $res, $row ) {}
+       function lastErrno() { return 0; }
+       function lastError() { return ''; }
+       function affectedRows() {}
+       function fieldInfo( $table, $field ) {}
+       function strencode( $s ) {}
+       function getSoftwareLink() {}
+       function getServerVersion() {}
+}
\ No newline at end of file
diff --git a/t/inc/SearchUpdate.t b/t/inc/SearchUpdate.t
new file mode 100644 (file)
index 0000000..da061f7
--- /dev/null
@@ -0,0 +1,61 @@
+#!/usr/bin/env php\r
+<?php\r
+\r
+require 't/Test.php';\r
+\r
+plan( 4 );\r
+\r
+define( 'MEDIAWIKI', 1 );\r
+require 'includes/Defines.php';\r
+require 'includes/ProfilerStub.php';\r
+require 'includes/AutoLoader.php';\r
+require 'LocalSettings.php';\r
+\r
+require 't/DatabaseMock.inc';\r
+\r
+$wgSearchType = 'MockSearch';\r
+\r
+require 'includes/Setup.php';\r
+\r
+\r
+class MockSearch extends SearchEngine {\r
+       public static $id;\r
+       public static $title;\r
+       public static $text;\r
+\r
+       public function __construct( $db ) {\r
+       }\r
+\r
+       public function update( $id, $title, $text ) {\r
+               self::$id = $id;\r
+               self::$title = $title;\r
+               self::$text = $text;\r
+       }\r
+}\r
+\r
+function update( $text, $title = 'Test', $id = 1 ) {\r
+       $u = new SearchUpdate( $id, $title, $text );\r
+       $u->doUpdate();\r
+       return array( MockSearch::$title, MockSearch::$text );\r
+}\r
+\r
+function updateText( $text ) {\r
+       list( $title, $resultText ) = update( $text );\r
+       $resultText = trim( $resultText ); // abstract from some implementation details\r
+       return $resultText;\r
+}\r
+\r
+is( updateText( '<div>TeSt</div>' ), 'test', 'HTML stripped, text lowercased' );\r
+\r
+is( updateText( <<<EOT\r
+<table style="color:red; font-size:100px">\r
+       <tr class="scary"><td><div>foo</div></td><tr>bar</td></tr>\r
+       <tr><td>boz</td><tr>quux</td></tr>\r
+</table>\r
+EOT\r
+), 'foo bar boz quux', 'Stripping HTML tables' );\r
+\r
+is( updateText( 'a > b' ), 'a b', 'Handle unclosed tags' );\r
+\r
+$text = str_pad( "foo <barbarbar \n", 10000, 'x' );\r
+ok( updateText( $text ) != '', 'Bug 18609' );
\ No newline at end of file